From 5cf2e5d8d55f80506c8817b7cf86797bd4792ce8 Mon Sep 17 00:00:00 2001 From: Claude Paroz Date: Thu, 1 Oct 2015 17:02:19 +0200 Subject: [PATCH] Add fields (ext_id, sector, short_name) to Corporation --- stages/admin.py | 5 ++-- stages/migrations/0003_add_corp_fields.py | 29 +++++++++++++++++++++++ stages/models.py | 6 ++++- stages/views.py | 2 ++ 4 files changed, 39 insertions(+), 3 deletions(-) create mode 100644 stages/migrations/0003_add_corp_fields.py diff --git a/stages/admin.py b/stages/admin.py index ef0a86f..68a8bee 100644 --- a/stages/admin.py +++ b/stages/admin.py @@ -55,10 +55,11 @@ class ContactInline(admin.StackedInline): extra = 1 class CorporationAdmin(admin.ModelAdmin): - list_display = ('name', 'pcode', 'city') + list_display = ('name', 'short_name', 'pcode', 'city') + list_editable = ('short_name',) # Temporarily? search_fields = ('name', 'pcode', 'city') ordering = ('name',) - fields = ('name', 'typ', 'street', ('pcode', 'city'), ('tel', 'email'), + fields = (('name', 'short_name', 'sector'), ('typ', 'ext_id'), 'street', ('pcode', 'city'), ('tel', 'email'), 'web', 'archived') inlines = [ContactInline] diff --git a/stages/migrations/0003_add_corp_fields.py b/stages/migrations/0003_add_corp_fields.py new file mode 100644 index 0000000..f6abc8d --- /dev/null +++ b/stages/migrations/0003_add_corp_fields.py @@ -0,0 +1,29 @@ +# -*- coding: utf-8 -*- +from __future__ import unicode_literals + +from django.db import models, migrations + + +class Migration(migrations.Migration): + + dependencies = [ + ('stages', '0002_corpcontact_ext_id'), + ] + + operations = [ + migrations.AddField( + model_name='corporation', + name='ext_id', + field=models.IntegerField(verbose_name='ID externe', null=True, blank=True), + ), + migrations.AddField( + model_name='corporation', + name='sector', + field=models.CharField(max_length=40, verbose_name='Secteur', blank=True), + ), + migrations.AddField( + model_name='corporation', + name='short_name', + field=models.CharField(max_length=40, verbose_name='Nom court', blank=True), + ), + ] diff --git a/stages/models.py b/stages/models.py index 6fdd82c..fe006fb 100644 --- a/stages/models.py +++ b/stages/models.py @@ -113,7 +113,10 @@ class Referent(models.Model): class Corporation(models.Model): + ext_id = models.IntegerField(null=True, blank=True, verbose_name='ID externe') name = models.CharField(max_length=100, verbose_name='Nom', unique=True) + short_name = models.CharField(max_length=40, blank=True, verbose_name='Nom court') + sector = models.CharField(max_length=40, blank=True, verbose_name='Secteur') typ = models.CharField(max_length=40, blank=True, verbose_name='Type de structure') street = models.CharField(max_length=100, blank=True, verbose_name='Rue') pcode = models.CharField(max_length=4, verbose_name='Code postal') @@ -128,7 +131,8 @@ class Corporation(models.Model): ordering = ('name',) def __unicode__(self): - return self.name + sect = ' (%s)' % self.sector if self.sector else '' + return "%s%s, %s %s" % (self.name, sect, self.pcode, self.city) class CorpContact(models.Model): diff --git a/stages/views.py b/stages/views.py index 39df66b..264a40f 100644 --- a/stages/views.py +++ b/stages/views.py @@ -213,6 +213,7 @@ EXPORT_FIELDS = [ ('Prénom référent', 'referent__first_name'), ('Nom référent', 'referent__last_name'), ('Courriel référent', 'referent__email'), ('Institution', 'availability__corporation__name'), + ('ID externe Inst.', 'availability__corporation__ext_id'), ('Rue Inst.', 'availability__corporation__street'), ('NPA Inst.', 'availability__corporation__pcode'), ('Ville Inst.', 'availability__corporation__city'), @@ -222,6 +223,7 @@ EXPORT_FIELDS = [ ('Civilité contact', 'availability__contact__title'), ('Prénom contact', 'availability__contact__first_name'), ('Nom contact', 'availability__contact__last_name'), + ('ID externe contact', 'availability__contact__ext_id'), ('Tél contact', 'availability__contact__tel'), ('Courriel contact', 'availability__contact__email'), ('Courriel contact - copie', None),