Add an always_cc field on contacts which is exported as extra column
This commit is contained in:
parent
8d8454ba56
commit
1b6ce3acfe
4 changed files with 139 additions and 6 deletions
|
|
@ -41,12 +41,13 @@ class ReferentAdmin(admin.ModelAdmin):
|
|||
|
||||
class CorpContactAdmin(admin.ModelAdmin):
|
||||
list_display = ('__unicode__', 'corporation', 'role')
|
||||
fields = (('corporation', 'is_main'), ('title', 'last_name', 'first_name'),
|
||||
fields = (('corporation', 'is_main', 'always_cc'),
|
||||
('title', 'last_name', 'first_name'),
|
||||
'role', ('tel', 'email'))
|
||||
|
||||
class ContactInline(admin.StackedInline):
|
||||
model = CorpContact
|
||||
fields = ('is_main', ('title', 'last_name', 'first_name'),
|
||||
fields = (('is_main', 'always_cc'), ('title', 'last_name', 'first_name'),
|
||||
('role', 'tel', 'email'))
|
||||
extra = 1
|
||||
|
||||
|
|
|
|||
124
stages/migrations/0008_add_contact_cc.py
Normal file
124
stages/migrations/0008_add_contact_cc.py
Normal file
|
|
@ -0,0 +1,124 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
import datetime
|
||||
from south.db import db
|
||||
from south.v2 import SchemaMigration
|
||||
from django.db import models
|
||||
|
||||
|
||||
class Migration(SchemaMigration):
|
||||
|
||||
def forwards(self, orm):
|
||||
# Adding field 'CorpContact.always_cc'
|
||||
db.add_column(u'stages_corpcontact', 'always_cc',
|
||||
self.gf('django.db.models.fields.BooleanField')(default=False),
|
||||
keep_default=False)
|
||||
|
||||
|
||||
def backwards(self, orm):
|
||||
# Deleting field 'CorpContact.always_cc'
|
||||
db.delete_column(u'stages_corpcontact', 'always_cc')
|
||||
|
||||
|
||||
models = {
|
||||
u'stages.availability': {
|
||||
'Meta': {'object_name': 'Availability'},
|
||||
'comment': ('django.db.models.fields.TextField', [], {'blank': 'True'}),
|
||||
'contact': ('django.db.models.fields.related.ForeignKey', [], {'to': u"orm['stages.CorpContact']", 'null': 'True', 'blank': 'True'}),
|
||||
'corporation': ('django.db.models.fields.related.ForeignKey', [], {'to': u"orm['stages.Corporation']"}),
|
||||
'domain': ('django.db.models.fields.related.ForeignKey', [], {'to': u"orm['stages.Domain']"}),
|
||||
u'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
|
||||
'period': ('django.db.models.fields.related.ForeignKey', [], {'to': u"orm['stages.Period']"})
|
||||
},
|
||||
u'stages.corpcontact': {
|
||||
'Meta': {'object_name': 'CorpContact'},
|
||||
'always_cc': ('django.db.models.fields.BooleanField', [], {'default': 'False'}),
|
||||
'corporation': ('django.db.models.fields.related.ForeignKey', [], {'to': u"orm['stages.Corporation']"}),
|
||||
'email': ('django.db.models.fields.CharField', [], {'max_length': '40', 'blank': 'True'}),
|
||||
'first_name': ('django.db.models.fields.CharField', [], {'max_length': '40', 'blank': 'True'}),
|
||||
u'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
|
||||
'is_main': ('django.db.models.fields.BooleanField', [], {'default': 'False'}),
|
||||
'last_name': ('django.db.models.fields.CharField', [], {'max_length': '40'}),
|
||||
'role': ('django.db.models.fields.CharField', [], {'max_length': '40', 'blank': 'True'}),
|
||||
'tel': ('django.db.models.fields.CharField', [], {'max_length': '20', 'blank': 'True'}),
|
||||
'title': ('django.db.models.fields.CharField', [], {'max_length': '40', 'blank': 'True'})
|
||||
},
|
||||
u'stages.corporation': {
|
||||
'Meta': {'ordering': "(u'name',)", 'object_name': 'Corporation'},
|
||||
'archived': ('django.db.models.fields.BooleanField', [], {'default': 'False'}),
|
||||
'city': ('django.db.models.fields.CharField', [], {'max_length': '40'}),
|
||||
'email': ('django.db.models.fields.EmailField', [], {'max_length': '75', 'blank': 'True'}),
|
||||
u'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
|
||||
'name': ('django.db.models.fields.CharField', [], {'unique': 'True', 'max_length': '100'}),
|
||||
'pcode': ('django.db.models.fields.CharField', [], {'max_length': '4'}),
|
||||
'street': ('django.db.models.fields.CharField', [], {'max_length': '100', 'blank': 'True'}),
|
||||
'tel': ('django.db.models.fields.CharField', [], {'max_length': '20', 'blank': 'True'}),
|
||||
'typ': ('django.db.models.fields.CharField', [], {'max_length': '40', 'blank': 'True'}),
|
||||
'web': ('django.db.models.fields.URLField', [], {'max_length': '200', 'blank': 'True'})
|
||||
},
|
||||
u'stages.domain': {
|
||||
'Meta': {'ordering': "(u'name',)", 'object_name': 'Domain'},
|
||||
u'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
|
||||
'name': ('django.db.models.fields.CharField', [], {'max_length': '50'})
|
||||
},
|
||||
u'stages.klass': {
|
||||
'Meta': {'object_name': 'Klass'},
|
||||
u'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
|
||||
'level': ('django.db.models.fields.related.ForeignKey', [], {'to': u"orm['stages.Level']"}),
|
||||
'name': ('django.db.models.fields.CharField', [], {'max_length': '10'}),
|
||||
'section': ('django.db.models.fields.related.ForeignKey', [], {'to': u"orm['stages.Section']"})
|
||||
},
|
||||
u'stages.level': {
|
||||
'Meta': {'object_name': 'Level'},
|
||||
u'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
|
||||
'name': ('django.db.models.fields.CharField', [], {'max_length': '10'})
|
||||
},
|
||||
u'stages.period': {
|
||||
'Meta': {'ordering': "(u'-start_date',)", 'object_name': 'Period'},
|
||||
'end_date': ('django.db.models.fields.DateField', [], {}),
|
||||
u'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
|
||||
'level': ('django.db.models.fields.related.ForeignKey', [], {'to': u"orm['stages.Level']"}),
|
||||
'section': ('django.db.models.fields.related.ForeignKey', [], {'to': u"orm['stages.Section']"}),
|
||||
'start_date': ('django.db.models.fields.DateField', [], {}),
|
||||
'title': ('django.db.models.fields.CharField', [], {'max_length': '150'})
|
||||
},
|
||||
u'stages.referent': {
|
||||
'Meta': {'ordering': "(u'last_name', u'first_name')", 'object_name': 'Referent'},
|
||||
'abrev': ('django.db.models.fields.CharField', [], {'max_length': '10', 'blank': 'True'}),
|
||||
'archived': ('django.db.models.fields.BooleanField', [], {'default': 'False'}),
|
||||
'email': ('django.db.models.fields.EmailField', [], {'max_length': '75', 'blank': 'True'}),
|
||||
'first_name': ('django.db.models.fields.CharField', [], {'max_length': '40'}),
|
||||
u'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
|
||||
'last_name': ('django.db.models.fields.CharField', [], {'max_length': '40'})
|
||||
},
|
||||
u'stages.section': {
|
||||
'Meta': {'object_name': 'Section'},
|
||||
u'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
|
||||
'name': ('django.db.models.fields.CharField', [], {'max_length': '20'})
|
||||
},
|
||||
u'stages.student': {
|
||||
'Meta': {'object_name': 'Student'},
|
||||
'archived': ('django.db.models.fields.BooleanField', [], {'default': 'False'}),
|
||||
'birth_date': ('django.db.models.fields.DateField', [], {}),
|
||||
'city': ('django.db.models.fields.CharField', [], {'max_length': '40'}),
|
||||
'email': ('django.db.models.fields.EmailField', [], {'max_length': '75', 'blank': 'True'}),
|
||||
'ext_id': ('django.db.models.fields.IntegerField', [], {'unique': 'True', 'null': 'True'}),
|
||||
'first_name': ('django.db.models.fields.CharField', [], {'max_length': '40'}),
|
||||
u'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
|
||||
'klass': ('django.db.models.fields.related.ForeignKey', [], {'to': u"orm['stages.Klass']"}),
|
||||
'last_name': ('django.db.models.fields.CharField', [], {'max_length': '40'}),
|
||||
'mobile': ('django.db.models.fields.CharField', [], {'max_length': '40', 'blank': 'True'}),
|
||||
'pcode': ('django.db.models.fields.CharField', [], {'max_length': '4'}),
|
||||
'street': ('django.db.models.fields.CharField', [], {'max_length': '150', 'blank': 'True'}),
|
||||
'tel': ('django.db.models.fields.CharField', [], {'max_length': '40', 'blank': 'True'})
|
||||
},
|
||||
u'stages.training': {
|
||||
'Meta': {'object_name': 'Training'},
|
||||
'availability': ('django.db.models.fields.related.OneToOneField', [], {'to': u"orm['stages.Availability']", 'unique': 'True'}),
|
||||
'comment': ('django.db.models.fields.TextField', [], {'blank': 'True'}),
|
||||
u'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
|
||||
'referent': ('django.db.models.fields.related.ForeignKey', [], {'to': u"orm['stages.Referent']", 'null': 'True', 'blank': 'True'}),
|
||||
'student': ('django.db.models.fields.related.ForeignKey', [], {'to': u"orm['stages.Student']"})
|
||||
}
|
||||
}
|
||||
|
||||
complete_apps = ['stages']
|
||||
|
|
@ -134,6 +134,7 @@ class Corporation(models.Model):
|
|||
class CorpContact(models.Model):
|
||||
corporation = models.ForeignKey(Corporation, verbose_name='Institution')
|
||||
is_main = models.BooleanField(default=False, verbose_name='Contact principal')
|
||||
always_cc = models.BooleanField(default=False, verbose_name='Toujours en copie')
|
||||
title = models.CharField(max_length=40, blank=True, verbose_name='Civilité')
|
||||
first_name = models.CharField(max_length=40, blank=True, verbose_name='Prénom')
|
||||
last_name = models.CharField(max_length=40, verbose_name='Nom')
|
||||
|
|
|
|||
|
|
@ -221,6 +221,7 @@ EXPORT_FIELDS = [
|
|||
('Prénom contact', 'availability__contact__first_name'),
|
||||
('Nom contact', 'availability__contact__last_name'),
|
||||
('Courriel contact', 'availability__contact__email'),
|
||||
('Courriel contact - copie', None),
|
||||
]
|
||||
|
||||
NON_ATTR_EXPORT_FIELDS = [
|
||||
|
|
@ -237,6 +238,7 @@ NON_ATTR_EXPORT_FIELDS = [
|
|||
('Prénom contact', 'contact__first_name'),
|
||||
('Nom contact', 'contact__last_name'),
|
||||
('Courriel contact', 'contact__email'),
|
||||
('Courriel contact - copie', None),
|
||||
]
|
||||
|
||||
def stages_export(request):
|
||||
|
|
@ -266,10 +268,13 @@ def stages_export(request):
|
|||
query = Training.objects.all()
|
||||
|
||||
# Prepare "default" contacts (when not defined on training)
|
||||
contacts = {}
|
||||
default_contacts = dict((c, '') for c in Corporation.objects.all().values_list('name', flat=True))
|
||||
always_ccs = dict((c, []) for c in Corporation.objects.all().values_list('name', flat=True))
|
||||
for contact in CorpContact.objects.all().select_related('corporation').order_by('corporation'):
|
||||
if contact.corporation.name not in contacts or contact.is_main is True:
|
||||
contacts[contact.corporation.name] = contact
|
||||
if not default_contacts[contact.corporation.name] or contact.is_main is True:
|
||||
default_contacts[contact.corporation.name] = contact
|
||||
if contact.always_cc:
|
||||
always_ccs[contact.corporation.name].append(contact)
|
||||
|
||||
wb = Workbook()
|
||||
ws = wb.get_active_sheet()
|
||||
|
|
@ -285,12 +290,14 @@ def stages_export(request):
|
|||
ws.cell(row=row_idx, column=col_idx).value = tr[field]
|
||||
if tr[contact_test_field] is None:
|
||||
# Use default contact
|
||||
contact = contacts.get(tr[corp_name_field])
|
||||
contact = default_contacts.get(tr[corp_name_field])
|
||||
if contact:
|
||||
ws.cell(row=row_idx, column=col_idx-3).value = contact.title
|
||||
ws.cell(row=row_idx, column=col_idx-2).value = contact.first_name
|
||||
ws.cell(row=row_idx, column=col_idx-1).value = contact.last_name
|
||||
ws.cell(row=row_idx, column=col_idx).value = contact.email
|
||||
if always_ccs[tr[corp_name_field]]:
|
||||
ws.cell(row=row_idx, column=col_idx+1).value = "; ".join([c.email for c in always_ccs[tr[corp_name_field]]])
|
||||
|
||||
response = HttpResponse(save_virtual_workbook(wb), mimetype='application/ms-excel')
|
||||
response['Content-Disposition'] = 'attachment; filename=%s%s.xlsx' % (
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue