@ -12,9 +12,9 @@ import io
import time
import time
import logging
import logging
from . models import Entity , Prospect , Activity , Status , ActivityType , EmailTemplate
from . models import Entity , Prospect , Activity , Status , ActivityType , EmailTemplate , DeclinationReason
from . forms import FileImportForm , EmailTemplateSelectionForm
from . forms import FileImportForm , EmailTemplateSelectionForm
from . filters import StaffUserFilter , ProspectProfileFilter
from . filters import ProspectStatusFilter , StaffUserFilter , ProspectProfileFilter , ProspectDeclineReason Filter
from tournaments . models import CustomUser
from tournaments . models import CustomUser
from tournaments . models . enums import UserOrigin
from tournaments . models . enums import UserOrigin
@ -92,14 +92,14 @@ create_activity_for_prospect.short_description = "Create event"
@admin . register ( Prospect )
@admin . register ( Prospect )
class ProspectAdmin ( SyncedObjectAdmin ) :
class ProspectAdmin ( SyncedObjectAdmin ) :
readonly_fields = [ ' related_event s ' , ' entity_names ' , ' current_status ' ]
readonly_fields = [ ' related_activitie s ' , ' entity_names ' , ' current_status ' , ' id ' ]
fieldsets = [
fieldsets = [
( None , {
( None , {
' fields ' : [ ' related_events ' , ' entity_names ' , ' first_name ' , ' last_name ' , ' email ' , ' phone ' , ' name_unsure ' , ' official_user ' , ' entities ' ]
' fields ' : [ ' related_activities ' , ' id ' , ' entity_names ' , ' related_user ' , ' first_name ' , ' last_name ' , ' email ' , ' phone ' , ' official_user ' , ' name_unsure ' , ' entities ' ]
} ) ,
} ) ,
]
]
list_display = ( ' entity_names ' , ' first_name ' , ' last_name ' , ' email ' , ' last_update ' , ' current_status ' )
list_display = ( ' entity_names ' , ' first_name ' , ' last_name ' , ' email ' , ' last_update ' , ' current_status ' )
list_filter = ( ' creation_date ' , StaffUserFilter , ' source ' , ProspectProfileFilter )
list_filter = ( ProspectStatusFilter , ProspectDeclineReasonFilter , ' creation_date ' , StaffUserFilter , ' source ' , ProspectProfileFilter )
search_fields = ( ' first_name ' , ' last_name ' , ' email ' )
search_fields = ( ' first_name ' , ' last_name ' , ' email ' )
date_hierarchy = ' creation_date '
date_hierarchy = ' creation_date '
change_list_template = " admin/bizdev/prospect/change_list.html "
change_list_template = " admin/bizdev/prospect/change_list.html "
@ -107,27 +107,16 @@ class ProspectAdmin(SyncedObjectAdmin):
filter_horizontal = [ ' entities ' ]
filter_horizontal = [ ' entities ' ]
actions = [ ' send_email ' , create_activity_for_prospect , contacted_by_sms , mark_as_should_test , mark_as_testing , mark_as_customer , declined_too_expensive , declined_use_something_else ]
actions = [ ' send_email ' , create_activity_for_prospect , contacted_by_sms , mark_as_should_test , mark_as_testing , mark_as_customer , declined_too_expensive , declined_use_something_else ]
def related_event s ( self , obj ) :
def related_activitie s ( self , obj ) :
event s = obj . event s. all ( )
activitie s = obj . activitie s. all ( )
if event s:
if activitie s:
event _links = [ ]
activity _links = [ ]
for event in event s:
for activity in activitie s:
url = f " /kingdom/bizdev/event/ { event . id } /change/ "
url = f " /kingdom/bizdev/activity/ { activity . id } /change/ "
event _links. append ( f ' <a href= " { url } " > { event . html_desc ( ) } </a> ' )
activity _links. append ( f ' <a href= " { url } " > { activity . html_desc ( ) } </a> ' )
return format_html ( ' <br> ' . join ( event _links) )
return format_html ( ' <br> ' . join ( activity _links) )
return " No events "
return " No events "
related_activities . short_description = " Related Activities "
related_events . short_description = " Related Events "
def changelist_view ( self , request , extra_context = None ) :
# Add the URL with a filter for the current user
user_filter_url = " {} ?related_user__id__exact= {} " . format (
reverse ( ' admin:bizdev_prospect_changelist ' ) ,
request . user . id
)
extra_context = extra_context or { }
extra_context [ ' user_filter_url ' ] = user_filter_url
return super ( ) . changelist_view ( request , extra_context = extra_context )
def get_urls ( self ) :
def get_urls ( self ) :
urls = super ( ) . get_urls ( )
urls = super ( ) . get_urls ( )
@ -292,7 +281,8 @@ class ProspectAdmin(SyncedObjectAdmin):
# Create Event if attachment_text or status is provided
# Create Event if attachment_text or status is provided
if attachment_text or status_text :
if attachment_text or status_text :
# Map status text to Status enum
# Map status text to Status enum
status_value = Status . NONE
status_value = None
declination_reason = None
if status_text :
if status_text :
if ' CONTACTED ' in status_text :
if ' CONTACTED ' in status_text :
status_value = Status . CONTACTED
status_value = Status . CONTACTED
@ -302,19 +292,30 @@ class ProspectAdmin(SyncedObjectAdmin):
status_value = Status . SHOULD_TEST
status_value = Status . SHOULD_TEST
elif ' CUSTOMER ' in status_text :
elif ' CUSTOMER ' in status_text :
status_value = Status . CUSTOMER
status_value = Status . CUSTOMER
elif ' TESTING ' in status_text :
status_value = Status . TESTING
elif ' LOST ' in status_text :
elif ' LOST ' in status_text :
status_value = Status . LOST
status_value = Status . LOST
elif ' DECLINED_TOO_EXPENSIVE ' in status_text :
elif ' DECLINED_TOO_EXPENSIVE ' in status_text :
status_value = Status . DECLINED_TOO_EXPENSIVE
status_value = Status . DECLINED
elif ' DECLINED_USE_SOMETHING_ELSE ' in status_text :
declination_reason = DeclinationReason . TOO_EXPENSIVE
status_value = Status . DECLINED_USE_SOMETHING_ELSE
elif ' USE_OTHER_PRODUCT ' in status_text :
elif ' DECLINED_UNRELATED ' in status_text or ' NOK ' in status_text :
status_value = Status . DECLINED
declination_reason = DeclinationReason . USE_OTHER_PRODUCT
elif ' USE_ANDROID ' in status_text :
status_value = Status . DECLINED
declination_reason = DeclinationReason . USE_ANDROID
elif ' NOK ' in status_text :
status_value = Status . DECLINED
declination_reason = DeclinationReason . UNKNOWN
elif ' DECLINED_UNRELATED ' in status_text :
status_value = Status . DECLINED_UNRELATED
status_value = Status . DECLINED_UNRELATED
activity = Activity . objects . create (
activity = Activity . objects . create (
type = ActivityType . SMS ,
type = ActivityType . SMS ,
attachment_text = attachment_text ,
attachment_text = attachment_text ,
status = status_value ,
status = status_value ,
declination_reason = declination_reason ,
description = f " Imported from CSV - Status: { status_text } " if status_text else " Imported from CSV "
description = f " Imported from CSV - Status: { status_text } " if status_text else " Imported from CSV "
)
)
activity . prospects . add ( prospect )
activity . prospects . add ( prospect )
@ -378,7 +379,7 @@ class ProspectAdmin(SyncedObjectAdmin):
@admin . register ( Activity )
@admin . register ( Activity )
class ActivityAdmin ( SyncedObjectAdmin ) :
class ActivityAdmin ( SyncedObjectAdmin ) :
list_display = ( ' creation_date ' , ' type ' , ' description ' , ' attachment_text ' )
list_display = ( ' creation_date ' , ' status ' , ' type' , ' description ' , ' attachment_text ' )
list_filter = ( ' status ' , ' type ' )
list_filter = ( ' status ' , ' type ' )
search_fields = ( ' description ' , )
search_fields = ( ' description ' , )
filter_horizontal = ( ' prospects ' , )
filter_horizontal = ( ' prospects ' , )