mirror of
https://github.com/nottinghamtec/PyRIGS.git
synced 2026-01-17 05:22:16 +00:00
Make confirmation more useful
This commit is contained in:
@@ -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)
|
||||
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']
|
||||
Reference in New Issue
Block a user