Permalink
Browse files

better feedback in Person/Entity admin

  • Loading branch information...
1 parent f8603e3 commit beb65760ee8585af39fa85ac5e13b61760089ffc @evildmp committed Oct 12, 2012
Showing with 30 additions and 8 deletions.
  1. +1 −1 arkestra_utilities/admin_mixins.py
  2. +29 −7 contacts_and_people/admin.py
@@ -84,6 +84,6 @@ class InputURLMixin(forms.ModelForm):
'importance': ('', {'fields': ('importance',)}),
'url': ('If this is an external item', {'fields': ('external_url', 'input_url',)}),
'slug': ('If this is an internal item', {'fields': ('slug',)}),
- 'location': ('', {'fields': ('precise_location', 'access_note',)}),
+ 'location': ('', {'fields': ('get_full_address', 'precise_location', 'access_note',)}),
'email': ('', {'fields': ('email',)}),
}
@@ -88,6 +88,7 @@ class PhoneContactAdmin(admin.ModelAdmin):
pass
class PersonAndEntityAdmin(SupplyRequestMixin, AutocompleteMixin, ModelAdminWithTabsAndCMSPlaceholder):
+
def _media(self):
return super(AutocompleteMixin, self).media + super(ModelAdminWithTabsAndCMSPlaceholder, self).media
media = property(_media)
@@ -181,19 +182,32 @@ def action(modeladmin,request,queryset):
return (name, (action, name,"Add selected Person to %s as 'Member'" % (entity,)))
-class PersonAdmin(PersonAndEntityAdmin):
+class PersonAdmin(PersonAndEntityAdmin):
search_fields = ['given_name','surname','institutional_username',]
-
-
form = PersonForm
list_display = ( 'surname', 'given_name', 'image', 'get_entity', 'slug')
# list_editable = ('user',)
filter_horizontal = ('entities',)
prepopulated_fields = {'slug': ('title', 'given_name', 'middle_names', 'surname',)}
-
- name_fieldset = ('Name', {'fields': ('title', 'given_name', 'middle_names', 'surname',),})
+ readonly_fields = ['get_full_address', 'role']
+
+ def get_full_address(self, instance):
+ if instance.building and instance.get_full_address == instance.get_entity.get_full_address:
+ return "Warning: this Person has the Specify Building field set, probably unnecessarily."
+ else:
+ return "%s" % (", ".join(instance.get_full_address)) or "Warning: this person has no address."
+
+ get_full_address.short_description = "Address"
+
+ def role(self, instance):
+ return models.Membership.objects.get(
+ person = instance,
+ entity__abstract_entity = False,
+ importance_to_person = 5)
+
+ name_fieldset = ('Name', {'fields': ('title', 'given_name', 'middle_names', 'surname', 'role'),})
override_fieldset = ('Over-ride default output', {
- 'fields': ('please_contact', 'override_entity', 'building',),
+ 'fields': ('please_contact', 'building',),
'classes': ('collapse',)
})
advanced_fieldset = (
@@ -205,7 +219,6 @@ class PersonAdmin(PersonAndEntityAdmin):
'fields': ('description',),
'classes': ('plugin-holder', 'plugin-holder-nopage',)
})
-
tabs = [
('Personal details', {'fieldsets': (name_fieldset, fieldsets["image"])}),
('Contact information', {
@@ -310,6 +323,15 @@ class EntityAdmin(PersonAndEntityAdmin):
prepopulated_fields = {
'slug': ('name',)
}
+ readonly_fields = ['get_full_address']
+
+ def get_full_address(self, instance):
+ if not instance.abstract_entity:
+ return "%s" % (", ".join(instance.get_full_address)) or "Warning: this Entity has no address."
+ else:
+ return "This is an abstract entity and therefore has no address"
+
+ get_full_address.short_description = "Address"
name_fieldset = ('Name', {'fields': ('name', 'short_name')})
website_fieldset = ('', {'fields': ('website',)})

0 comments on commit beb6576

Please sign in to comment.