From 814119082f319440e00814676b92cd91d4865ed5 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?J=C3=A9r=C3=B4me=20Schneider?= <jschneider@entrouvert.com>
Date: Thu, 10 Jul 2014 18:20:30 +0200
Subject: [PATCH] ressources: improved socialisation place search

Fixes #5127
---
 calebasse/ressources/lookups.py                    |  29 +-
 .../0009_auto__add_field_school_display_name.py    | 324 +++++++++++++++++++++
 calebasse/ressources/models.py                     |  16 +
 3 files changed, 356 insertions(+), 13 deletions(-)
 create mode 100644 calebasse/ressources/migrations/0009_auto__add_field_school_display_name.py

diff --git a/calebasse/ressources/lookups.py b/calebasse/ressources/lookups.py
index f37d5b7..0932237 100644
--- a/calebasse/ressources/lookups.py
+++ b/calebasse/ressources/lookups.py
@@ -1,5 +1,8 @@
 # -*- coding: utf-8 -*-
 import itertools
+import re
+
+from django.db.models import Q
 
 from calebasse.lookups import CalebasseLookup
 from calebasse.personnes.models import Worker
@@ -61,24 +64,24 @@ class AllWorkerOrGroupLookup(WorkerOrGroupLookup):
 class SchoolLookup(CalebasseLookup):
     model = School
     search_field = 'name'
+    query_words = []
+
+    def get_query(self, q, request):
+        words = q.split()
+        self.query_words = words
+        lookups = [Q(display_name__icontains=word) for word in words]
+        return School.objects.filter(*lookups)
 
     def get_result(self, obj):
         return self.format_item_display(obj)
 
     def format_match(self, obj):
-        return self.format_item_display(obj)
+        display = obj.display_name
+        for word in self.query_words:
+            pattern = re.compile(r"(%s)" % word, re.IGNORECASE)
+            display = re.sub(pattern, r"<strong>\1</strong>", display)
+        return display
 
     def format_item_display(self, obj):
-        text = ''
-        if obj.school_type.name != 'Inconnu':
-            text = unicode(obj.school_type) + ' ' + obj.name
-        else:
-            text = obj.name
-        if obj.address:
-            text += " - "  + obj.address
-        if obj.private:
-            text += " (Privé)"
-        else:
-            text +=  " (Public)"
-        return text
+        return obj.display_name
 
