1 from datetime
import datetime
3 from django
import forms
4 from django
.contrib
.auth
import authenticate
5 from django
.contrib
.auth
.models
import User
6 from django
.http
import HttpResponse
7 from django
.shortcuts
import render_to_response
8 from django
.template
import loader
, Context
9 from django
.utils
import simplejson
10 from auf
.django
.emploi
import models
as emploi
15 STATUS_ERROR_NOT_FOUND
= 404
16 STATUS_ERROR_PERMISSIONS
= 403
17 STATUS_ERROR_BADMETHOD
= 405
19 def api_return(status
, text
='', json
=False):
20 content_type
= 'text/plain'
21 if status
== STATUS_OK
and json
:
22 content_type
= 'text/json'
25 if status
== STATUS_ERROR
:
27 elif status
== STATUS_ERROR_NOT_FOUND
:
28 text
= 'Resource Not Found'
29 elif status
== STATUS_ERROR_PERMISSIONS
:
30 text
= 'Invalid username or password'
31 elif status
== STATUS_ERROR_BADMETHOD
:
32 text
= 'Invalid request method'
33 elif status
== STATUS_OK
:
36 r
= HttpResponse(status
=status
, content
=text
, content_type
=content_type
)
38 if status
== STATUS_ERROR_BADMETHOD
:
46 # L'échange d'information doit être possible qu'avec les HOST désirés.
47 def __init__(self
, request
):
48 self
.request
= request
50 def candidat_add(self
, candidat
):
52 candidat_dict
= simplejson
.loads(candidat
)
53 cand
= emploi
.Candidat()
54 cand
.offre_emploi
= candidat_dict('offre_emploi')
55 cand
.prenom
= candidat_dict('prenom')
56 cand
.nom
= candidat_dict('nom')
57 cand
.genre
= candidat_dict('genre')
58 cand
.nationalite
= candidat_dict('nationalite')
59 cand
.situation_famille
= candidat_dict('situation_famille')
60 cand
.nombre_dependant
= candidat_dict('nombre_dependant')
61 cand
.niveau_diplome
= candidat_dict('niveau_diplome')
62 cand
.employeur_actuel
= candidat_dict('employeur_actuel')
63 cand
.poste_actuel
= candidat_dict('poste_actuel')
64 cand
.domaine_professionnel
= candidat_dict('domaine_professionnel')
65 cand
.telephone
= candidat_dict('telephone')
66 cand
.email
= candidat_dict('email')
67 cand
.adresse
= candidat_dict('adresse')
68 cand
.ville
= candidat_dict('ville')
69 cand
.etat_province
= candidat_dict('etat_province')
70 cand
.code_postal
= candidat_dict('code_postal')
71 cand
.pays
= candidat_dict('pays')
74 return api_return(STATUS_ERROR
)
75 return api_return(STATUS_OK
)
78 def offre_emploi(self
, id_offre_emploi
=None):
79 if id_offre_emploi
is None:
80 return api_return(STATUS_OK
, simplejson
.dumps(
81 [{"id": "%s" % offre
.id,
82 "nom": "%s" % offre
.nom
,
83 "resume": "%s" % offre
.resume
,
84 "description": "%s" % offre
.description
,
85 "date_limite": "%s" % offre
.date_limite
,
86 "duree_affectation": "%s" % offre
.duree_affectation
,
87 "renumeration": "%s" % offre
.renumeration
,
88 "debut_affectation": "%s" % offre
.debut_affectation
,
89 "lieu_affectation": "%s" % offre
.lieu_affectation
}
90 for offre
in emploi
.OffreEmploi
.objects
.all()]), json
=True)
92 offre
= emploi
.OffreEmploi
.objects
.get(id=id_offre_emploi
)
93 return api_return(STATUS_OK
, simplejson
.dumps(
94 {"id": "%s" % offre
.id,
95 "nom": "%s" % offre
.nom
,
96 "resume": "%s" % offre
.resume
,
97 "description": "%s" % offre
.description
,
98 "date_limite": "%s" % offre
.date_limite
,
99 "duree_affectation": "%s" % offre
.duree_affectation
,
100 "renumeration": "%s" % offre
.renumeration
,
101 "debut_affectation": "%s" % offre
.debut_affectation
,
102 "lieu_affectation": "%s" % offre
.lieu_affectation
}), json
=True)