From 932eef9a80aa2506cc5677395514e59363095b5c Mon Sep 17 00:00:00 2001 From: Ali Jetha Date: Mon, 30 Aug 2010 08:29:59 -0400 Subject: [PATCH] Chercheurs --- auf_savoirs_en_partage/chercheurs/forms.py | 13 ++++++ auf_savoirs_en_partage/chercheurs/models.py | 49 ++++++++++++++++++++ auf_savoirs_en_partage/chercheurs/tests.py | 23 +++++++++ auf_savoirs_en_partage/chercheurs/views.py | 29 ++++++++++++ auf_savoirs_en_partage/production.py | 3 ++ auf_savoirs_en_partage/settings.py | 1 + auf_savoirs_en_partage/templates/500.html | 1 + .../templates/chercheurs/inscription.html | 16 +++++++ .../templates/chercheurs/personne.html | 15 ++++++ auf_savoirs_en_partage/templates/render_field.html | 14 ++++++ auf_savoirs_en_partage/templates/render_form.html | 3 ++ auf_savoirs_en_partage/templates/table_form.html | 3 ++ auf_savoirs_en_partage/urls.py | 2 + 13 files changed, 172 insertions(+) create mode 100644 auf_savoirs_en_partage/chercheurs/__init__.py create mode 100644 auf_savoirs_en_partage/chercheurs/forms.py create mode 100644 auf_savoirs_en_partage/chercheurs/models.py create mode 100644 auf_savoirs_en_partage/chercheurs/tests.py create mode 100644 auf_savoirs_en_partage/chercheurs/views.py create mode 100644 auf_savoirs_en_partage/templates/500.html create mode 100644 auf_savoirs_en_partage/templates/chercheurs/inscription.html create mode 100644 auf_savoirs_en_partage/templates/chercheurs/personne.html create mode 100644 auf_savoirs_en_partage/templates/render_field.html create mode 100644 auf_savoirs_en_partage/templates/render_form.html create mode 100644 auf_savoirs_en_partage/templates/table_form.html diff --git a/auf_savoirs_en_partage/chercheurs/__init__.py b/auf_savoirs_en_partage/chercheurs/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/auf_savoirs_en_partage/chercheurs/forms.py b/auf_savoirs_en_partage/chercheurs/forms.py new file mode 100644 index 0000000..fa2ec47 --- /dev/null +++ b/auf_savoirs_en_partage/chercheurs/forms.py @@ -0,0 +1,13 @@ +# -*- encoding: utf-8 -*- +from django import forms +from models import * + +class PersonneForm(forms.ModelForm): + class Meta: + model = Personne + fields = ('nom', 'prenom', 'courriel', 'genre') + +class ChercheurForm(forms.ModelForm): + class Meta: + model = Chercheur + fields = ('pays', 'discipline', 'groupes') diff --git a/auf_savoirs_en_partage/chercheurs/models.py b/auf_savoirs_en_partage/chercheurs/models.py new file mode 100644 index 0000000..aa2e206 --- /dev/null +++ b/auf_savoirs_en_partage/chercheurs/models.py @@ -0,0 +1,49 @@ +# -*- encoding: utf-8 -*- +from django.db import models +from auf_references_client.models import Discipline, Pays + +GENRE_CHOICES = (('H', 'Homme'), ('F', 'Femme')) +class Personne(models.Model): + + id = models.AutoField(primary_key=True) + salutation = models.CharField(max_length=128, null = True, blank = True) + nom = models.CharField(max_length=255) + prenom = models.CharField(max_length=128, verbose_name = 'Prénom') + courriel = models.CharField(max_length=128, blank = True) + fonction = models.CharField(max_length=128, null = True, blank = True) + sousfonction = models.CharField(max_length=128, null = True, blank = True, + verbose_name = 'Sous-fonction') + mobile = models.CharField(max_length=32, null = True, blank = True, + verbose_name = 'Numéro de téléphone portable ') + genre = models.CharField(max_length=1, choices=GENRE_CHOICES) + commentaire = models.TextField(verbose_name = 'Commentaires', null = True, + blank = True) + actif = models.BooleanField(editable = False) + + def __unicode__(self): + return u"%s %s, %s" % (self.prenom, self.nom, self.courriel) + + class Meta: + ordering = ["prenom", "nom"] + +class Chercheur(models.Model): + id = models.AutoField(primary_key=True, db_column='id') + personne = models.ForeignKey('Personne') + discipline = models.ForeignKey(Discipline) + pays = models.ForeignKey(Pays) + groupes = models.ManyToManyField('Groupe', through='ChercheurGroupe') + actif = models.BooleanField(editable = False) + + +class Groupe(models.Model): + id = models.AutoField(primary_key=True, db_column='id') + nom = models.CharField(max_length=255, db_column='nom') + actif = models.BooleanField(editable = False, db_column='actif') + + def __unicode__(self): + return u"%s" % (self.nom) + +class ChercheurGroupe(models.Model): + chercheur = models.ForeignKey('Chercheur') + groupe = models.ForeignKey('Groupe') + date_inscription = models.DateField(auto_now=True) diff --git a/auf_savoirs_en_partage/chercheurs/tests.py b/auf_savoirs_en_partage/chercheurs/tests.py new file mode 100644 index 0000000..2247054 --- /dev/null +++ b/auf_savoirs_en_partage/chercheurs/tests.py @@ -0,0 +1,23 @@ +""" +This file demonstrates two different styles of tests (one doctest and one +unittest). These will both pass when you run "manage.py test". + +Replace these with more appropriate tests for your application. +""" + +from django.test import TestCase + +class SimpleTest(TestCase): + def test_basic_addition(self): + """ + Tests that 1 + 1 always equals 2. + """ + self.failUnlessEqual(1 + 1, 2) + +__test__ = {"doctest": """ +Another way to test that 1 + 1 is equal to 2. + +>>> 1 + 1 == 2 +True +"""} + diff --git a/auf_savoirs_en_partage/chercheurs/views.py b/auf_savoirs_en_partage/chercheurs/views.py new file mode 100644 index 0000000..b4cc42b --- /dev/null +++ b/auf_savoirs_en_partage/chercheurs/views.py @@ -0,0 +1,29 @@ +# Create your views here. +from django.shortcuts import render_to_response +from django.template import Context, RequestContext +from forms import * + +from auf_references_client.models import Discipline, TypeImplantation +from models import Personne + +def inscription(request): + if request.method == 'POST': + personne_form = PersonneForm (request.POST, prefix="personne") + chercheur_form = ChercheurForm (request.POST, prefix="chercheur") + if personne_form.is_valid(): + if chercheur_form.is_valid(): + p = personne_form.save() + c = chercheur_form.save(commit=False) + c.personne = p + c.save() + else: + personne_form = PersonneForm(prefix="personne") + chercheur_form = ChercheurForm(prefix="chercheur") + + variables = { 'personne_form': personne_form, + 'chercheur_form': chercheur_form, + } + + return render_to_response ("chercheurs/inscription.html", \ + Context (variables), + context_instance = RequestContext(request)) diff --git a/auf_savoirs_en_partage/production.py b/auf_savoirs_en_partage/production.py index f88417b..cdc9de5 100644 --- a/auf_savoirs_en_partage/production.py +++ b/auf_savoirs_en_partage/production.py @@ -1 +1,4 @@ from auf_savoirs_en_partage.settings import * + +DEBUG=True +TEMPLATE_DEBUG=DEBUG diff --git a/auf_savoirs_en_partage/settings.py b/auf_savoirs_en_partage/settings.py index 644e3fb..1840698 100644 --- a/auf_savoirs_en_partage/settings.py +++ b/auf_savoirs_en_partage/settings.py @@ -49,6 +49,7 @@ INSTALLED_APPS = ( 'django_roa', 'timezones', 'savoirs', + 'chercheurs', ) TEMPLATE_LOADERS = ( diff --git a/auf_savoirs_en_partage/templates/500.html b/auf_savoirs_en_partage/templates/500.html new file mode 100644 index 0000000..35fff58 --- /dev/null +++ b/auf_savoirs_en_partage/templates/500.html @@ -0,0 +1 @@ +erreur 500 diff --git a/auf_savoirs_en_partage/templates/chercheurs/inscription.html b/auf_savoirs_en_partage/templates/chercheurs/inscription.html new file mode 100644 index 0000000..aba7736 --- /dev/null +++ b/auf_savoirs_en_partage/templates/chercheurs/inscription.html @@ -0,0 +1,16 @@ +{% extends "container_base.html" %} + +{% block contenu %} +
+

