From 80cb4ebc307246a4b2c1e43ba7cda7fc711710b7 Mon Sep 17 00:00:00 2001 From: Claude Paroz Date: Fri, 5 Apr 2013 16:18:18 +0200 Subject: [PATCH] Add link from training to corporation contact --- common/urls.py | 1 + stages/admin.py | 1 + .../migrations/0003_add_training_contact.py | 122 ++++++++++++++++++ stages/models.py | 1 + stages/static/js/attribution.js | 19 ++- stages/views.py | 35 ++++- templates/attribution.html | 3 + 7 files changed, 173 insertions(+), 9 deletions(-) create mode 100644 stages/migrations/0003_add_training_contact.py diff --git a/common/urls.py b/common/urls.py index 54d4f97..68d1e40 100644 --- a/common/urls.py +++ b/common/urls.py @@ -30,4 +30,5 @@ urlpatterns = patterns('', url(r'^student/(?P\d+)/summary/', views.StudentSummaryView.as_view()), url(r'^availability/(?P\d+)/summary/', views.AvailabilitySummaryView.as_view()), + url(r'^corporation/(?P\d+)/contacts/', views.CorpContactJSONView.as_view()), ) diff --git a/stages/admin.py b/stages/admin.py index a34dea2..28fe2fa 100644 --- a/stages/admin.py +++ b/stages/admin.py @@ -83,6 +83,7 @@ class AvailabilityAdminForm(forms.ModelForm): class AvailabilityInline(admin.TabularInline): model = Availability form = AvailabilityAdminForm + ordering = ('corporation__name',) extra = 1 formfield_overrides = { models.TextField: {'widget': forms.Textarea(attrs={'rows':2, 'cols':40})}, diff --git a/stages/migrations/0003_add_training_contact.py b/stages/migrations/0003_add_training_contact.py new file mode 100644 index 0000000..b36f95d --- /dev/null +++ b/stages/migrations/0003_add_training_contact.py @@ -0,0 +1,122 @@ +# -*- 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 'Training.contact' + db.add_column('stages_training', 'contact', + self.gf('django.db.models.fields.related.ForeignKey')(to=orm['stages.CorpContact'], null=True, blank=True), + keep_default=False) + + + def backwards(self, orm): + # Deleting field 'Training.contact' + db.delete_column('stages_training', 'contact_id') + + + models = { + 'stages.availability': { + 'Meta': {'object_name': 'Availability'}, + 'comment': ('django.db.models.fields.TextField', [], {'blank': 'True'}), + 'corporation': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['stages.Corporation']"}), + 'domain': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['stages.Domain']"}), + 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}), + 'period': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['stages.Period']"}) + }, + 'stages.corpcontact': { + 'Meta': {'object_name': 'CorpContact'}, + 'corporation': ('django.db.models.fields.related.ForeignKey', [], {'to': "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'}), + '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'}) + }, + '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'}), + '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'}) + }, + 'stages.domain': { + 'Meta': {'ordering': "(u'name',)", 'object_name': 'Domain'}, + 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}), + 'name': ('django.db.models.fields.CharField', [], {'max_length': '50'}) + }, + 'stages.klass': { + 'Meta': {'object_name': 'Klass'}, + 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}), + 'level': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['stages.Level']"}), + 'name': ('django.db.models.fields.CharField', [], {'max_length': '10'}), + 'section': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['stages.Section']"}) + }, + 'stages.level': { + 'Meta': {'object_name': 'Level'}, + 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}), + 'name': ('django.db.models.fields.CharField', [], {'max_length': '10'}) + }, + 'stages.period': { + 'Meta': {'object_name': 'Period'}, + 'end_date': ('django.db.models.fields.DateField', [], {}), + 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}), + 'level': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['stages.Level']"}), + 'section': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['stages.Section']"}), + 'start_date': ('django.db.models.fields.DateField', [], {}), + 'title': ('django.db.models.fields.CharField', [], {'max_length': '150'}) + }, + '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'}), + 'first_name': ('django.db.models.fields.CharField', [], {'max_length': '40'}), + 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}), + 'last_name': ('django.db.models.fields.CharField', [], {'max_length': '40'}) + }, + 'stages.section': { + 'Meta': {'object_name': 'Section'}, + 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}), + 'name': ('django.db.models.fields.CharField', [], {'max_length': '20'}) + }, + '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'}), + 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}), + 'klass': ('django.db.models.fields.related.ForeignKey', [], {'to': "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'}) + }, + 'stages.training': { + 'Meta': {'object_name': 'Training'}, + 'availability': ('django.db.models.fields.related.OneToOneField', [], {'to': "orm['stages.Availability']", 'unique': 'True'}), + 'comment': ('django.db.models.fields.TextField', [], {'blank': 'True'}), + 'contact': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['stages.CorpContact']", 'null': 'True', 'blank': 'True'}), + 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}), + 'referent': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['stages.Referent']", 'null': 'True', 'blank': 'True'}), + 'student': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['stages.Student']"}) + } + } + + complete_apps = ['stages'] \ No newline at end of file diff --git a/stages/models.py b/stages/models.py index b29a8e6..d9ca6d1 100644 --- a/stages/models.py +++ b/stages/models.py @@ -191,6 +191,7 @@ class Training(models.Model): student = models.ForeignKey(Student, verbose_name='Étudiant') availability = models.OneToOneField(Availability, verbose_name='Disponibilité') referent = models.ForeignKey(Referent, null=True, blank=True, verbose_name='Référent') + contact = models.ForeignKey(CorpContact, null=True, blank=True, verbose_name='Contact institution') comment = models.TextField(blank=True, verbose_name='Remarques') class Meta: diff --git a/stages/static/js/attribution.js b/stages/static/js/attribution.js index 2015f59..dcb23f1 100644 --- a/stages/static/js/attribution.js +++ b/stages/static/js/attribution.js @@ -45,6 +45,7 @@ function update_corporations(period_id) { $('#corp_select').empty(); $('#corp_detail').html('').removeClass("filled"); current_avail = null; + $('#contact_select').find('option:gt(0)').remove(); $('input#valid_training').hide(); if (period_id == '') return; $.getJSON('/period/' + period_id + '/corporations/', function(data) { @@ -52,10 +53,11 @@ function update_corporations(period_id) { var domains = []; var options = []; $('#corp_filter').empty().append($("'); + var id_corp = $("option:selected", this).data('id_corp'); + $.getJSON('/corporation/' + id_corp + '/contacts/', function(data) { + $.each(data, function(key, contact) { + var item = contact.first_name + ' ' + contact.last_name; + if (contact.role.length) item += ' (' + contact.role + ')'; + sel.append($("