Ajout formulaire, liens pour login
[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
9from recherche import cherche
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):
22 results = None
23 q = request.GET.get("q", "")
24 page = int(request.GET.get("page", 0))
25
40a5ebfb 26 r = cherche (page, q)
d15017b2 27
5ecd5424 28 return render_to_response ("savoirs/recherche.html", \
d15017b2
CR
29 Context ({'q': q,
30 'page': page,
31 'data': r}), \
32 context_instance = RequestContext(request))
33
34def conseils (request):
5ecd5424 35 return render_to_response ("savoirs/conseils.html", \
d15017b2
CR
36 Context (), \
37 context_instance = RequestContext(request))
38
39def a_propos (request):
5ecd5424 40 return render_to_response ("savoirs/a-propos.html", \
d15017b2
CR
41 Context (), \
42 context_instance = RequestContext(request))
43
44def nous_contacter (request):
5ecd5424 45 return render_to_response ("savoirs/contact.html", \
d15017b2
CR
46 Context (), \
47 context_instance = RequestContext(request))
5ecd5424
CR
48
49@login_required
50def 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
62def 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')