From 99dfdcd253a094f3eb4c5613f600024a60ef72a6 Mon Sep 17 00:00:00 2001 From: David Taylor Date: Tue, 5 Apr 2016 12:53:04 +0100 Subject: [PATCH] Make confirmation more useful --- RIGS/admin.py | 35 ++++++++++++++++--- .../templates/RIGS/admin_associate_merge.html | 25 +++++++++++-- 2 files changed, 53 insertions(+), 7 deletions(-) diff --git a/RIGS/admin.py b/RIGS/admin.py index 9bfcb3eb..0dfafd7a 100644 --- a/RIGS/admin.py +++ b/RIGS/admin.py @@ -10,6 +10,7 @@ from django.contrib import messages from django.db import transaction from django.core.exceptions import ObjectDoesNotExist from django.db.models import Count +from django.forms import ModelForm # Register your models here. admin.site.register(models.VatRate, reversion.VersionAdmin) @@ -38,19 +39,19 @@ class ProfileAdmin(UserAdmin): form = forms.ProfileChangeForm add_form = forms.ProfileCreationForm -@admin.register(models.Person, models.Organisation, models.Venue) class AssociateAdmin(reversion.VersionAdmin): list_display = ('id', 'name','number_of_events') search_fields = ['id','name'] - + list_display_links = ['id','name'] actions = ['merge'] + merge_fields = ['name'] + def get_queryset(self, request): return super(AssociateAdmin, self).get_queryset(request).annotate(event_count = Count('event')) def number_of_events(self,obj): return obj.latest_events.count() - number_of_events.admin_order_field = 'event_count' def merge(self, request, queryset): @@ -73,9 +74,35 @@ class AssociateAdmin(reversion.VersionAdmin): self.message_user(request, "Objects successfully merged.") return else: # Present the confirmation screen + + class TempForm(ModelForm): + class Meta: + model = queryset.model + fields = self.merge_fields + + forms = [] + for obj in queryset: + forms.append(TempForm(instance=obj)) + context = { 'title': _("Are you sure?"), 'queryset': queryset, 'action_checkbox_name': helpers.ACTION_CHECKBOX_NAME, + 'forms': forms } - return TemplateResponse(request, 'RIGS/admin_associate_merge.html', context, current_app=self.admin_site.name) \ No newline at end of file + return TemplateResponse(request, 'RIGS/admin_associate_merge.html', context, current_app=self.admin_site.name) + +@admin.register(models.Person) +class PersonAdmin(AssociateAdmin): + list_display = ('id', 'name','phone','email','number_of_events') + merge_fields = ['name','phone','email','address','notes'] + +@admin.register(models.Venue) +class VenueAdmin(AssociateAdmin): + list_display = ('id', 'name','phone','email','number_of_events') + merge_fields = ['name','phone','email','address','notes','three_phase_available'] + +@admin.register(models.Organisation) +class OrganisationAdmin(AssociateAdmin): + list_display = ('id', 'name','phone','email','number_of_events') + merge_fields = ['name','phone','email','address','notes','union_account'] \ No newline at end of file diff --git a/RIGS/templates/RIGS/admin_associate_merge.html b/RIGS/templates/RIGS/admin_associate_merge.html index e30b2e55..2128725c 100644 --- a/RIGS/templates/RIGS/admin_associate_merge.html +++ b/RIGS/templates/RIGS/admin_associate_merge.html @@ -5,13 +5,32 @@
{% csrf_token %}

The following objects will be merged. Please select the 'master' record which you would like to keep. Other records will have associated events moved to the 'master' copy, and then will be deleted.

- {% for item in queryset %} - {{item.pk}} | {{item}}
+ + {% for form in forms %} + {% if forloop.first %} + + + + {% for field in form %} + + {% endfor %} + + {% endif %} + + + + + {% for field in form %} + + {% endfor %} + {% endfor %} +
ID {{ field.label }}
{{form.instance.pk}} {{ field.value }}
+
{% for obj in queryset %} - + {% endfor %}