--- /dev/null
+from datetime import datetime
+
+from django import forms
+from django.contrib.auth import authenticate
+from django.contrib.auth.models import User
+from django.http import HttpResponse
+from django.shortcuts import render_to_response
+from django.template import loader, Context
+from django.utils import simplejson
+from auf.django.emploi import models as emploi
+
+STATUS_OK = 200
+
+STATUS_ERROR = 400
+STATUS_ERROR_NOT_FOUND = 404
+STATUS_ERROR_PERMISSIONS = 403
+STATUS_ERROR_BADMETHOD = 405
+
+def api_return(status, text='', json=False):
+ content_type = 'text/plain'
+ if status == STATUS_OK and json:
+ content_type = 'text/json'
+
+ if text is None:
+ if status == STATUS_ERROR:
+ text = 'Error'
+ elif status == STATUS_ERROR_NOT_FOUND:
+ text = 'Resource Not Found'
+ elif status == STATUS_ERROR_PERMISSIONS:
+ text = 'Invalid username or password'
+ elif status == STATUS_ERROR_BADMETHOD:
+ text = 'Invalid request method'
+ elif status == STATUS_OK:
+ text = 'OK'
+
+ r = HttpResponse(status=status, content=text, content_type=content_type)
+
+ if status == STATUS_ERROR_BADMETHOD:
+ r.Allow = 'POST'
+
+ return r
+
+
+class API:
+ # TODO: Sécurité :
+ # L'échange d'information doit être possible qu'avec les HOST désirés.
+ def __init__(self, request):
+ self.request = request
+
+ def candidat_add(self, candidat):
+ try:
+ candidat_dict = simplejson.loads(candidat)
+ cand = emploi.Candidat()
+ cand.offre_emploi = candidat_dict('offre_emploi')
+ cand.prenom = candidat_dict('prenom')
+ cand.nom = candidat_dict('nom')
+ cand.genre = candidat_dict('genre')
+ cand.nationalite = candidat_dict('nationalite')
+ cand.situation_famille = candidat_dict('situation_famille')
+ cand.nombre_dependant = candidat_dict('nombre_dependant')
+ cand.niveau_diplome = candidat_dict('niveau_diplome')
+ cand.employeur_actuel = candidat_dict('employeur_actuel')
+ cand.poste_actuel = candidat_dict('poste_actuel')
+ cand.domaine_professionnel = candidat_dict('domaine_professionnel')
+ cand.telephone = candidat_dict('telephone')
+ cand.email = candidat_dict('email')
+ cand.adresse = candidat_dict('adresse')
+ cand.ville = candidat_dict('ville')
+ cand.etat_province = candidat_dict('etat_province')
+ cand.code_postal = candidat_dict('code_postal')
+ cand.pays = candidat_dict('pays')
+ cand.save()
+ except:
+ return api_return(STATUS_ERROR)
+ return api_return(STATUS_OK)
+
+
+ def offre_emploi(self, id_offre_emploi=None):
+ if id_offre_emploi is None:
+ return api_return(STATUS_OK, simplejson.dumps(
+ [{"id": "%s" % offre.id,
+ "nom": "%s" % offre.nom,
+ "resume": "%s" % offre.resume,
+ "description": "%s" % offre.description,
+ "date_limite": "%s" % offre.date_limite,
+ "duree_affectation": "%s" % offre.duree_affectation,
+ "renumeration": "%s" % offre.renumeration,
+ "debut_affectation": "%s" % offre.debut_affectation,
+ "lieu_affectation": "%s" % offre.lieu_affectation}
+ for offre in emploi.OffreEmploi.objects.all()]), json=True)
+ else:
+ offre = emploi.OffreEmploi.objects.get(id=id_offre_emploi)
+ return api_return(STATUS_OK, simplejson.dumps(
+ {"id": "%s" % offre.id,
+ "nom": "%s" % offre.nom,
+ "resume": "%s" % offre.resume,
+ "description": "%s" % offre.description,
+ "date_limite": "%s" % offre.date_limite,
+ "duree_affectation": "%s" % offre.duree_affectation,
+ "renumeration": "%s" % offre.renumeration,
+ "debut_affectation": "%s" % offre.debut_affectation,
+ "lieu_affectation": "%s" % offre.lieu_affectation}), json=True)
+