Informations générales

+ {% with personne_form as form %} + {% include "table_form.html" %} + {% endwith %} + {% with chercheur_form as form %} + {% include "table_form.html" %} + {% endwith %} + +
+{% endblock %} diff --git a/auf_savoirs_en_partage/templates/chercheurs/personne.html b/auf_savoirs_en_partage/templates/chercheurs/personne.html new file mode 100644 index 0000000..8558181 --- /dev/null +++ b/auf_savoirs_en_partage/templates/chercheurs/personne.html @@ -0,0 +1,15 @@ +{% extends "container_base.html" %} + +{% block contenu %} +{% for d in disciplines %} +
  • {{d}}
  • +{% endfor %} + +
    + +{% for p in personnes %} +
  • {{p}}
  • +{% endfor %} + + +{% endblock %} diff --git a/auf_savoirs_en_partage/templates/render_field.html b/auf_savoirs_en_partage/templates/render_field.html new file mode 100644 index 0000000..636d7b4 --- /dev/null +++ b/auf_savoirs_en_partage/templates/render_field.html @@ -0,0 +1,14 @@ + + {% if field.is_hidden %} + {{ field }} + {% else %} + + {{ field.label_tag }} + {% if field.errors %} + {{ field.errors }} + {% endif %} + + {{ field }} + + {% endif %} + diff --git a/auf_savoirs_en_partage/templates/render_form.html b/auf_savoirs_en_partage/templates/render_form.html new file mode 100644 index 0000000..e242675 --- /dev/null +++ b/auf_savoirs_en_partage/templates/render_form.html @@ -0,0 +1,3 @@ +{% for field in form %} +{% include "render_field.html" %} +{% endfor %} diff --git a/auf_savoirs_en_partage/templates/table_form.html b/auf_savoirs_en_partage/templates/table_form.html new file mode 100644 index 0000000..6ff4fa3 --- /dev/null +++ b/auf_savoirs_en_partage/templates/table_form.html @@ -0,0 +1,3 @@ + + {% include "render_form.html" %} +
    diff --git a/auf_savoirs_en_partage/urls.py b/auf_savoirs_en_partage/urls.py index 6d4e414..3c66dc2 100644 --- a/auf_savoirs_en_partage/urls.py +++ b/auf_savoirs_en_partage/urls.py @@ -28,6 +28,8 @@ urlpatterns = patterns( (r'^json/get/$', 'savoirs.views.json_get'), (r'^json/set/$', 'savoirs.views.json_set'), + + (r'^chercheurs/inscription/$', 'chercheurs.views.inscription'), ) if settings.DEBUG: -- 1.7.10.4