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