Fix temporaire
[auf_savoirs_en_partage_django.git] / auf_savoirs_en_partage_django / savoirs / views.py
CommitLineData
d15017b2 1# -*- encoding: utf-8 -*-
5ecd5424 2import datetime, simplejson
d15017b2
CR
3from django.shortcuts import render_to_response
4from django.template import Context, RequestContext
5ecd5424
CR
5from django.http import HttpResponse
6from django.contrib.auth.decorators import login_required
d15017b2
CR
7from models import Actualite
8from savoirs import configuration
a008c7e5 9from recherche import cherche, google_search
5ecd5424 10from auf_savoirs_en_partage_backend.sep.io import SEP
d15017b2
CR
11
12def index (request):
13 delta = datetime.timedelta (days = 90)
14 oldest = datetime.date.today () - delta
15 articles = Actualite.objects.filter (visible = '1', date__gt = oldest)
16 articles = articles[0:configuration['accueil_actualite']]
5ecd5424 17 return render_to_response ("savoirs/index.html", \
d15017b2
CR
18 Context ({"articles": articles}), \
19 context_instance = RequestContext(request))
20
21def recherche (request):
d15017b2
CR
22 q = request.GET.get("q", "")
23 page = int(request.GET.get("page", 0))
24
40a5ebfb 25 r = cherche (page, q)
d15017b2 26
5ecd5424 27 return render_to_response ("savoirs/recherche.html", \
d15017b2
CR
28 Context ({'q': q,
29 'page': page,
30 'data': r}), \
31 context_instance = RequestContext(request))
32
a008c7e5
CR
33def avancee (request):
34 type = request.GET.get("type", "")
35 page = int(request.GET.get("page", 0))
36
cebcab65
CR
37 ##TEMP
38 r = {'results': [], 'last_page': 0, 'more_link': ''}
39
a008c7e5
CR
40 q = request.GET.get("google-q", "")
41
42 if type == 'google':
43 r = cherche (page, q, type)
44
45 return render_to_response ("savoirs/avancee.html", \
46 Context ({'type': type,
47 'page': page,
48 'data': r,
49 'q': q}),
50 context_instance = RequestContext(request))
51
d15017b2 52def conseils (request):
5ecd5424 53 return render_to_response ("savoirs/conseils.html", \
d15017b2
CR
54 Context (), \
55 context_instance = RequestContext(request))
56
57def a_propos (request):
5ecd5424 58 return render_to_response ("savoirs/a-propos.html", \
d15017b2
CR
59 Context (), \
60 context_instance = RequestContext(request))
61
62def nous_contacter (request):
5ecd5424 63 return render_to_response ("savoirs/contact.html", \
d15017b2
CR
64 Context (), \
65 context_instance = RequestContext(request))
5ecd5424
CR
66
67@login_required
68def json_get (request):
69 uri = request.GET.get ("uri")
70 if uri:
71 s = SEP ()
72 res = s.search ({'uri': uri.encode("utf-8")})
73 if len (res) > 0:
74 r = s.get (res[0])
75
76 return HttpResponse(simplejson.dumps(r),
77 mimetype='application/json')
78
79@login_required
80def json_set (request):
81 data = request.POST.get("data")
82 if data:
83 r = simplejson.loads(data)
84 s = SEP ()
85 s.add (r)
86 return HttpResponse(simplejson.dumps("OK"),
87 mimetype='application/json')