Ajout formulaire, liens pour login
[auf_savoirs_en_partage_django.git] / auf_savoirs_en_partage_django / savoirs / views.py
1 # -*- encoding: utf-8 -*-
2 import datetime, simplejson
3 from django.shortcuts import render_to_response
4 from django.template import Context, RequestContext
5 from django.http import HttpResponse
6 from django.contrib.auth.decorators import login_required
7 from models import Actualite
8 from savoirs import configuration
9 from recherche import cherche
10 from auf_savoirs_en_partage_backend.sep.io import SEP
11
12 def 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']]
17 return render_to_response ("savoirs/index.html", \
18 Context ({"articles": articles}), \
19 context_instance = RequestContext(request))
20
21 def recherche (request):
22 results = None
23 q = request.GET.get("q", "")
24 page = int(request.GET.get("page", 0))
25
26 r = cherche (page, q)
27
28 return render_to_response ("savoirs/recherche.html", \
29 Context ({'q': q,
30 'page': page,
31 'data': r}), \
32 context_instance = RequestContext(request))
33
34 def conseils (request):
35 return render_to_response ("savoirs/conseils.html", \
36 Context (), \
37 context_instance = RequestContext(request))
38
39 def a_propos (request):
40 return render_to_response ("savoirs/a-propos.html", \
41 Context (), \
42 context_instance = RequestContext(request))
43
44 def nous_contacter (request):
45 return render_to_response ("savoirs/contact.html", \
46 Context (), \
47 context_instance = RequestContext(request))
48
49 @login_required
50 def json_get (request):
51 uri = request.GET.get ("uri")
52 if uri:
53 s = SEP ()
54 res = s.search ({'uri': uri.encode("utf-8")})
55 if len (res) > 0:
56 r = s.get (res[0])
57
58 return HttpResponse(simplejson.dumps(r),
59 mimetype='application/json')
60
61 @login_required
62 def json_set (request):
63 data = request.POST.get("data")
64 if data:
65 r = simplejson.loads(data)
66 s = SEP ()
67 s.add (r)
68 return HttpResponse(simplejson.dumps("OK"),
69 mimetype='application/json')