diff --git a/calebasse/ressources/migrations/0009_auto__add_field_school_display_name.py b/calebasse/ressources/migrations/0009_auto__add_field_school_display_name.py
new file mode 100644
index 0000000..b0a13a9
--- /dev/null
+++ b/calebasse/ressources/migrations/0009_auto__add_field_school_display_name.py
@@ -0,0 +1,324 @@
+# -*- coding: utf-8 -*-
+from south.utils import datetime_utils as 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 'School.display_name'
+        db.add_column(u'ressources_school', 'display_name',
+                      self.gf('django.db.models.fields.CharField')(default='', max_length=256, null=True, blank=True),
+                      keep_default=False)
+        from calebasse.ressources.models import School
+        for school in School.objects.all():
+            school.save()
+
+
+    def backwards(self, orm):
+        # Deleting field 'School.display_name'
+        db.delete_column(u'ressources_school', 'display_name')
+
+
+    models = {
+        u'ressources.acttype': {
+            'Meta': {'ordering': "('-display_first', 'name')", 'object_name': 'ActType'},
+            'billable': ('django.db.models.fields.BooleanField', [], {'default': 'True'}),
+            'display_first': ('django.db.models.fields.BooleanField', [], {'default': 'False'}),
+            'group': ('django.db.models.fields.BooleanField', [], {'default': 'False'}),
+            u'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+            'name': ('django.db.models.fields.CharField', [], {'max_length': '150'}),
+            'old_id': ('django.db.models.fields.CharField', [], {'max_length': '256', 'null': 'True', 'blank': 'True'}),
+            'service': ('django.db.models.fields.related.ForeignKey', [], {'to': u"orm['ressources.Service']", 'null': 'True', 'blank': 'True'})
+        },
+        u'ressources.advicegiver': {
+            'Meta': {'object_name': 'AdviceGiver'},
+            u'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+            'name': ('django.db.models.fields.CharField', [], {'max_length': '150'})
+        },
+        u'ressources.analysemotive': {
+            'Meta': {'object_name': 'AnalyseMotive'},
+            u'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+            'name': ('django.db.models.fields.CharField', [], {'max_length': '150'})
+        },
+        u'ressources.codecftmea': {
+            'Meta': {'ordering': "['ordering_code']", 'object_name': 'CodeCFTMEA'},
+            'axe': ('django.db.models.fields.IntegerField', [], {'max_length': '1'}),
+            'code': ('django.db.models.fields.IntegerField', [], {}),
+            u'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+            'name': ('django.db.models.fields.CharField', [], {'max_length': '150'}),
+            'ordering_code': ('django.db.models.fields.CharField', [], {'max_length': '20', 'null': 'True', 'blank': 'True'})
+        },
+        u'ressources.familymotive': {
+            'Meta': {'object_name': 'FamilyMotive'},
+            u'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+            'name': ('django.db.models.fields.CharField', [], {'max_length': '150'})
+        },
+        u'ressources.familysituationtype': {
+            'Meta': {'object_name': 'FamilySituationType'},
+            u'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+            'name': ('django.db.models.fields.CharField', [], {'max_length': '150'})
+        },
+        u'ressources.healthcenter': {
+            'Meta': {'object_name': 'HealthCenter'},
+            'abbreviation': ('django.db.models.fields.CharField', [], {'default': 'True', 'max_length': '8', 'null': 'True'}),
+            'accounting_number': ('django.db.models.fields.CharField', [], {'max_length': '30', 'null': 'True', 'blank': 'True'}),
+            'active': ('django.db.models.fields.BooleanField', [], {'default': 'True'}),
+            'address': ('django.db.models.fields.CharField', [], {'max_length': '120'}),
+            'address_complement': ('django.db.models.fields.CharField', [], {'default': 'None', 'max_length': '120', 'null': 'True', 'blank': 'True'}),
+            'city': ('django.db.models.fields.CharField', [], {'max_length': '80'}),
+            'code': ('django.db.models.fields.CharField', [], {'max_length': '4', 'null': 'True', 'blank': 'True'}),
+            'computer_center_code': ('django.db.models.fields.CharField', [], {'default': 'True', 'max_length': '8', 'null': 'True'}),
+            'correspondant': ('django.db.models.fields.CharField', [], {'max_length': '80'}),
+            'dest_organism': ('django.db.models.fields.CharField', [], {'max_length': '8'}),
+            'email': ('django.db.models.fields.EmailField', [], {'max_length': '75', 'null': 'True', 'blank': 'True'}),
+            'fax': ('django.db.models.fields.CharField', [], {'max_length': '30', 'null': 'True', 'blank': 'True'}),
+            'hc_invoice': ('django.db.models.fields.related.ForeignKey', [], {'default': 'None', 'to': u"orm['ressources.HealthCenter']", 'null': 'True', 'blank': 'True'}),
+            'health_fund': ('django.db.models.fields.CharField', [], {'max_length': '3'}),
+            u'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+            'large_regime': ('django.db.models.fields.related.ForeignKey', [], {'to': u"orm['ressources.LargeRegime']"}),
+            'name': ('django.db.models.fields.CharField', [], {'max_length': '150'}),
+            'phone': ('django.db.models.fields.CharField', [], {'max_length': '30'}),
+            'zip_code': ('django.db.models.fields.CharField', [], {'max_length': '8'})
+        },
+        u'ressources.holidaytype': {
+            'Meta': {'object_name': 'HolidayType'},
+            'for_group': ('django.db.models.fields.BooleanField', [], {'default': 'False'}),
+            u'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+            'name': ('django.db.models.fields.CharField', [], {'max_length': '150'})
+        },
+        u'ressources.inscriptionmotive': {
+            'Meta': {'object_name': 'InscriptionMotive'},
+            u'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+            'name': ('django.db.models.fields.CharField', [], {'max_length': '150'})
+        },
+        u'ressources.job': {
+            'Meta': {'object_name': 'Job'},
+            u'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+            'name': ('django.db.models.fields.CharField', [], {'max_length': '150'})
+        },
+        u'ressources.largeregime': {
+            'Meta': {'object_name': 'LargeRegime'},
+            'code': ('django.db.models.fields.CharField', [], {'max_length': '2'}),
+            u'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+            'name': ('django.db.models.fields.CharField', [], {'max_length': '150'})
+        },
+        u'ressources.managementcode': {
+            'Meta': {'object_name': 'ManagementCode'},
+            'code': ('django.db.models.fields.CharField', [], {'max_length': '10'}),
+            u'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+            'name': ('django.db.models.fields.CharField', [], {'max_length': '150'}),
+            'old_id': ('django.db.models.fields.CharField', [], {'max_length': '256', 'null': 'True', 'blank': 'True'})
+        },
+        u'ressources.maritalstatustype': {
+            'Meta': {'object_name': 'MaritalStatusType'},
+            u'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+            'name': ('django.db.models.fields.CharField', [], {'max_length': '150'})
+        },
+        u'ressources.mdph': {
+            'Meta': {'object_name': 'MDPH'},
+            'address': ('django.db.models.fields.CharField', [], {'max_length': '120', 'null': 'True', 'blank': 'True'}),
+            'address_complement': ('django.db.models.fields.CharField', [], {'default': 'None', 'max_length': '120', 'null': 'True', 'blank': 'True'}),
+            'city': ('django.db.models.fields.CharField', [], {'max_length': '80', 'null': 'True', 'blank': 'True'}),
+            'department': ('django.db.models.fields.CharField', [], {'max_length': '200'}),
+            'description': ('django.db.models.fields.TextField', [], {'null': 'True', 'blank': 'True'}),
+            'email': ('django.db.models.fields.EmailField', [], {'max_length': '75', 'null': 'True', 'blank': 'True'}),
+            'fax': ('calebasse.models.PhoneNumberField', [], {'max_length': '20', 'null': 'True', 'blank': 'True'}),
+            u'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+            'phone': ('calebasse.models.PhoneNumberField', [], {'max_length': '20', 'null': 'True', 'blank': 'True'}),
+            'website': ('django.db.models.fields.CharField', [], {'max_length': '200', 'null': 'True', 'blank': 'True'}),
+            'zip_code': ('calebasse.models.ZipCodeField', [], {'max_length': '5', 'null': 'True', 'blank': 'True'})
+        },
+        u'ressources.mdphrequest': {
+            'Meta': {'object_name': 'MDPHRequest'},
+            'comment': ('django.db.models.fields.TextField', [], {'max_length': '3000', 'null': 'True', 'blank': 'True'}),
+            'created': ('django.db.models.fields.DateTimeField', [], {'auto_now_add': 'True', 'blank': 'True'}),
+            u'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+            'mdph': ('django.db.models.fields.related.ForeignKey', [], {'to': u"orm['ressources.MDPH']"}),
+            'start_date': ('django.db.models.fields.DateField', [], {})
+        },
+        u'ressources.mdphresponse': {
+            'Meta': {'object_name': 'MDPHResponse'},
+            'comment': ('django.db.models.fields.TextField', [], {'max_length': '3000', 'null': 'True', 'blank': 'True'}),
+            'created': ('django.db.models.fields.DateTimeField', [], {'auto_now_add': 'True', 'blank': 'True'}),
+            'end_date': ('django.db.models.fields.DateField', [], {}),
+            u'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+            'mdph': ('django.db.models.fields.related.ForeignKey', [], {'to': u"orm['ressources.MDPH']"}),
+            'name': ('django.db.models.fields.CharField', [], {'max_length': '200', 'null': 'True', 'blank': 'True'}),
+            'rate': ('django.db.models.fields.CharField', [], {'max_length': '10', 'null': 'True', 'blank': 'True'}),
+            'start_date': ('django.db.models.fields.DateField', [], {}),
+            'type_aide': ('django.db.models.fields.IntegerField', [], {'default': '0', 'max_length': '1'})
+        },
+        u'ressources.nationality': {
+            'Meta': {'object_name': 'Nationality'},
+            u'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+            'name': ('django.db.models.fields.CharField', [], {'max_length': '150'})
+        },
+        u'ressources.office': {
+            'Meta': {'object_name': 'Office'},
+            'address': ('django.db.models.fields.CharField', [], {'default': 'None', 'max_length': '120', 'null': 'True', 'blank': 'True'}),
+            'address_complement': ('django.db.models.fields.CharField', [], {'default': 'None', 'max_length': '120', 'null': 'True', 'blank': 'True'}),
+            'city': ('django.db.models.fields.CharField', [], {'default': 'None', 'max_length': '80', 'null': 'True', 'blank': 'True'}),
+            'description': ('django.db.models.fields.TextField', [], {'null': 'True', 'blank': 'True'}),
+            'email': ('django.db.models.fields.EmailField', [], {'max_length': '75', 'null': 'True', 'blank': 'True'}),
+            'fax': ('calebasse.models.PhoneNumberField', [], {'max_length': '20', 'null': 'True', 'blank': 'True'}),
+            u'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+            'name': ('django.db.models.fields.CharField', [], {'max_length': '150'}),
+            'phone': ('calebasse.models.PhoneNumberField', [], {'max_length': '20', 'null': 'True', 'blank': 'True'}),
+            'zip_code': ('calebasse.models.ZipCodeField', [], {'default': 'None', 'max_length': '5', 'null': 'True', 'blank': 'True'})
+        },
+        u'ressources.outmotive': {
+            'Meta': {'object_name': 'OutMotive'},
+            u'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+            'name': ('django.db.models.fields.CharField', [], {'max_length': '150'})
+        },
+        u'ressources.outto': {
+            'Meta': {'object_name': 'OutTo'},
+            u'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+            'name': ('django.db.models.fields.CharField', [], {'max_length': '150'})
+        },
+        u'ressources.parentalauthoritytype': {
+            'Meta': {'object_name': 'ParentalAuthorityType'},
+            u'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+            'name': ('django.db.models.fields.CharField', [], {'max_length': '150'})
+        },
+        u'ressources.parentalcustodytype': {
+            'Meta': {'object_name': 'ParentalCustodyType'},
+            u'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+            'name': ('django.db.models.fields.CharField', [], {'max_length': '150'})
+        },
+        u'ressources.patientrelatedlink': {
+            'Meta': {'object_name': 'PatientRelatedLink'},
+            u'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+            'name': ('django.db.models.fields.CharField', [], {'max_length': '150'}),
+            'old_camsp_id': ('django.db.models.fields.CharField', [], {'max_length': '256', 'null': 'True', 'blank': 'True'}),
+            'old_cmpp_id': ('django.db.models.fields.CharField', [], {'max_length': '256', 'null': 'True', 'blank': 'True'}),
+            'old_sessad_dys_id': ('django.db.models.fields.CharField', [], {'max_length': '256', 'null': 'True', 'blank': 'True'}),
+            'old_sessad_ted_id': ('django.db.models.fields.CharField', [], {'max_length': '256', 'null': 'True', 'blank': 'True'})
+        },
+        u'ressources.priceperact': {
+            'Meta': {'object_name': 'PricePerAct'},
+            u'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+            'price': ('django.db.models.fields.DecimalField', [], {'max_digits': '5', 'decimal_places': '2'}),
+            'start_date': ('django.db.models.fields.DateField', [], {})
+        },
+        u'ressources.provenance': {
+            'Meta': {'object_name': 'Provenance'},
+            u'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+            'name': ('django.db.models.fields.CharField', [], {'max_length': '150'}),
+            'old_id': ('django.db.models.fields.CharField', [], {'max_length': '256', 'null': 'True', 'blank': 'True'}),
+            'old_service': ('django.db.models.fields.CharField', [], {'max_length': '256', 'null': 'True', 'blank': 'True'})
+        },
+        u'ressources.provenanceplace': {
+            'Meta': {'object_name': 'ProvenancePlace'},
+            u'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+            'name': ('django.db.models.fields.CharField', [], {'max_length': '150'})
+        },
+        u'ressources.ressource': {
+            'Meta': {'object_name': 'Ressource'},
+            'etablissement': ('django.db.models.fields.related.ForeignKey', [], {'to': u"orm['ressources.Office']"}),
+            u'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+            'name': ('django.db.models.fields.CharField', [], {'max_length': '150'})
+        },
+        u'ressources.school': {
+            'Meta': {'object_name': 'School'},
+            'address': ('django.db.models.fields.CharField', [], {'default': 'None', 'max_length': '120', 'null': 'True', 'blank': 'True'}),
+            'address_complement': ('django.db.models.fields.CharField', [], {'default': 'None', 'max_length': '120', 'null': 'True', 'blank': 'True'}),
+            'city': ('django.db.models.fields.CharField', [], {'default': 'None', 'max_length': '80', 'null': 'True', 'blank': 'True'}),
+            'description': ('django.db.models.fields.TextField', [], {'default': 'None', 'null': 'True', 'blank': 'True'}),
+            'director_name': ('django.db.models.fields.CharField', [], {'default': 'None', 'max_length': '70', 'null': 'True', 'blank': 'True'}),
+            'display_name': ('django.db.models.fields.CharField', [], {'default': "''", 'max_length': '256', 'null': 'True', 'blank': 'True'}),
+            'email': ('django.db.models.fields.EmailField', [], {'default': 'None', 'max_length': '75', 'null': 'True', 'blank': 'True'}),
+            'fax': ('django.db.models.fields.CharField', [], {'default': 'None', 'max_length': '30', 'null': 'True', 'blank': 'True'}),
+            u'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+            'name': ('django.db.models.fields.CharField', [], {'max_length': '150'}),
+            'old_id': ('django.db.models.fields.CharField', [], {'max_length': '256', 'null': 'True', 'blank': 'True'}),
+            'old_service': ('django.db.models.fields.CharField', [], {'max_length': '256', 'null': 'True', 'blank': 'True'}),
+            'phone': ('calebasse.models.PhoneNumberField', [], {'default': 'None', 'max_length': '20', 'null': 'True', 'blank': 'True'}),
+            'private': ('django.db.models.fields.BooleanField', [], {'default': 'False'}),
+            'school_type': ('django.db.models.fields.related.ForeignKey', [], {'to': u"orm['ressources.SchoolType']"}),
+            'zip_code': ('calebasse.models.ZipCodeField', [], {'default': 'None', 'max_length': '5', 'null': 'True', 'blank': 'True'})
+        },
+        u'ressources.schoollevel': {
+            'Meta': {'object_name': 'SchoolLevel'},
+            u'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+            'name': ('django.db.models.fields.CharField', [], {'max_length': '150'}),
+            'old_id': ('django.db.models.fields.CharField', [], {'max_length': '256', 'null': 'True', 'blank': 'True'}),
+            'old_service': ('django.db.models.fields.CharField', [], {'max_length': '256', 'null': 'True', 'blank': 'True'})
+        },
+        u'ressources.schoolteacherrole': {
+            'Meta': {'object_name': 'SchoolTeacherRole'},
+            u'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+            'name': ('django.db.models.fields.CharField', [], {'max_length': '150'})
+        },
+        u'ressources.schooltype': {
+            'Meta': {'object_name': 'SchoolType'},
+            u'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+            'name': ('django.db.models.fields.CharField', [], {'max_length': '150'}),
+            'services': ('django.db.models.fields.related.ManyToManyField', [], {'to': u"orm['ressources.Service']", 'symmetrical': 'False'})
+        },
+        u'ressources.service': {
+            'Meta': {'object_name': 'Service'},
+            'description': ('django.db.models.fields.TextField', [], {}),
+            'email': ('django.db.models.fields.EmailField', [], {'max_length': '75'}),
+            'fax': ('calebasse.models.PhoneNumberField', [], {'max_length': '20'}),
+            u'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+            'name': ('django.db.models.fields.CharField', [], {'max_length': '150'}),
+            'phone': ('calebasse.models.PhoneNumberField', [], {'max_length': '20'}),
+            'slug': ('django.db.models.fields.SlugField', [], {'max_length': '50'})
+        },
+        u'ressources.sessiontype': {
+            'Meta': {'object_name': 'SessionType'},
+            u'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+            'name': ('django.db.models.fields.CharField', [], {'max_length': '150'})
+        },
+        u'ressources.socialisationduration': {
+            'Meta': {'object_name': 'SocialisationDuration'},
+            'comment': ('django.db.models.fields.TextField', [], {'max_length': '3000', 'null': 'True', 'blank': 'True'}),
+            'contact': ('django.db.models.fields.CharField', [], {'default': 'None', 'max_length': '200', 'null': 'True', 'blank': 'True'}),
+            'created': ('django.db.models.fields.DateTimeField', [], {'auto_now_add': 'True', 'blank': 'True'}),
+            'end_date': ('django.db.models.fields.DateField', [], {'null': 'True', 'blank': 'True'}),
+            u'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+            'level': ('django.db.models.fields.related.ForeignKey', [], {'to': u"orm['ressources.SchoolLevel']", 'null': 'True', 'blank': 'True'}),
+            'redoublement': ('django.db.models.fields.BooleanField', [], {'default': 'False'}),
+            'school': ('django.db.models.fields.related.ForeignKey', [], {'to': u"orm['ressources.School']", 'null': 'True', 'blank': 'True'}),
+            'start_date': ('django.db.models.fields.DateField', [], {})
+        },
+        u'ressources.transportcompany': {
+            'Meta': {'object_name': 'TransportCompany'},
+            'address': ('django.db.models.fields.CharField', [], {'default': 'None', 'max_length': '120', 'null': 'True', 'blank': 'True'}),
+            'address_complement': ('django.db.models.fields.CharField', [], {'default': 'None', 'max_length': '120', 'null': 'True', 'blank': 'True'}),
+            'city': ('django.db.models.fields.CharField', [], {'default': 'None', 'max_length': '80', 'null': 'True', 'blank': 'True'}),
+            'correspondant': ('django.db.models.fields.CharField', [], {'max_length': '80', 'null': 'True', 'blank': 'True'}),
+            'description': ('django.db.models.fields.TextField', [], {'default': 'None', 'null': 'True', 'blank': 'True'}),
+            'email': ('django.db.models.fields.EmailField', [], {'max_length': '75', 'null': 'True', 'blank': 'True'}),
+            'fax': ('django.db.models.fields.CharField', [], {'default': 'None', 'max_length': '30', 'null': 'True', 'blank': 'True'}),
+            u'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+            'name': ('django.db.models.fields.CharField', [], {'max_length': '150'}),
+            'old_camsp_id': ('django.db.models.fields.CharField', [], {'max_length': '256', 'null': 'True', 'blank': 'True'}),
+            'old_cmpp_id': ('django.db.models.fields.CharField', [], {'max_length': '256', 'null': 'True', 'blank': 'True'}),
+            'old_sessad_dys_id': ('django.db.models.fields.CharField', [], {'max_length': '256', 'null': 'True', 'blank': 'True'}),
+            'old_sessad_ted_id': ('django.db.models.fields.CharField', [], {'max_length': '256', 'null': 'True', 'blank': 'True'}),
+            'phone': ('calebasse.models.PhoneNumberField', [], {'default': 'None', 'max_length': '20', 'null': 'True', 'blank': 'True'}),
+            'zip_code': ('calebasse.models.ZipCodeField', [], {'default': 'None', 'max_length': '5', 'null': 'True', 'blank': 'True'})
+        },
+        u'ressources.transporttype': {
+            'Meta': {'object_name': 'TransportType'},
+            u'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+            'name': ('django.db.models.fields.CharField', [], {'max_length': '150'})
+        },
+        u'ressources.uninvoicablecode': {
+            'Meta': {'object_name': 'UninvoicableCode'},
+            u'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'})
+        },
+        u'ressources.workertype': {
+            'Meta': {'object_name': 'WorkerType'},
+            u'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+            'intervene': ('django.db.models.fields.BooleanField', [], {'default': 'False'}),
+            'name': ('django.db.models.fields.CharField', [], {'max_length': '150'})
+        }
+    }
+
+    complete_apps = ['ressources']
diff --git a/calebasse/ressources/models.py b/calebasse/ressources/models.py
index d63e17e..793bf50 100644
--- a/calebasse/ressources/models.py
+++ b/calebasse/ressources/models.py
@@ -226,6 +226,22 @@ class School(NamedAbstractModel):
             return unicode(self.school_type) + ' ' + self.name
         return self.name
 
+    def save(self, **kwargs):
+        self.display_name = ""
+        if self.school_type.name != 'Inconnu':
+            self.display_name = unicode(self.school_type) + ' ' + self.name
+        else:
+            self.display_name = self.name
+        if self.address:
+            self.display_name += " - "  + self.address
+        if self.private:
+            self.display_name += " (Privé)"
+        else:
+            self.display_name +=  " (Public)"
+        super(School, self).save(**kwargs)
+
+    display_name = models.CharField(max_length=256,
+            blank=True, null=True, default='')
     school_type = models.ForeignKey('ressources.SchoolType',
         verbose_name=u"Type d'établissement")
     description = models.TextField(blank=True, null=True, default=None)
-- 
2.0.1

