Ajout bouton impression avec style d'impression pour les fiches des candidats
[auf_django_emploi.git] / auf / django / emploi / api.py
CommitLineData
d691a5d3
NBV
1# -*- encoding: utf-8 -*
2from django.shortcuts import render_to_response, redirect, get_object_or_404
448f1dfa 3from django.template import Context, RequestContext
d691a5d3
NBV
4
5from django.utils import simplejson
efd28a79
NBV
6import datamaster_modeles.models as ref
7
449e9e93 8from restkit import request as req
36b8eabb
NBV
9from restkit import Resource
10from httplib2 import Http
3d78c976 11import urllib2
efd28a79
NBV
12from poster.encode import multipart_encode, MultipartParam
13from poster.streaminghttp import StreamingHTTPHandler, StreamingHTTPRedirectHandler, StreamingHTTPSHandler, register_openers
14from StringIO import StringIO
15import urllib2, poster.streaminghttp
16
3d78c976
NBV
17
18
efd28a79
NBV
19import settings
20from auf.django.emploi import models as emploi
21
3d78c976 22STATUS_OK = '200 OK'
d691a5d3
NBV
23
24class API:
25 def __init__(self, request):
26 self.request = request
27
7f2e1e11
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"
449e9e93 34 r = req(url)
d691a5d3 35 liste_json = r.body_string()
1ff71303
NBV
36 try:
37 liste_offres = simplejson.loads(liste_json)
38 except:
39 return []
d691a5d3
NBV
40 obj_offres_emploi = []
41
42 for offre_dict in liste_offres:
43 offre = emploi.OffreEmploi()
efd28a79 44 offre.id = offre_dict['id']
8acb3cd3
NBV
45 offre.est_affiche = offre_dict['est_affiche']
46 offre.statut = offre_dict['statut']
d691a5d3
NBV
47 offre.nom = offre_dict['nom']
48 offre.resume = offre_dict['resume']
49 offre.description = offre_dict['description']
44accb6d 50 offre.poste_nom = offre_dict['poste_nom']
448f1dfa
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'])
d691a5d3
NBV
54 offre.duree_affectation = offre_dict['duree_affectation']
55 offre.renumeration = offre_dict['renumeration']
56 offre.debut_affectation = offre_dict['debut_affectation']
efd28a79
NBV
57 offre.lieu_affectation = ref.Implantation.objects.\
58 get(id=offre_dict['lieu_affectation'])
d691a5d3
NBV
59 obj_offres_emploi.append(offre)
60 return obj_offres_emploi
61
7f2e1e11
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)
d691a5d3 68 offre_json = r.body_string()
1ff71303
NBV
69
70 try:
71 offre_dict = simplejson.loads(offre_json)
72 except:
73 return []
448f1dfa 74 obj_offres_emploi = []
d691a5d3 75
448f1dfa 76 offre = emploi.OffreEmploi()
efd28a79 77 offre.id = offre_dict['id']
8acb3cd3
NBV
78 offre.est_affiche = offre_dict['est_affiche']
79 offre.statut = offre_dict['statut']
448f1dfa
NBV
80 offre.nom = offre_dict['nom']
81 offre.resume = offre_dict['resume']
82 offre.description = offre_dict['description']
44accb6d 83 offre.poste_nom = offre_dict['poste_nom']
448f1dfa
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']
efd28a79
NBV
90 offre.lieu_affectation = ref.Implantation.objects.\
91 get(id=offre_dict['lieu_affectation'])
448f1dfa
NBV
92 obj_offres_emploi.append(offre)
93 return obj_offres_emploi
94
7f2e1e11
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"
efd28a79
NBV
100
101
3d78c976 102 return None
448f1dfa 103