]> git.parisson.com Git - mezzo.git/commitdiff
simplify person model and admin field order
authorGuillaume Pellerin <guillaume.pellerin@ircam.fr>
Thu, 14 Jul 2016 17:50:17 +0000 (19:50 +0200)
committerGuillaume Pellerin <guillaume.pellerin@ircam.fr>
Thu, 14 Jul 2016 17:50:17 +0000 (19:50 +0200)
app/organization/team/admin.py
app/organization/team/migrations/0002_auto_20160714_1905.py [new file with mode: 0644]
app/organization/team/migrations/0003_auto_20160714_1943.py [new file with mode: 0644]
app/organization/team/models.py

index 38e3943073a9596b97e4048924abde01da743173..044ade888b811ccfbbab964b3e2ad6a84ae71f6a 100644 (file)
@@ -1,7 +1,7 @@
 from django.contrib import admin
 from django import forms
 from copy import deepcopy
-from mezzanine.core.admin import DisplayableAdmin, BaseDynamicInlineAdmin, BaseTranslationModelAdmin
+from mezzanine.core.admin import *
 from organization.team.models import *
 
 
@@ -25,26 +25,48 @@ class ActivityAdmin(BaseTranslationModelAdmin):
     model = Activity
 
 
-class ActivityInline(admin.StackedInline):
+class ActivityInline(StackedDynamicInlineAdmin):
 
     model = Activity
-    extras = 3
 
 
-class PersonAdmin(admin.ModelAdmin):
+class PersonAdminBase(admin.ModelAdmin):
 
     model = Person
 
+#
+# class PersonAdmin(BaseTranslationModelAdmin):
+#
+#     model = Person
+#     inlines = [ActivityInline,]
+#
+#     def get_fieldsets(self, request, obj = None):
+#         res = super(PersonAdmin, self).get_fieldsets(request, obj)
+#         # I only need to move one field; change the following
+#         # line to account for more.
+#         fields = (res[0][1]['fields'])
+#
+#         res[0][1]['fields'].append(res[0][1]['fields'].pop(0))
+#         return res
+
+class PersonAdmin(BaseTranslationModelAdmin):
 
-class PersonAdminDisplayable(DisplayableAdmin):
-
-    fieldsets = deepcopy(PersonAdmin.fieldsets)
+    model = Person
     inlines = [ActivityInline,]
+    first_fields = ['first_name', 'last_name', 'title', 'gender', 'user']
+
+    def get_fieldsets(self, request, obj = None):
+        res = super(PersonAdmin, self).get_fieldsets(request, obj)
+        for field in reversed(self.first_fields):
+            index = res[0][1]['fields'].index(field)
+            res[0][1]['fields'].insert(0, res[0][1]['fields'].pop(index))
+        return res
+
 
 
 admin.site.register(Organization, OrganizationAdmin)
 admin.site.register(OrganizationType)
 admin.site.register(Department, DepartmentAdmin)
 admin.site.register(Team, TeamAdmin)
-admin.site.register(Person, PersonAdminDisplayable)
+admin.site.register(Person, PersonAdmin)
 admin.site.register(Activity, ActivityAdmin)
diff --git a/app/organization/team/migrations/0002_auto_20160714_1905.py b/app/organization/team/migrations/0002_auto_20160714_1905.py
new file mode 100644 (file)
index 0000000..faca81f
--- /dev/null
@@ -0,0 +1,71 @@
+# -*- coding: utf-8 -*-
+# Generated by Django 1.9.7 on 2016-07-14 17:05
+from __future__ import unicode_literals
+
+from django.db import migrations
+
+
+class Migration(migrations.Migration):
+
+    dependencies = [
+        ('organization-team', '0001_initial'),
+    ]
+
+    operations = [
+        migrations.RemoveField(
+            model_name='person',
+            name='_meta_title',
+        ),
+        migrations.RemoveField(
+            model_name='person',
+            name='created',
+        ),
+        migrations.RemoveField(
+            model_name='person',
+            name='description',
+        ),
+        migrations.RemoveField(
+            model_name='person',
+            name='expiry_date',
+        ),
+        migrations.RemoveField(
+            model_name='person',
+            name='gen_description',
+        ),
+        migrations.RemoveField(
+            model_name='person',
+            name='in_sitemap',
+        ),
+        migrations.RemoveField(
+            model_name='person',
+            name='keywords_string',
+        ),
+        migrations.RemoveField(
+            model_name='person',
+            name='publish_date',
+        ),
+        migrations.RemoveField(
+            model_name='person',
+            name='short_url',
+        ),
+        migrations.RemoveField(
+            model_name='person',
+            name='site',
+        ),
+        migrations.RemoveField(
+            model_name='person',
+            name='slug',
+        ),
+        migrations.RemoveField(
+            model_name='person',
+            name='status',
+        ),
+        migrations.RemoveField(
+            model_name='person',
+            name='title',
+        ),
+        migrations.RemoveField(
+            model_name='person',
+            name='updated',
+        ),
+    ]
diff --git a/app/organization/team/migrations/0003_auto_20160714_1943.py b/app/organization/team/migrations/0003_auto_20160714_1943.py
new file mode 100644 (file)
index 0000000..0b2c300
--- /dev/null
@@ -0,0 +1,20 @@
+# -*- coding: utf-8 -*-
+# Generated by Django 1.9.7 on 2016-07-14 17:43
+from __future__ import unicode_literals
+
+from django.db import migrations
+
+
+class Migration(migrations.Migration):
+
+    dependencies = [
+        ('organization-team', '0002_auto_20160714_1905'),
+    ]
+
+    operations = [
+        migrations.RenameField(
+            model_name='person',
+            old_name='person_title',
+            new_name='title',
+        ),
+    ]
index 256dafc3c9d491a1bcd084769a100afa8a82ba16..7cfc0c2e2935300ebef488d3fcbab07bb19c8f1c 100644 (file)
@@ -100,17 +100,17 @@ class Team(Named):
         return u"Team"
 
 
-class Person(Displayable, AdminThumbMixin, Photo):
+class Person(AdminThumbMixin, Photo):
     """(Person description)"""
 
     user = models.ForeignKey(User, verbose_name=_('user'), blank=True, null=True, on_delete=models.SET_NULL)
-    person_title = models.CharField(_('title'), max_length=16, choices=TITLE_CHOICES, blank=True)
+    title = models.CharField(_('title'), max_length=16, choices=TITLE_CHOICES, blank=True)
     gender = models.CharField(_('gender'), max_length=16, choices=GENDER_CHOICES, blank=True)
     first_name = models.CharField(_('first name'), max_length=255, blank=True, null=True)
     last_name = models.CharField(_('last name'), max_length=255, blank=True, null=True)
     birthday = models.DateField(_('birthday'), blank=True)
-    organization = models.ForeignKey('Organization', verbose_name=_('organization'), blank=True, null=True, on_delete=models.SET_NULL)
     bio = RichTextField(_('biography'), blank=True)
+    organization = models.ForeignKey('Organization', verbose_name=_('organization'), blank=True, null=True, on_delete=models.SET_NULL)
 
     class Meta:
         verbose_name = _('person')