From 808d65a5a3ad482bc3569c5d7121bfc0c8f4b762 Mon Sep 17 00:00:00 2001 From: Laurent Date: Fri, 10 Oct 2025 11:29:55 +0200 Subject: [PATCH] adds a plus button to add activities to prospect in the dashboard, and setting related_user if needed --- biz/admin.py | 15 ++++++-- biz/templates/admin/biz/dashboard.html | 47 ++++++++++++++++++++++++++ 2 files changed, 60 insertions(+), 2 deletions(-) diff --git a/biz/admin.py b/biz/admin.py index 7dee939..e4b5de3 100644 --- a/biz/admin.py +++ b/biz/admin.py @@ -131,7 +131,12 @@ class ProspectAdmin(SyncedObjectAdmin): ordering = ['-last_update'] filter_horizontal = ['entities'] actions = ['send_email', create_activity_for_prospect, mark_as_inbound, contacted_by_sms, mark_as_should_test, mark_as_testing, mark_as_customer, mark_as_have_account, declined_too_expensive, declined_use_something_else, declined_android_user, mark_as_not_concerned] - raw_id_fields = ['official_user', 'related_user'] + autocomplete_fields = ['official_user', 'related_user'] + + def save_model(self, request, obj, form, change): + if obj.related_user is None: + obj.related_user = request.user + super().save_model(request, obj, form, change) def last_update_date(self, obj): return obj.last_update.date() if obj.last_update else None @@ -492,11 +497,12 @@ class ProspectGroupAdmin(SyncedObjectAdmin): @admin.register(Activity) class ActivityAdmin(SyncedObjectAdmin): - raw_id_fields = ['prospects'] + # raw_id_fields = ['prospects'] list_display = ('prospect_names', 'last_update', 'status', 'type', 'description', 'attachment_text', ) list_filter = ('status', 'type') search_fields = ('attachment_text',) date_hierarchy = 'last_update' + autocomplete_fields = ['prospects', 'related_user'] def get_form(self, request, obj=None, **kwargs): form = super().get_form(request, obj, **kwargs) @@ -518,6 +524,11 @@ class ActivityAdmin(SyncedObjectAdmin): return form + def save_model(self, request, obj, form, change): + if obj.related_user is None: + obj.related_user = request.user + super().save_model(request, obj, form, change) + def get_event_display(self, obj): return str(obj) get_event_display.short_description = 'Activity' diff --git a/biz/templates/admin/biz/dashboard.html b/biz/templates/admin/biz/dashboard.html index 1e03a58..4cff282 100644 --- a/biz/templates/admin/biz/dashboard.html +++ b/biz/templates/admin/biz/dashboard.html @@ -105,6 +105,33 @@ width: 130px; } + .prospect-table th.actions-col, + .prospect-table td.actions-col { + width: 80px; + text-align: center; + } + + .add-activity-btn { + display: inline-flex; + align-items: center; + justify-content: center; + width: 24px; + height: 24px; + background: #70bf2b; + color: white !important; + text-decoration: none !important; + border-radius: 50%; + font-size: 18px; + font-weight: bold; + transition: background-color 0.2s; + } + + .add-activity-btn:hover { + background: #5fa624; + color: white !important; + text-decoration: none !important; + } + .prospect-table tbody tr { border-bottom: 1px solid #eee; transition: background-color 0.2s; @@ -189,6 +216,7 @@ Status Contact Again Last Update + Actions @@ -204,6 +232,9 @@ {{ prospect.current_status }} {{ prospect.contact_again|date:"d/m/Y" }} {{ prospect.last_update|date:"d/m/Y H:i" }} + + + + {% endfor %} @@ -228,6 +259,7 @@ Phone Activity Type Last Update + Actions @@ -242,6 +274,9 @@ {{ prospect.phone|default:"-" }} {{ prospect.current_activity_type|default:"-" }} {{ prospect.last_update|date:"d/m/Y H:i" }} + + + + {% endfor %} @@ -266,6 +301,7 @@ Phone Activity Type Last Update + Actions @@ -280,6 +316,9 @@ {{ prospect.phone|default:"-" }} {{ prospect.current_activity_type|default:"-" }} {{ prospect.last_update|date:"d/m/Y H:i" }} + + + + {% endfor %} @@ -305,6 +344,7 @@ Status Activity Type Last Update + Actions @@ -320,6 +360,9 @@ {{ prospect.current_status }} {{ prospect.current_activity_type|default:"-" }} {{ prospect.last_update|date:"d/m/Y H:i" }} + + + + {% endfor %} @@ -344,6 +387,7 @@ Phone Activity Type Last Update + Actions @@ -358,6 +402,9 @@ {{ prospect.phone|default:"-" }} {{ prospect.current_activity_type|default:"-" }} {{ prospect.last_update|date:"d/m/Y H:i" }} + + + + {% endfor %}