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 | |
32c22f96 NBV |
6 | import datamaster_modeles.models as ref |
7 | ||
14e06ff6 | 8 | from restkit import request as req |
43198a9f NBV |
9 | from restkit import Resource |
10 | from httplib2 import Http | |
3a542b85 | 11 | import urllib2 |
32c22f96 NBV |
12 | from poster.encode import multipart_encode, MultipartParam |
13 | from poster.streaminghttp import StreamingHTTPHandler, StreamingHTTPRedirectHandler, StreamingHTTPSHandler, register_openers | |
14 | from StringIO import StringIO | |
15 | import urllib2, poster.streaminghttp | |
16 | ||
3a542b85 NBV |
17 | |
18 | ||
32c22f96 NBV |
19 | import settings |
20 | from auf.django.emploi import models as emploi | |
21 | ||
3a542b85 | 22 | STATUS_OK = '200 OK' |
f77f4b9b NBV |
23 | |
24 | class API: | |
25 | def __init__(self, request): | |
26 | self.request = request | |
27 | ||
30945e50 NBV |
28 | def offre_emploi_liste(self, env): |
29 | ||
30 | if hasattr(settings, "RECRUTEMENT_URL"): | |
31 | url = getattr(settings, "RECRUTEMENT_URL")[env] + "offre_emploi_liste/" | |
32 | else: | |
33 | raise ImportError, "Could not import settings RECRUTEMENT_PATH" | |
14e06ff6 | 34 | r = req(url) |
f77f4b9b | 35 | liste_json = r.body_string() |
13b8a64e NBV |
36 | try: |
37 | liste_offres = simplejson.loads(liste_json) | |
38 | except: | |
39 | return [] | |
f77f4b9b NBV |
40 | obj_offres_emploi = [] |
41 | ||
42 | for offre_dict in liste_offres: | |
43 | offre = emploi.OffreEmploi() | |
32c22f96 | 44 | offre.id = offre_dict['id'] |
8e0d552d NBV |
45 | offre.est_affiche = offre_dict['est_affiche'] |
46 | offre.statut = offre_dict['statut'] | |
f77f4b9b NBV |
47 | offre.nom = offre_dict['nom'] |
48 | offre.resume = offre_dict['resume'] | |
49 | offre.description = offre_dict['description'] | |
e2968e84 | 50 | offre.poste_nom = offre_dict['poste_nom'] |
d46075cb NBV |
51 | offre.date_limite = offre_dict['date_limite'] |
52 | offre.region = ref.Region.objects.get(id=offre_dict['region']) | |
53 | offre.bureau = ref.Bureau.objects.get(id=offre_dict['bureau']) | |
f77f4b9b NBV |
54 | offre.duree_affectation = offre_dict['duree_affectation'] |
55 | offre.renumeration = offre_dict['renumeration'] | |
56 | offre.debut_affectation = offre_dict['debut_affectation'] | |
32c22f96 NBV |
57 | offre.lieu_affectation = ref.Implantation.objects.\ |
58 | get(id=offre_dict['lieu_affectation']) | |
f77f4b9b NBV |
59 | obj_offres_emploi.append(offre) |
60 | return obj_offres_emploi | |
61 | ||
30945e50 NBV |
62 | def offre_emploi(self, offre_id, env): |
63 | if hasattr(settings, "RECRUTEMENT_URL"): | |
64 | url = getattr(settings, "RECRUTEMENT_URL")[env] + "offre_emploi/?id=%s" | |
65 | else: | |
66 | raise ImportError, "Could not import settings RECRUTEMENT_PATH" | |
67 | r = req(url % offre_id) | |
f77f4b9b | 68 | offre_json = r.body_string() |
13b8a64e NBV |
69 | |
70 | try: | |
71 | offre_dict = simplejson.loads(offre_json) | |
72 | except: | |
73 | return [] | |
d46075cb | 74 | obj_offres_emploi = [] |
f77f4b9b | 75 | |
d46075cb | 76 | offre = emploi.OffreEmploi() |
32c22f96 | 77 | offre.id = offre_dict['id'] |
8e0d552d NBV |
78 | offre.est_affiche = offre_dict['est_affiche'] |
79 | offre.statut = offre_dict['statut'] | |
d46075cb NBV |
80 | offre.nom = offre_dict['nom'] |
81 | offre.resume = offre_dict['resume'] | |
82 | offre.description = offre_dict['description'] | |
e2968e84 | 83 | offre.poste_nom = offre_dict['poste_nom'] |
d46075cb NBV |
84 | offre.date_limite = offre_dict['date_limite'] |
85 | offre.region = ref.Region.objects.get(id=offre_dict['region']) | |
86 | offre.bureau = ref.Bureau.objects.get(id=offre_dict['bureau']) | |
87 | offre.duree_affectation = offre_dict['duree_affectation'] | |
88 | offre.renumeration = offre_dict['renumeration'] | |
89 | offre.debut_affectation = offre_dict['debut_affectation'] | |
32c22f96 NBV |
90 | offre.lieu_affectation = ref.Implantation.objects.\ |
91 | get(id=offre_dict['lieu_affectation']) | |
d46075cb NBV |
92 | obj_offres_emploi.append(offre) |
93 | return obj_offres_emploi | |
94 | ||
30945e50 NBV |
95 | def candidat_add(self, offre_id, env): |
96 | if hasattr(settings, "RECRUTEMENT_URL"): | |
97 | url = getattr(settings, "RECRUTEMENT_URL")[env] + "candidat_add/%s" | |
98 | else: | |
99 | raise ImportError, "Could not import settings RECRUTEMENT_PATH" | |
32c22f96 NBV |
100 | |
101 | ||
3a542b85 | 102 | return None |
d46075cb | 103 |