Commit | Line | Data |
---|---|---|
f77f4b9b NBV |
1 | # -*- encoding: utf-8 -* |
2 | from django.shortcuts import render_to_response, redirect, get_object_or_404 | |
d46075cb | 3 | from django.template import Context, RequestContext |
f77f4b9b NBV |
4 | |
5 | from django.utils import simplejson | |
6 | from auf.django.emploi import models as emploi | |
14e06ff6 | 7 | from restkit import request as req |
43198a9f NBV |
8 | from restkit import Resource |
9 | from httplib2 import Http | |
10 | from urllib import urlencode | |
d46075cb | 11 | import datamaster_modeles.models as ref |
3a542b85 NBV |
12 | from poster.encode import MultipartParam |
13 | from poster.encode import multipart_encode | |
14 | import urllib2 | |
30945e50 | 15 | import settings |
3a542b85 NBV |
16 | |
17 | ||
18 | STATUS_OK = '200 OK' | |
f77f4b9b NBV |
19 | |
20 | class API: | |
21 | def __init__(self, request): | |
22 | self.request = request | |
23 | ||
30945e50 NBV |
24 | def offre_emploi_liste(self, env): |
25 | ||
26 | if hasattr(settings, "RECRUTEMENT_URL"): | |
27 | url = getattr(settings, "RECRUTEMENT_URL")[env] + "offre_emploi_liste/" | |
28 | else: | |
29 | raise ImportError, "Could not import settings RECRUTEMENT_PATH" | |
14e06ff6 | 30 | r = req(url) |
f77f4b9b | 31 | liste_json = r.body_string() |
13b8a64e NBV |
32 | try: |
33 | liste_offres = simplejson.loads(liste_json) | |
34 | except: | |
35 | return [] | |
f77f4b9b NBV |
36 | obj_offres_emploi = [] |
37 | ||
38 | for offre_dict in liste_offres: | |
39 | offre = emploi.OffreEmploi() | |
8e0d552d NBV |
40 | offre.est_affiche = offre_dict['est_affiche'] |
41 | offre.statut = offre_dict['statut'] | |
f77f4b9b NBV |
42 | offre.nom = offre_dict['nom'] |
43 | offre.resume = offre_dict['resume'] | |
44 | offre.description = offre_dict['description'] | |
e2968e84 | 45 | offre.poste_nom = offre_dict['poste_nom'] |
d46075cb NBV |
46 | offre.date_limite = offre_dict['date_limite'] |
47 | offre.region = ref.Region.objects.get(id=offre_dict['region']) | |
48 | offre.bureau = ref.Bureau.objects.get(id=offre_dict['bureau']) | |
f77f4b9b NBV |
49 | offre.duree_affectation = offre_dict['duree_affectation'] |
50 | offre.renumeration = offre_dict['renumeration'] | |
51 | offre.debut_affectation = offre_dict['debut_affectation'] | |
d46075cb | 52 | offre.lieu_affectation = ref.Implantation.objects.get(id=offre_dict['lieu_affectation']) |
f77f4b9b NBV |
53 | obj_offres_emploi.append(offre) |
54 | return obj_offres_emploi | |
55 | ||
30945e50 NBV |
56 | def offre_emploi(self, offre_id, env): |
57 | if hasattr(settings, "RECRUTEMENT_URL"): | |
58 | url = getattr(settings, "RECRUTEMENT_URL")[env] + "offre_emploi/?id=%s" | |
59 | else: | |
60 | raise ImportError, "Could not import settings RECRUTEMENT_PATH" | |
61 | r = req(url % offre_id) | |
f77f4b9b | 62 | offre_json = r.body_string() |
13b8a64e NBV |
63 | |
64 | try: | |
65 | offre_dict = simplejson.loads(offre_json) | |
66 | except: | |
67 | return [] | |
d46075cb | 68 | obj_offres_emploi = [] |
f77f4b9b | 69 | |
d46075cb | 70 | offre = emploi.OffreEmploi() |
8e0d552d NBV |
71 | offre.est_affiche = offre_dict['est_affiche'] |
72 | offre.statut = offre_dict['statut'] | |
d46075cb NBV |
73 | offre.nom = offre_dict['nom'] |
74 | offre.resume = offre_dict['resume'] | |
75 | offre.description = offre_dict['description'] | |
e2968e84 | 76 | offre.poste_nom = offre_dict['poste_nom'] |
d46075cb NBV |
77 | offre.date_limite = offre_dict['date_limite'] |
78 | offre.region = ref.Region.objects.get(id=offre_dict['region']) | |
79 | offre.bureau = ref.Bureau.objects.get(id=offre_dict['bureau']) | |
80 | offre.duree_affectation = offre_dict['duree_affectation'] | |
81 | offre.renumeration = offre_dict['renumeration'] | |
82 | offre.debut_affectation = offre_dict['debut_affectation'] | |
83 | offre.lieu_affectation = ref.Implantation.objects.get(id=offre_dict['lieu_affectation']) | |
84 | obj_offres_emploi.append(offre) | |
85 | return obj_offres_emploi | |
86 | ||
30945e50 NBV |
87 | def candidat_add(self, offre_id, env): |
88 | if hasattr(settings, "RECRUTEMENT_URL"): | |
89 | url = getattr(settings, "RECRUTEMENT_URL")[env] + "candidat_add/%s" | |
90 | else: | |
91 | raise ImportError, "Could not import settings RECRUTEMENT_PATH" | |
92 | r = Resource(url % offre_id) | |
3a542b85 | 93 | mp = MultipartParam.from_file('cv', self.request.POST.get('candidat_piece-0-nom')) |
3a542b85 | 94 | datagen, headers = multipart_encode([image_param]) |
3a542b85 NBV |
95 | resp = r.post(payload=self.request.FILES, params_dict=self.request.POST) |
96 | if resp.status == STATUS_OK: | |
97 | candidat_id = simplejson.loads(resp.body_string())['candidat_id'] | |
98 | return candidat_id | |
99 | return None | |
d46075cb | 100 |