adds a plus button to add activities to prospect in the dashboard, and setting related_user if needed

main
Laurent 1 month ago
parent 0f7516a617
commit 808d65a5a3
  1. 15
      biz/admin.py
  2. 47
      biz/templates/admin/biz/dashboard.html

@ -131,7 +131,12 @@ class ProspectAdmin(SyncedObjectAdmin):
ordering = ['-last_update'] ordering = ['-last_update']
filter_horizontal = ['entities'] 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] 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): def last_update_date(self, obj):
return obj.last_update.date() if obj.last_update else None return obj.last_update.date() if obj.last_update else None
@ -492,11 +497,12 @@ class ProspectGroupAdmin(SyncedObjectAdmin):
@admin.register(Activity) @admin.register(Activity)
class ActivityAdmin(SyncedObjectAdmin): class ActivityAdmin(SyncedObjectAdmin):
raw_id_fields = ['prospects'] # raw_id_fields = ['prospects']
list_display = ('prospect_names', 'last_update', 'status', 'type', 'description', 'attachment_text', ) list_display = ('prospect_names', 'last_update', 'status', 'type', 'description', 'attachment_text', )
list_filter = ('status', 'type') list_filter = ('status', 'type')
search_fields = ('attachment_text',) search_fields = ('attachment_text',)
date_hierarchy = 'last_update' date_hierarchy = 'last_update'
autocomplete_fields = ['prospects', 'related_user']
def get_form(self, request, obj=None, **kwargs): def get_form(self, request, obj=None, **kwargs):
form = super().get_form(request, obj, **kwargs) form = super().get_form(request, obj, **kwargs)
@ -518,6 +524,11 @@ class ActivityAdmin(SyncedObjectAdmin):
return form 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): def get_event_display(self, obj):
return str(obj) return str(obj)
get_event_display.short_description = 'Activity' get_event_display.short_description = 'Activity'

@ -105,6 +105,33 @@
width: 130px; 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 { .prospect-table tbody tr {
border-bottom: 1px solid #eee; border-bottom: 1px solid #eee;
transition: background-color 0.2s; transition: background-color 0.2s;
@ -189,6 +216,7 @@
<th>Status</th> <th>Status</th>
<th>Contact Again</th> <th>Contact Again</th>
<th>Last Update</th> <th>Last Update</th>
<th class="actions-col">Actions</th>
</tr> </tr>
</thead> </thead>
<tbody> <tbody>
@ -204,6 +232,9 @@
<td><span class="prospect-status">{{ prospect.current_status }}</span></td> <td><span class="prospect-status">{{ prospect.current_status }}</span></td>
<td class="prospect-date">{{ prospect.contact_again|date:"d/m/Y" }}</td> <td class="prospect-date">{{ prospect.contact_again|date:"d/m/Y" }}</td>
<td class="prospect-date">{{ prospect.last_update|date:"d/m/Y H:i" }}</td> <td class="prospect-date">{{ prospect.last_update|date:"d/m/Y H:i" }}</td>
<td class="actions-col">
<a href="{% url 'admin:biz_activity_add' %}?prospect={{ prospect.id }}" class="add-activity-btn" title="Add Activity">+</a>
</td>
</tr> </tr>
{% endfor %} {% endfor %}
</tbody> </tbody>
@ -228,6 +259,7 @@
<th>Phone</th> <th>Phone</th>
<th>Activity Type</th> <th>Activity Type</th>
<th>Last Update</th> <th>Last Update</th>
<th class="actions-col">Actions</th>
</tr> </tr>
</thead> </thead>
<tbody> <tbody>
@ -242,6 +274,9 @@
<td>{{ prospect.phone|default:"-" }}</td> <td>{{ prospect.phone|default:"-" }}</td>
<td>{{ prospect.current_activity_type|default:"-" }}</td> <td>{{ prospect.current_activity_type|default:"-" }}</td>
<td class="prospect-date">{{ prospect.last_update|date:"d/m/Y H:i" }}</td> <td class="prospect-date">{{ prospect.last_update|date:"d/m/Y H:i" }}</td>
<td class="actions-col">
<a href="{% url 'admin:biz_activity_add' %}?prospect={{ prospect.id }}" class="add-activity-btn" title="Add Activity">+</a>
</td>
</tr> </tr>
{% endfor %} {% endfor %}
</tbody> </tbody>
@ -266,6 +301,7 @@
<th>Phone</th> <th>Phone</th>
<th>Activity Type</th> <th>Activity Type</th>
<th>Last Update</th> <th>Last Update</th>
<th class="actions-col">Actions</th>
</tr> </tr>
</thead> </thead>
<tbody> <tbody>
@ -280,6 +316,9 @@
<td>{{ prospect.phone|default:"-" }}</td> <td>{{ prospect.phone|default:"-" }}</td>
<td>{{ prospect.current_activity_type|default:"-" }}</td> <td>{{ prospect.current_activity_type|default:"-" }}</td>
<td class="prospect-date">{{ prospect.last_update|date:"d/m/Y H:i" }}</td> <td class="prospect-date">{{ prospect.last_update|date:"d/m/Y H:i" }}</td>
<td class="actions-col">
<a href="{% url 'admin:biz_activity_add' %}?prospect={{ prospect.id }}" class="add-activity-btn" title="Add Activity">+</a>
</td>
</tr> </tr>
{% endfor %} {% endfor %}
</tbody> </tbody>
@ -305,6 +344,7 @@
<th>Status</th> <th>Status</th>
<th>Activity Type</th> <th>Activity Type</th>
<th>Last Update</th> <th>Last Update</th>
<th class="actions-col">Actions</th>
</tr> </tr>
</thead> </thead>
<tbody> <tbody>
@ -320,6 +360,9 @@
<td><span class="prospect-status">{{ prospect.current_status }}</span></td> <td><span class="prospect-status">{{ prospect.current_status }}</span></td>
<td>{{ prospect.current_activity_type|default:"-" }}</td> <td>{{ prospect.current_activity_type|default:"-" }}</td>
<td class="prospect-date">{{ prospect.last_update|date:"d/m/Y H:i" }}</td> <td class="prospect-date">{{ prospect.last_update|date:"d/m/Y H:i" }}</td>
<td class="actions-col">
<a href="{% url 'admin:biz_activity_add' %}?prospect={{ prospect.id }}" class="add-activity-btn" title="Add Activity">+</a>
</td>
</tr> </tr>
{% endfor %} {% endfor %}
</tbody> </tbody>
@ -344,6 +387,7 @@
<th>Phone</th> <th>Phone</th>
<th>Activity Type</th> <th>Activity Type</th>
<th>Last Update</th> <th>Last Update</th>
<th class="actions-col">Actions</th>
</tr> </tr>
</thead> </thead>
<tbody> <tbody>
@ -358,6 +402,9 @@
<td>{{ prospect.phone|default:"-" }}</td> <td>{{ prospect.phone|default:"-" }}</td>
<td>{{ prospect.current_activity_type|default:"-" }}</td> <td>{{ prospect.current_activity_type|default:"-" }}</td>
<td class="prospect-date">{{ prospect.last_update|date:"d/m/Y H:i" }}</td> <td class="prospect-date">{{ prospect.last_update|date:"d/m/Y H:i" }}</td>
<td class="actions-col">
<a href="{% url 'admin:biz_activity_add' %}?prospect={{ prospect.id }}" class="add-activity-btn" title="Add Activity">+</a>
</td>
</tr> </tr>
{% endfor %} {% endfor %}
</tbody> </tbody>

Loading…
Cancel
Save