1.1 emploi (PDF)
authorOlivier Larchevêque <olivier.larcheveque@auf.org>
Thu, 22 Mar 2012 15:59:44 +0000 (11:59 -0400)
committerOlivier Larchevêque <olivier.larcheveque@auf.org>
Thu, 22 Mar 2012 15:59:44 +0000 (11:59 -0400)
src/auf.django.emploi/CHANGES
src/auf.django.emploi/auf/django/emploi/fields.py [new file with mode: 0644]
src/auf.django.emploi/auf/django/emploi/locale/fr/LC_MESSAGES/django.mo [new file with mode: 0644]
src/auf.django.emploi/auf/django/emploi/locale/fr/LC_MESSAGES/django.po [new file with mode: 0644]
src/auf.django.emploi/auf/django/emploi/models.py
src/auf.django.emploi/auf/django/emploi/templates/emploi/candidat_form.html [new file with mode: 0644]
src/auf.django.emploi/auf/django/emploi/urls.py [new file with mode: 0644]
src/auf.django.emploi/auf/django/emploi/views.py [new file with mode: 0644]
src/auf.django.emploi/setup.py

index f470d3b..f018c4e 100644 (file)
@@ -1,6 +1,13 @@
 auf.django.emploi
 =================
 
+1.1
+---
+
+* contrainte type de fichier (PDF)
+
+* vue de test
+
 1.0
 ---
 
diff --git a/src/auf.django.emploi/auf/django/emploi/fields.py b/src/auf.django.emploi/auf/django/emploi/fields.py
new file mode 100644 (file)
index 0000000..da66600
--- /dev/null
@@ -0,0 +1,49 @@
+# -*- coding: utf-8 -*-
+
+from django.db.models import FileField
+from django.forms import forms
+from django.template.defaultfilters import filesizeformat
+from django.utils.translation import ugettext_lazy as _
+
+class ContentTypeRestrictedFileField(FileField):
+    """
+    Same as FileField, but you can specify:
+        * content_types - list containing allowed content_types. Example: ['application/pdf', 'image/jpeg']
+        * max_upload_size - a number indicating the maximum file size allowed for upload.
+            2.5MB - 2621440
+            5MB - 5242880
+            10MB - 10485760
+            20MB - 20971520
+            50MB - 5242880
+            100MB 104857600
+            250MB - 214958080
+            500MB - 429916160
+"""
+    def __init__(self, *args, **kwargs):
+        self.content_types = kwargs.pop("content_types")
+        self.max_upload_size = kwargs.pop("max_upload_size")
+        
+        super(ContentTypeRestrictedFileField, self).__init__(*args, **kwargs)
+    
+    def clean(self, *args, **kwargs):        
+        data = super(ContentTypeRestrictedFileField, self).clean(*args, **kwargs)
+    
+        file = data.file
+        try:
+            params = {
+                    'max': filesizeformat(self.max_upload_size),
+                    'current': filesizeformat(file._size),
+                    'allowed': ", ".join(self.content_types),
+                    }
+            content_type = file.content_type
+            if content_type in self.content_types:
+                if file._size > self.max_upload_size:
+                    msgid = 'Please keep filesize under %(max)s. Current filesize %(current)s'
+                    raise forms.ValidationError(_(msgid) % params)
+            else:
+                msgid = "Filetype not supported. (allowed: %(allowed)s"
+                raise forms.ValidationError(_(msgid) % params)
+        except AttributeError:
+            pass        
+    
+        return data
diff --git a/src/auf.django.emploi/auf/django/emploi/locale/fr/LC_MESSAGES/django.mo b/src/auf.django.emploi/auf/django/emploi/locale/fr/LC_MESSAGES/django.mo
new file mode 100644 (file)
index 0000000..c779769
Binary files /dev/null and b/src/auf.django.emploi/auf/django/emploi/locale/fr/LC_MESSAGES/django.mo differ
diff --git a/src/auf.django.emploi/auf/django/emploi/locale/fr/LC_MESSAGES/django.po b/src/auf.django.emploi/auf/django/emploi/locale/fr/LC_MESSAGES/django.po
new file mode 100644 (file)
index 0000000..0b3da74
--- /dev/null
@@ -0,0 +1,28 @@
+# SOME DESCRIPTIVE TITLE.
+# Copyright (C) YEAR THE PACKAGE'S COPYRIGHT HOLDER
+# This file is distributed under the same license as the PACKAGE package.
+# FIRST AUTHOR <EMAIL@ADDRESS>, YEAR.
+#
+#, fuzzy
+msgid ""
+msgstr ""
+"Project-Id-Version: PACKAGE VERSION\n"
+"Report-Msgid-Bugs-To: \n"
+"POT-Creation-Date: 2012-03-22 11:38-0400\n"
+"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
+"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
+"Language-Team: LANGUAGE <LL@li.org>\n"
+"MIME-Version: 1.0\n"
+"Content-Type: text/plain; charset=UTF-8\n"
+"Content-Transfer-Encoding: 8bit\n"
+"Plural-Forms: nplurals=2; plural=(n > 1)\n"
+
+#: auf/django/emploi/fields.py:41
+#, python-format
+msgid "Please keep filesize under %(max)s. Current filesize %(current)s"
+msgstr "Le fichier est trop grand %(current)s.(max: %(max)s)"
+
+#: auf/django/emploi/fields.py:43
+#, python-format
+msgid "Filetype not supported. (allowed: %(allowed)s"
+msgstr "Type de fichier interdit. (autorisé(s): %(allowed)s)"
index efa52c6..31545e4 100644 (file)
@@ -3,6 +3,7 @@
 from django.core.files.storage import FileSystemStorage
 from django.db import models
 import datamaster_modeles.models as ref
+from fields import ContentTypeRestrictedFileField
 import settings
 
 ### CONSTANTES ###
@@ -153,8 +154,12 @@ class CandidatPiece(models.Model):
     candidat = models.ForeignKey(Candidat, db_column='candidat',
                 related_name='candidat_piece') 
     nom = models.CharField(max_length=3, choices=TYPE_PIECE_CHOICES)
-    path = models.FileField(verbose_name="Fichier", 
-                        upload_to=candidat_piece_dispatch, storage=storage_prive)
+    path = ContentTypeRestrictedFileField(verbose_name="Fichier", 
+                        upload_to=candidat_piece_dispatch,
+                        storage=storage_prive,
+                        content_types=['application/pdf', ],
+                        max_upload_size=5242880,
+                        )
 
     class Meta:
         db_table = 'emploi_pieces'
diff --git a/src/auf.django.emploi/auf/django/emploi/templates/emploi/candidat_form.html b/src/auf.django.emploi/auf/django/emploi/templates/emploi/candidat_form.html
new file mode 100644 (file)
index 0000000..f7be70f
--- /dev/null
@@ -0,0 +1,110 @@
+
+<form action="" method="post" enctype="multipart/form-data">
+<div class="BlocEmploi">
+    <fieldset>
+        <h2>Informations personnelles</h2>
+            <div class="tabtr">
+                <span class="tabtd">{{ form.prenom.label }} <span class="etoile">*</span></span>
+                <span class="tabtd2">{{ form.prenom }}</span>
+            </div>
+            <div class="tabtr">
+                <span class="tabtd">{{ form.nom.label }} <span class="etoile">*</span></span>
+                <span class="tabtd2">{{ form.nom }}</span>
+            </div>
+            <div class="tabtr">
+                <span class="tabtd">{{ form.genre.label }} <span class="etoile">*</span></span>
+                <span class="tabtd2">{{ form.genre }}</span>
+            </div>
+            <div class="tabtr">
+                <span class="tabtd">{{ form.nationalite.label }} <span class="etoile">*</span></span>
+                <span class="tabtd2">{{ form.nationalite }}</span>
+            </div>
+            <div class="tabtr">
+                <span class="tabtd">{{ form.situation_famille.label }} <span class="etoile">*</span></span>
+                <span class="tabtd2">{{ form.situation_famille }}</span>
+            </div>
+            <div class="tabtr">
+                <span class="tabtd">{{ form.nombre_dependant.label }} <span class="etoile">*</span></span>
+                <span class="tabtd2">{{ form.nombre_dependant }}<br />
+                    <span class="info">{{ form.nombre_dependant.help_text }}</span>
+                </span>
+            </div>          
+    </fieldset>
+    </div>
+    <div class="BlocEmploi">
+    <fieldset>
+        <h2>Coordonnées</h2>
+            <div class="tabtr">
+                <span class="tabtd">{{ form.telephone.label }} <span class="etoile">*</span></span>
+                <span class="tabtd2">{{ form.telephone }}</span>
+            </div>
+            <div class="tabtr">
+                <span class="tabtd">{{ form.email.label }} <span class="etoile">*</span></span>
+                <span class="tabtd2">{{ form.email }}</span>
+            </div>
+            <div class="tabtr">
+                <span class="tabtd">{{ form.adresse.label }} <span class="etoile">*</span></span>
+                <span class="tabtd2">{{ form.adresse }}</span>
+            </div>
+            <div class="tabtr">
+                <span class="tabtd">{{ form.ville.label }} <span class="etoile">*</span></span>
+                <span class="tabtd2">{{ form.ville }}</span>
+            </div>
+            <div class="tabtr">
+                <span class="tabtd">{{ form.etat_province.label }}</span>
+                <span class="tabtd2">{{ form.etat_province }}</span>
+            </div>
+            <div class="tabtr">
+                <span class="tabtd">{{ form.code_postal.label }} <span class="etoile">*</span></span>
+                <span class="tabtd2">{{ form.code_postal }}</span>
+            </div>
+            <div class="tabtr">
+                <span class="tabtd">{{ form.pays.label }} <span class="etoile">*</span></span>
+                <span class="tabtd2">{{ form.pays }}</span>
+            </div>
+    </fieldset>
+    </div>
+    <div class="BlocEmploi">
+    <fieldset>
+        <h2>Informations professionnelles</h2>
+           <div class="tabtr">
+                <span class="tabtd">{{ form.niveau_diplome.label }} <span class="etoile">*</span></span>
+                <span class="tabtd2">{{ form.niveau_diplome }}</span>
+            </div>
+            <div class="tabtr">
+                <span class="tabtd">{{ form.employeur_actuel.label }} <span class="etoile">*</span></span>
+                <span class="tabtd2">{{ form.employeur_actuel }}</span>
+            </div>
+            <div class="tabtr">
+                <span class="tabtd">{{ form.poste_actuel.label }} <span class="etoile">*</span></span>
+                <span class="tabtd2">{{ form.poste_actuel }}</span>
+            </div>
+            <div class="tabtr">
+                <span class="tabtd">{{ form.domaine_professionnel.label }} <span class="etoile">*</span></span>
+                <span class="tabtd2">{{ form.domaine_professionnel }}</span>
+            </div>
+    </fieldset>
+    </div>
+    <div class="BlocEmploi">
+    <fieldset>
+        <h2>Pièces jointes</h2>
+        <p class="info">CV, lettre de motivation...</p>
+        {% include "emploi/pieces.html" %}
+    </fieldset>
+    </div>
+    <div class="BlocEmploi">
+    <fieldset>
+        <h2>Vérification CAPTCHA</h2>
+        <p class="info">Entrez les caractères figurant dans l'image ci-dessous. <span class="etoile">*</span></p>
+            <tr>
+                <td>
+                    {{ form.captcha }} 
+                    {{ form.captcha.errors }}
+                </td>
+            </tr>
+    </fieldset>
+    </div>
+    <div class="submit-row">
+        <input type="submit" name="save" value="Envoyer votre candidature" />
+    </div>
+</form>
diff --git a/src/auf.django.emploi/auf/django/emploi/urls.py b/src/auf.django.emploi/auf/django/emploi/urls.py
new file mode 100644 (file)
index 0000000..94b5c1d
--- /dev/null
@@ -0,0 +1,7 @@
+# -*- encoding: utf-8 -*
+
+from django.conf.urls.defaults import patterns, url
+
+urlpatterns = patterns('auf.django.emploi.views',
+    url(r'^test/form$', 'postuler' , name='test_postuler'),
+)
diff --git a/src/auf.django.emploi/auf/django/emploi/views.py b/src/auf.django.emploi/auf/django/emploi/views.py
new file mode 100644 (file)
index 0000000..35ddd1d
--- /dev/null
@@ -0,0 +1,18 @@
+from django.core.urlresolvers import reverse
+from django.shortcuts import render_to_response, redirect
+from django.template import RequestContext, Context
+from auf.django.emploi import forms as emploiForms
+
+def postuler(request,):
+    if request.method == "POST":
+        form = emploiForms.PostulerOffreEmploiForm(request.POST)     
+        piecesForm = emploiForms.CandidatPieceForm(request.POST, request.FILES)
+        if form.is_valid() and piecesForm.is_valid():
+            redirect(reverse('test_postuler'))
+
+    else:
+        form = emploiForms.PostulerOffreEmploiForm()
+        piecesForm = emploiForms.CandidatPieceForm(instance=form.instance)
+    c = {'form' : form, 'piecesForm': piecesForm, 'page_title': 'Offre emploi', }  
+
+    return render_to_response('emploi/candidat_form.html', Context(c), RequestContext(request))
index 3d43851..6018138 100644 (file)
@@ -3,7 +3,7 @@
 from setuptools import setup, find_packages
 
 name = 'auf.django.emploi'
-version = '1.0'
+version = '1.1'
 
 setup(name=name,
       version=version,