| author | ymh <ymh.work@gmail.com> |
| Fri, 19 Jun 2015 18:25:35 +0200 | |
| changeset 627 | 3fd558fa38b1 |
| parent 608 | d1eb7acb5b84 |
| child 640 | 939461cc322b |
| permissions | -rw-r--r-- |
| 293 | 1 |
# -*- coding: utf-8 -*- |
2 |
''' |
|
3 |
Created on Jul 01, 2014 |
|
4 |
||
5 |
@author: tc |
|
6 |
''' |
|
| 308 | 7 |
|
| 293 | 8 |
from datetime import datetime |
| 473 | 9 |
import json |
10 |
import logging |
|
|
563
e25de27cba8c
do not load User model in module definition
ymh <ymh.work@gmail.com>
parents:
561
diff
changeset
|
11 |
from renkanmanager.views import RenkanGetPut |
| 473 | 12 |
import uuid |
13 |
||
| 308 | 14 |
from django.conf import settings |
|
563
e25de27cba8c
do not load User model in module definition
ymh <ymh.work@gmail.com>
parents:
561
diff
changeset
|
15 |
from django.contrib.auth import REDIRECT_FIELD_NAME, login as auth_login |
| 308 | 16 |
from django.contrib.auth.forms import AuthenticationForm |
17 |
from django.contrib.sites.models import get_current_site |
|
| 332 | 18 |
from django.core.paginator import Paginator, PageNotAnInteger, EmptyPage |
| 531 | 19 |
from django.core.urlresolvers import reverse |
|
299
8e00641076e7
remove renkan management to an other django app (see renkan hg repo)
cavaliet
parents:
297
diff
changeset
|
20 |
from django.db.models import Q |
| 310 | 21 |
from django.http import HttpResponse, HttpResponseBadRequest |
| 308 | 22 |
from django.http import HttpResponseRedirect |
| 332 | 23 |
from django.http.response import Http404 |
| 300 | 24 |
from django.shortcuts import get_object_or_404, redirect |
| 308 | 25 |
from django.shortcuts import resolve_url |
26 |
from django.template.response import TemplateResponse |
|
| 312 | 27 |
from django.templatetags.static import static |
| 308 | 28 |
from django.utils.http import is_safe_url |
| 338 | 29 |
from django.utils.translation import ugettext as _ |
| 308 | 30 |
from django.views.decorators.cache import never_cache |
31 |
from django.views.decorators.csrf import csrf_exempt, csrf_protect |
|
32 |
from django.views.decorators.debug import sensitive_post_parameters |
|
| 300 | 33 |
from django.views.generic import TemplateView, View |
| 529 | 34 |
from django.views.generic.edit import UpdateView |
|
563
e25de27cba8c
do not load User model in module definition
ymh <ymh.work@gmail.com>
parents:
561
diff
changeset
|
35 |
from renkanmanager.models import Renkan |
|
e25de27cba8c
do not load User model in module definition
ymh <ymh.work@gmail.com>
parents:
561
diff
changeset
|
36 |
from renkanmanager.utils import LineNodePlacer, HorLineNodePlacer, renkan_copier, renkan_deleter, \ |
|
e25de27cba8c
do not load User model in module definition
ymh <ymh.work@gmail.com>
parents:
561
diff
changeset
|
37 |
CircleNodePlacer |
| 473 | 38 |
|
|
316
5cc83cd7d1d1
renkan from notice/datasheet and correct renkan from facettes.
cavaliet
parents:
315
diff
changeset
|
39 |
from hdabo.models import Tag, Datasheet, TaggedSheet, Folder |
| 473 | 40 |
from hdalab.forms import HdalabRenkanStateForm, HdalabRenkanFavoriteForm |
| 322 | 41 |
from hdalab.models.dataviz import DbpediaFieldsTranslation |
| 300 | 42 |
from hdalab.models.renkan import HdalabRenkan |
| 473 | 43 |
from hdalab.services import change_renkan_state |
|
299
8e00641076e7
remove renkan management to an other django app (see renkan hg repo)
cavaliet
parents:
297
diff
changeset
|
44 |
from hdalab.views.ajax import filter_generic |
| 293 | 45 |
|
|
563
e25de27cba8c
do not load User model in module definition
ymh <ymh.work@gmail.com>
parents:
561
diff
changeset
|
46 |
|
| 293 | 47 |
logger = logging.getLogger(__name__) |
48 |
||
49 |
||
| 332 | 50 |
class BaseRenkanList(TemplateView): |
| 293 | 51 |
|
| 332 | 52 |
def update_context(self, context, renkan_queryset): |
| 331 | 53 |
|
| 343 | 54 |
filters = "" |
55 |
filter_title = self.request.GET.get("title", "") |
|
|
342
a0fa17c48236
title filter on renkan lists (personal, public and admin).
cavaliet
parents:
340
diff
changeset
|
56 |
if(len(filter_title)>0): |
|
a0fa17c48236
title filter on renkan lists (personal, public and admin).
cavaliet
parents:
340
diff
changeset
|
57 |
renkan_queryset = renkan_queryset.filter(renkan__title__icontains=filter_title) |
| 343 | 58 |
filters += "&title=" + filter_title |
59 |
filter_username = self.request.GET.get("username", "") |
|
60 |
if(len(filter_username)>0): |
|
61 |
renkan_queryset = renkan_queryset.filter(renkan__owner__username=filter_username) |
|
62 |
filters += "&username=" + filter_username |
|
63 |
filter_state = self.request.GET.get("state", "") |
|
64 |
if(len(filter_state)>0): |
|
65 |
try: |
|
66 |
filter_state = int(filter_state) |
|
67 |
except: |
|
68 |
pass |
|
69 |
renkan_queryset = renkan_queryset.filter(state=filter_state) |
|
70 |
filter_state = str(filter_state) |
|
71 |
filters += "&state=" + filter_state |
|
72 |
filter_startdate = self.request.GET.get("startdate", "") |
|
73 |
if filter_startdate!="": |
|
74 |
renkan_queryset = renkan_queryset.filter(renkan__modification_date__gt=filter_startdate) |
|
75 |
filters += "&startdate=" + filter_startdate |
|
76 |
filter_enddate = self.request.GET.get("enddate", "") |
|
77 |
if filter_enddate!="": |
|
78 |
renkan_queryset = renkan_queryset.filter(renkan__modification_date__lt=filter_enddate + " 23:59:59") |
|
79 |
filters += "&enddate=" + filter_enddate |
|
| 473 | 80 |
filter_favorite = int(self.request.GET.get('favorite', "2")) |
81 |
if filter_favorite == 1: |
|
82 |
renkan_queryset = renkan_queryset.filter(favorite=True) |
|
83 |
elif filter_favorite == 0: |
|
84 |
renkan_queryset = renkan_queryset.filter(favorite=False) |
|
85 |
||
| 331 | 86 |
sort_param = self.request.GET.get('sort', "date") |
87 |
order_param = self.request.GET.get('order', "desc") |
|
| 473 | 88 |
sort = {"date":"renkan__modification_date", "title":"renkan__title", "state":"state", "user":"renkan__owner__username", "favorite":"favorite"}.get(sort_param, None) |
| 331 | 89 |
if order_param=="desc": |
90 |
order = "-" |
|
91 |
opposite = "asc" |
|
92 |
else: |
|
93 |
order = "" |
|
94 |
opposite = "desc" |
|
| 473 | 95 |
if sort: |
96 |
renkan_queryset = renkan_queryset.order_by(order + sort) |
|
|
342
a0fa17c48236
title filter on renkan lists (personal, public and admin).
cavaliet
parents:
340
diff
changeset
|
97 |
p = Paginator(renkan_queryset, settings.RENKANS_PER_PAGE) |
| 331 | 98 |
page_nb = self.request.GET.get('page') |
99 |
try: |
|
100 |
page = p.page(page_nb) |
|
101 |
except PageNotAnInteger: |
|
102 |
page = p.page(1) |
|
103 |
except EmptyPage: |
|
104 |
page = p.page(p.num_pages) |
|
105 |
||
| 343 | 106 |
context.update({"page": page, "sort_param":sort_param, "order_param":order_param, "opposite":opposite, |
107 |
"filters":filters, "title": filter_title, "username": filter_username, "state": filter_state, |
|
| 473 | 108 |
"startdate":filter_startdate, "enddate":filter_enddate, "favorite": filter_favorite}) |
| 331 | 109 |
|
| 301 | 110 |
return context |
111 |
||
112 |
||
| 300 | 113 |
|
| 332 | 114 |
class ProfileHome(BaseRenkanList): |
115 |
||
116 |
template_name = "profile_home.html" |
|
117 |
||
118 |
def get_context_data(self, **kwargs): |
|
|
342
a0fa17c48236
title filter on renkan lists (personal, public and admin).
cavaliet
parents:
340
diff
changeset
|
119 |
return self.update_context( super(ProfileHome, self).get_context_data(**kwargs), HdalabRenkan.objects.select_related("renkan").filter(renkan__owner=self.request.user)) |
| 332 | 120 |
|
121 |
||
122 |
class RenkanPublicList(BaseRenkanList): |
|
123 |
||
124 |
template_name = "renkan_list.html" |
|
125 |
||
126 |
def get_context_data(self, **kwargs): |
|
| 531 | 127 |
context = super(RenkanPublicList, self).get_context_data(**kwargs) |
128 |
#Liste des renkans publics |
|
|
627
3fd558fa38b1
correct various small bugs. upgrade renkan. news version
ymh <ymh.work@gmail.com>
parents:
608
diff
changeset
|
129 |
renkan_list = HdalabRenkan.objects |
|
3fd558fa38b1
correct various small bugs. upgrade renkan. news version
ymh <ymh.work@gmail.com>
parents:
608
diff
changeset
|
130 |
|
|
608
d1eb7acb5b84
correct small presentation problems
ymh <ymh.work@gmail.com>
parents:
586
diff
changeset
|
131 |
context['hide_favorite'] = True |
|
627
3fd558fa38b1
correct various small bugs. upgrade renkan. news version
ymh <ymh.work@gmail.com>
parents:
608
diff
changeset
|
132 |
context['show_username'] = self.request.user.is_staff |
|
3fd558fa38b1
correct various small bugs. upgrade renkan. news version
ymh <ymh.work@gmail.com>
parents:
608
diff
changeset
|
133 |
if self.request.user.is_staff: |
|
3fd558fa38b1
correct various small bugs. upgrade renkan. news version
ymh <ymh.work@gmail.com>
parents:
608
diff
changeset
|
134 |
renkan_list = renkan_list.select_related("renkan", "renkan__owner") |
|
3fd558fa38b1
correct various small bugs. upgrade renkan. news version
ymh <ymh.work@gmail.com>
parents:
608
diff
changeset
|
135 |
else: |
|
3fd558fa38b1
correct various small bugs. upgrade renkan. news version
ymh <ymh.work@gmail.com>
parents:
608
diff
changeset
|
136 |
renkan_list = renkan_list.select_related("renkan") |
|
3fd558fa38b1
correct various small bugs. upgrade renkan. news version
ymh <ymh.work@gmail.com>
parents:
608
diff
changeset
|
137 |
|
|
3fd558fa38b1
correct various small bugs. upgrade renkan. news version
ymh <ymh.work@gmail.com>
parents:
608
diff
changeset
|
138 |
return self.update_context(context, renkan_list.filter(state=HdalabRenkan.PUBLISHED, favorite=False) ) |
| 332 | 139 |
|
140 |
||
| 473 | 141 |
class RenkanFavoriteList(BaseRenkanList): |
142 |
||
|
586
32d9c3ff86eb
various small corrections + new version
ymh <ymh.work@gmail.com>
parents:
563
diff
changeset
|
143 |
template_name = "renkan_list_favorite.html" |
| 473 | 144 |
|
145 |
def get_context_data(self, **kwargs): |
|
|
586
32d9c3ff86eb
various small corrections + new version
ymh <ymh.work@gmail.com>
parents:
563
diff
changeset
|
146 |
context = super(RenkanFavoriteList, self).get_context_data(**kwargs) |
|
627
3fd558fa38b1
correct various small bugs. upgrade renkan. news version
ymh <ymh.work@gmail.com>
parents:
608
diff
changeset
|
147 |
renkan_list = HdalabRenkan.objects |
|
3fd558fa38b1
correct various small bugs. upgrade renkan. news version
ymh <ymh.work@gmail.com>
parents:
608
diff
changeset
|
148 |
|
| 473 | 149 |
context['hide_favorite'] = True |
|
627
3fd558fa38b1
correct various small bugs. upgrade renkan. news version
ymh <ymh.work@gmail.com>
parents:
608
diff
changeset
|
150 |
context['show_username'] = self.request.user.is_staff |
|
3fd558fa38b1
correct various small bugs. upgrade renkan. news version
ymh <ymh.work@gmail.com>
parents:
608
diff
changeset
|
151 |
if self.request.user.is_staff: |
|
3fd558fa38b1
correct various small bugs. upgrade renkan. news version
ymh <ymh.work@gmail.com>
parents:
608
diff
changeset
|
152 |
renkan_list = renkan_list.select_related("renkan", "renkan__owner") |
|
3fd558fa38b1
correct various small bugs. upgrade renkan. news version
ymh <ymh.work@gmail.com>
parents:
608
diff
changeset
|
153 |
else: |
|
3fd558fa38b1
correct various small bugs. upgrade renkan. news version
ymh <ymh.work@gmail.com>
parents:
608
diff
changeset
|
154 |
renkan_list = renkan_list.select_related("renkan") |
|
3fd558fa38b1
correct various small bugs. upgrade renkan. news version
ymh <ymh.work@gmail.com>
parents:
608
diff
changeset
|
155 |
|
|
3fd558fa38b1
correct various small bugs. upgrade renkan. news version
ymh <ymh.work@gmail.com>
parents:
608
diff
changeset
|
156 |
return self.update_context(context, renkan_list.filter(state=HdalabRenkan.PUBLISHED, favorite=True) ) |
| 473 | 157 |
|
158 |
||
|
627
3fd558fa38b1
correct various small bugs. upgrade renkan. news version
ymh <ymh.work@gmail.com>
parents:
608
diff
changeset
|
159 |
class RenkanNew(TemplateView): |
| 300 | 160 |
|
|
627
3fd558fa38b1
correct various small bugs. upgrade renkan. news version
ymh <ymh.work@gmail.com>
parents:
608
diff
changeset
|
161 |
template_name="renkan_new_confirm.html" |
|
3fd558fa38b1
correct various small bugs. upgrade renkan. news version
ymh <ymh.work@gmail.com>
parents:
608
diff
changeset
|
162 |
|
| 473 | 163 |
def post(self, request): |
| 300 | 164 |
rk = Renkan() |
165 |
rk_id = unicode(uuid.uuid1()) |
|
166 |
rk.rk_id = rk_id |
|
167 |
rk.owner = request.user |
|
168 |
rk.content = '{}' |
|
169 |
rk.title = "Nouveau Renkan " |
|
170 |
rk.save() |
|
171 |
hr = HdalabRenkan() |
|
172 |
hr.renkan = rk |
|
|
329
ea6268cf8c83
renkan state management for staff members : publish, unpublish, reject.
cavaliet
parents:
326
diff
changeset
|
173 |
hr.state = HdalabRenkan.EDITION |
| 300 | 174 |
hr.save() |
175 |
return redirect("%s?rk_id=%s" % (reverse('renkan_edit'), rk_id)) |
|
|
299
8e00641076e7
remove renkan management to an other django app (see renkan hg repo)
cavaliet
parents:
297
diff
changeset
|
176 |
|
|
8e00641076e7
remove renkan management to an other django app (see renkan hg repo)
cavaliet
parents:
297
diff
changeset
|
177 |
|
|
8e00641076e7
remove renkan management to an other django app (see renkan hg repo)
cavaliet
parents:
297
diff
changeset
|
178 |
class RenkanEdit(TemplateView): |
|
8e00641076e7
remove renkan management to an other django app (see renkan hg repo)
cavaliet
parents:
297
diff
changeset
|
179 |
|
|
8e00641076e7
remove renkan management to an other django app (see renkan hg repo)
cavaliet
parents:
297
diff
changeset
|
180 |
template_name="renkan_edit.html" |
|
8e00641076e7
remove renkan management to an other django app (see renkan hg repo)
cavaliet
parents:
297
diff
changeset
|
181 |
|
|
8e00641076e7
remove renkan management to an other django app (see renkan hg repo)
cavaliet
parents:
297
diff
changeset
|
182 |
def get_context_data(self, **kwargs): |
| 420 | 183 |
switch_shape_url= {} |
|
299
8e00641076e7
remove renkan management to an other django app (see renkan hg repo)
cavaliet
parents:
297
diff
changeset
|
184 |
context = super(RenkanEdit, self).get_context_data(**kwargs) |
|
8e00641076e7
remove renkan management to an other django app (see renkan hg repo)
cavaliet
parents:
297
diff
changeset
|
185 |
# If a renkan id is set |
|
8e00641076e7
remove renkan management to an other django app (see renkan hg repo)
cavaliet
parents:
297
diff
changeset
|
186 |
rk_id = self.request.GET.get("rk_id", "") |
|
8e00641076e7
remove renkan management to an other django app (see renkan hg repo)
cavaliet
parents:
297
diff
changeset
|
187 |
if rk_id!="": |
| 330 | 188 |
hr = get_object_or_404(HdalabRenkan.objects.select_related("renkan", "renkan__owner"), renkan__rk_id=rk_id) #.get(=rk_id) |
189 |
if hr.renkan.owner!=self.request.user or hr.state!=HdalabRenkan.EDITION: |
|
|
299
8e00641076e7
remove renkan management to an other django app (see renkan hg repo)
cavaliet
parents:
297
diff
changeset
|
190 |
raise Exception("You are not allowed to edit this renkan") |
|
490
97afeb38e259
hide the switch-shape dropdown when its a saved renkan (id_rk is set)
rougeronj
parents:
473
diff
changeset
|
191 |
else: |
|
97afeb38e259
hide the switch-shape dropdown when its a saved renkan (id_rk is set)
rougeronj
parents:
473
diff
changeset
|
192 |
current_url = self.request.get_full_path() |
|
97afeb38e259
hide the switch-shape dropdown when its a saved renkan (id_rk is set)
rougeronj
parents:
473
diff
changeset
|
193 |
switch_shape_url["current"] = current_url |
|
97afeb38e259
hide the switch-shape dropdown when its a saved renkan (id_rk is set)
rougeronj
parents:
473
diff
changeset
|
194 |
if "shape=horiz" in current_url: |
|
97afeb38e259
hide the switch-shape dropdown when its a saved renkan (id_rk is set)
rougeronj
parents:
473
diff
changeset
|
195 |
switch_shape_url["vert"] = current_url.replace("&shape=horiz", "&shape=vert") |
|
97afeb38e259
hide the switch-shape dropdown when its a saved renkan (id_rk is set)
rougeronj
parents:
473
diff
changeset
|
196 |
switch_shape_url["circle"] = current_url.replace("&shape=horiz", "") |
|
97afeb38e259
hide the switch-shape dropdown when its a saved renkan (id_rk is set)
rougeronj
parents:
473
diff
changeset
|
197 |
elif "shape=vert" in current_url: |
|
97afeb38e259
hide the switch-shape dropdown when its a saved renkan (id_rk is set)
rougeronj
parents:
473
diff
changeset
|
198 |
switch_shape_url["horiz"] = current_url.replace("&shape=vert", "&shape=horiz") |
|
97afeb38e259
hide the switch-shape dropdown when its a saved renkan (id_rk is set)
rougeronj
parents:
473
diff
changeset
|
199 |
switch_shape_url["circle"] = current_url.replace("&shape=vert", "") |
|
97afeb38e259
hide the switch-shape dropdown when its a saved renkan (id_rk is set)
rougeronj
parents:
473
diff
changeset
|
200 |
else: |
|
97afeb38e259
hide the switch-shape dropdown when its a saved renkan (id_rk is set)
rougeronj
parents:
473
diff
changeset
|
201 |
#if we generated the renkan from no filter, the url doesn't have any "?" |
|
97afeb38e259
hide the switch-shape dropdown when its a saved renkan (id_rk is set)
rougeronj
parents:
473
diff
changeset
|
202 |
#we add one to create the links to the other representation |
|
97afeb38e259
hide the switch-shape dropdown when its a saved renkan (id_rk is set)
rougeronj
parents:
473
diff
changeset
|
203 |
if "?" not in current_url: |
|
97afeb38e259
hide the switch-shape dropdown when its a saved renkan (id_rk is set)
rougeronj
parents:
473
diff
changeset
|
204 |
current_url += "?" |
|
97afeb38e259
hide the switch-shape dropdown when its a saved renkan (id_rk is set)
rougeronj
parents:
473
diff
changeset
|
205 |
switch_shape_url["horiz"] = current_url + "&shape=horiz" |
|
97afeb38e259
hide the switch-shape dropdown when its a saved renkan (id_rk is set)
rougeronj
parents:
473
diff
changeset
|
206 |
switch_shape_url["vert"] = current_url + "&shape=vert" |
|
97afeb38e259
hide the switch-shape dropdown when its a saved renkan (id_rk is set)
rougeronj
parents:
473
diff
changeset
|
207 |
context["switch_shape_url"] = switch_shape_url |
| 308 | 208 |
form = AuthenticationForm(self.request) |
209 |
context["form"] = form |
|
210 |
||
| 294 | 211 |
return context |
| 296 | 212 |
|
|
299
8e00641076e7
remove renkan management to an other django app (see renkan hg repo)
cavaliet
parents:
297
diff
changeset
|
213 |
|
|
8e00641076e7
remove renkan management to an other django app (see renkan hg repo)
cavaliet
parents:
297
diff
changeset
|
214 |
|
|
8e00641076e7
remove renkan management to an other django app (see renkan hg repo)
cavaliet
parents:
297
diff
changeset
|
215 |
class HdalabRenkanGetPut(RenkanGetPut): |
|
8e00641076e7
remove renkan management to an other django app (see renkan hg repo)
cavaliet
parents:
297
diff
changeset
|
216 |
|
|
8e00641076e7
remove renkan management to an other django app (see renkan hg repo)
cavaliet
parents:
297
diff
changeset
|
217 |
@csrf_exempt |
|
8e00641076e7
remove renkan management to an other django app (see renkan hg repo)
cavaliet
parents:
297
diff
changeset
|
218 |
def dispatch(self, *args, **kwargs): |
|
8e00641076e7
remove renkan management to an other django app (see renkan hg repo)
cavaliet
parents:
297
diff
changeset
|
219 |
return super(HdalabRenkanGetPut, self).dispatch(*args, **kwargs) |
|
8e00641076e7
remove renkan management to an other django app (see renkan hg repo)
cavaliet
parents:
297
diff
changeset
|
220 |
|
|
8e00641076e7
remove renkan management to an other django app (see renkan hg repo)
cavaliet
parents:
297
diff
changeset
|
221 |
def get(self, request): |
| 293 | 222 |
|
|
299
8e00641076e7
remove renkan management to an other django app (see renkan hg repo)
cavaliet
parents:
297
diff
changeset
|
223 |
# If a renkan id is set |
|
8e00641076e7
remove renkan management to an other django app (see renkan hg repo)
cavaliet
parents:
297
diff
changeset
|
224 |
rk_id = request.GET.get("rk_id", "") |
|
8e00641076e7
remove renkan management to an other django app (see renkan hg repo)
cavaliet
parents:
297
diff
changeset
|
225 |
if rk_id!="": |
|
8e00641076e7
remove renkan management to an other django app (see renkan hg repo)
cavaliet
parents:
297
diff
changeset
|
226 |
rk = get_object_or_404(Renkan, rk_id=rk_id) |
|
8e00641076e7
remove renkan management to an other django app (see renkan hg repo)
cavaliet
parents:
297
diff
changeset
|
227 |
return HttpResponse(rk.content, content_type="application/json") |
|
8e00641076e7
remove renkan management to an other django app (see renkan hg repo)
cavaliet
parents:
297
diff
changeset
|
228 |
|
| 319 | 229 |
shape = request.GET.get("shape", "") |
| 320 | 230 |
no_translate_langs = [ 'fr' ] |
231 |
lang = request.GET.get('lang',request.LANGUAGE_CODE) |
|
| 319 | 232 |
|
| 314 | 233 |
# Start dict for renkan json |
|
299
8e00641076e7
remove renkan management to an other django app (see renkan hg repo)
cavaliet
parents:
297
diff
changeset
|
234 |
now = datetime.now().strftime("%Y-%m-%d %H:%M") |
|
8e00641076e7
remove renkan management to an other django app (see renkan hg repo)
cavaliet
parents:
297
diff
changeset
|
235 |
|
|
8e00641076e7
remove renkan management to an other django app (see renkan hg repo)
cavaliet
parents:
297
diff
changeset
|
236 |
content = { |
|
8e00641076e7
remove renkan management to an other django app (see renkan hg repo)
cavaliet
parents:
297
diff
changeset
|
237 |
"id": unicode(uuid.uuid1()), |
|
627
3fd558fa38b1
correct various small bugs. upgrade renkan. news version
ymh <ymh.work@gmail.com>
parents:
608
diff
changeset
|
238 |
"schema_version": 2, |
|
302
106c33871db4
better presentation and automatic save for renkan from facettes
cavaliet
parents:
301
diff
changeset
|
239 |
"title": "", |
|
299
8e00641076e7
remove renkan management to an other django app (see renkan hg repo)
cavaliet
parents:
297
diff
changeset
|
240 |
"description": "(empty description)", |
|
8e00641076e7
remove renkan management to an other django app (see renkan hg repo)
cavaliet
parents:
297
diff
changeset
|
241 |
"created": now, |
|
8e00641076e7
remove renkan management to an other django app (see renkan hg repo)
cavaliet
parents:
297
diff
changeset
|
242 |
"updated": now, |
|
8e00641076e7
remove renkan management to an other django app (see renkan hg repo)
cavaliet
parents:
297
diff
changeset
|
243 |
"nodes": [], |
|
8e00641076e7
remove renkan management to an other django app (see renkan hg repo)
cavaliet
parents:
297
diff
changeset
|
244 |
"edges": [], |
|
8e00641076e7
remove renkan management to an other django app (see renkan hg repo)
cavaliet
parents:
297
diff
changeset
|
245 |
"views": [], |
|
8e00641076e7
remove renkan management to an other django app (see renkan hg repo)
cavaliet
parents:
297
diff
changeset
|
246 |
"users": [], |
|
8e00641076e7
remove renkan management to an other django app (see renkan hg repo)
cavaliet
parents:
297
diff
changeset
|
247 |
} |
|
8e00641076e7
remove renkan management to an other django app (see renkan hg repo)
cavaliet
parents:
297
diff
changeset
|
248 |
|
| 314 | 249 |
# category image dict |
250 |
cat_dict = {u"Créateur": static("hdalab/img/category_creator.png"), |
|
251 |
u"Datation": static("hdalab/img/category_datation.png"), |
|
252 |
u"Discipline artistique": static("hdalab/img/category_discipline.png"), |
|
253 |
u"Localisation": static("hdalab/img/category_localisation.png"), |
|
254 |
u"Ecole/Mouvement": static("hdalab/img/category_movement.png")} |
|
255 |
||
| 333 | 256 |
# category image dict |
257 |
shapes = { "tag1": "polygon", "notice": "rectangle", "tag2": "star" } |
|
258 |
||
| 314 | 259 |
|
260 |
# Renkan Project ID |
|
261 |
project_id = unicode(uuid.uuid1()) |
|
262 |
||
263 |
||
264 |
# If a notice id is set |
|
265 |
notice_id = request.GET.get("notice", "") |
|
266 |
if notice_id!="": |
|
267 |
notice = get_object_or_404(Datasheet, hda_id=notice_id) |
|
| 320 | 268 |
# We get the ORDERED tags if we display one sheet |
| 314 | 269 |
ordered_tags = TaggedSheet.objects.filter(datasheet=notice).select_related("tag", "tag__dbpedia_fields", "tag__category").order_by('order')[:15] |
270 |
# Prepare Node placer : |
|
| 420 | 271 |
np = CircleNodePlacer() |
272 |
if shape=="horiz": |
|
273 |
np = HorLineNodePlacer() |
|
274 |
elif shape=="vert": |
|
275 |
np = LineNodePlacer() |
|
276 |
||
| 314 | 277 |
np.init({"datasheet": (1, 1), "tags": (2, len(ordered_tags))}) |
278 |
# Place notice : |
|
279 |
content["nodes"].append({ |
|
280 |
"id": unicode(uuid.uuid1()), |
|
281 |
"title": notice.title, |
|
282 |
"description": notice.description, |
|
283 |
"uri": notice.url, |
|
284 |
"position": np.get_place("datasheet"), |
|
| 326 | 285 |
"image": "http://www.histoiredesarts.culture.fr/images/pf/" + notice.hda_id + ".jpg", |
| 314 | 286 |
"size": 0, |
287 |
"project_id": project_id, |
|
|
627
3fd558fa38b1
correct various small bugs. upgrade renkan. news version
ymh <ymh.work@gmail.com>
parents:
608
diff
changeset
|
288 |
"style" : { |
|
3fd558fa38b1
correct various small bugs. upgrade renkan. news version
ymh <ymh.work@gmail.com>
parents:
608
diff
changeset
|
289 |
"color": "#FF0033", |
|
3fd558fa38b1
correct various small bugs. upgrade renkan. news version
ymh <ymh.work@gmail.com>
parents:
608
diff
changeset
|
290 |
}, |
| 333 | 291 |
"shape": shapes["notice"] |
| 314 | 292 |
}) |
|
436
deb24a52827f
Close #26 - show link between a notice and a ressource
rougeronj
parents:
434
diff
changeset
|
293 |
notice_id = content["nodes"][0]["id"] |
| 314 | 294 |
|
| 320 | 295 |
# Get translated labels |
296 |
translations = {} |
|
297 |
if lang not in no_translate_langs: |
|
| 321 | 298 |
transqs = DbpediaFieldsTranslation.objects.filter(master__in = [ot.tag.dbpedia_fields if hasattr(ot.tag, 'dbpedia_fields') and ot.tag.dbpedia_fields else None for ot in ordered_tags], language_code = lang) |
|
445
a74ec9e02042
correct #35 + add tag abstract + improve translations
ymh <ymh.work@gmail.com>
parents:
438
diff
changeset
|
299 |
translations = dict([(trans.master_id,trans) for trans in transqs]) |
| 320 | 300 |
|
| 314 | 301 |
for ot in ordered_tags: |
302 |
t = ot.tag |
|
303 |
img_url = t.dbpedia_fields.thumbnail if hasattr(t, 'dbpedia_fields') and t.dbpedia_fields and t.dbpedia_fields.thumbnail else None |
|
304 |
if img_url is None and t.category is not None: |
|
305 |
img_url = cat_dict[t.category.label] |
|
|
445
a74ec9e02042
correct #35 + add tag abstract + improve translations
ymh <ymh.work@gmail.com>
parents:
438
diff
changeset
|
306 |
translation_obj = translations.get(t.dbpedia_fields.id, None) if t.dbpedia_fields else None |
|
a74ec9e02042
correct #35 + add tag abstract + improve translations
ymh <ymh.work@gmail.com>
parents:
438
diff
changeset
|
307 |
translation = { |
|
a74ec9e02042
correct #35 + add tag abstract + improve translations
ymh <ymh.work@gmail.com>
parents:
438
diff
changeset
|
308 |
'label': translation_obj.label if translation_obj and translation_obj.label else t.label, |
|
a74ec9e02042
correct #35 + add tag abstract + improve translations
ymh <ymh.work@gmail.com>
parents:
438
diff
changeset
|
309 |
'abstract': translation_obj.abstract if translation_obj and translation_obj.abstract else '', |
|
a74ec9e02042
correct #35 + add tag abstract + improve translations
ymh <ymh.work@gmail.com>
parents:
438
diff
changeset
|
310 |
} |
| 314 | 311 |
content["nodes"].append({ |
312 |
"id": unicode(uuid.uuid1()), |
|
|
445
a74ec9e02042
correct #35 + add tag abstract + improve translations
ymh <ymh.work@gmail.com>
parents:
438
diff
changeset
|
313 |
"title": translation['label'], |
|
a74ec9e02042
correct #35 + add tag abstract + improve translations
ymh <ymh.work@gmail.com>
parents:
438
diff
changeset
|
314 |
"description": translation['abstract'], |
|
a74ec9e02042
correct #35 + add tag abstract + improve translations
ymh <ymh.work@gmail.com>
parents:
438
diff
changeset
|
315 |
"uri": t.wikipedia_url, |
| 314 | 316 |
"position": np.get_place("tags"), |
317 |
"image": img_url, |
|
318 |
"size": 0, |
|
319 |
"project_id": project_id, |
|
|
627
3fd558fa38b1
correct various small bugs. upgrade renkan. news version
ymh <ymh.work@gmail.com>
parents:
608
diff
changeset
|
320 |
"style": { |
|
3fd558fa38b1
correct various small bugs. upgrade renkan. news version
ymh <ymh.work@gmail.com>
parents:
608
diff
changeset
|
321 |
"color": "#00FF33" |
|
3fd558fa38b1
correct various small bugs. upgrade renkan. news version
ymh <ymh.work@gmail.com>
parents:
608
diff
changeset
|
322 |
}, |
| 333 | 323 |
"shape": shapes["tag2"] |
| 314 | 324 |
}) |
|
436
deb24a52827f
Close #26 - show link between a notice and a ressource
rougeronj
parents:
434
diff
changeset
|
325 |
|
|
deb24a52827f
Close #26 - show link between a notice and a ressource
rougeronj
parents:
434
diff
changeset
|
326 |
# Place edges |
|
deb24a52827f
Close #26 - show link between a notice and a ressource
rougeronj
parents:
434
diff
changeset
|
327 |
for node in content["nodes"]: |
|
deb24a52827f
Close #26 - show link between a notice and a ressource
rougeronj
parents:
434
diff
changeset
|
328 |
content["edges"].append({ |
|
deb24a52827f
Close #26 - show link between a notice and a ressource
rougeronj
parents:
434
diff
changeset
|
329 |
"id": unicode(uuid.uuid1()), |
|
deb24a52827f
Close #26 - show link between a notice and a ressource
rougeronj
parents:
434
diff
changeset
|
330 |
"title": "", |
|
deb24a52827f
Close #26 - show link between a notice and a ressource
rougeronj
parents:
434
diff
changeset
|
331 |
"description": "", |
|
deb24a52827f
Close #26 - show link between a notice and a ressource
rougeronj
parents:
434
diff
changeset
|
332 |
"uri": "", |
|
627
3fd558fa38b1
correct various small bugs. upgrade renkan. news version
ymh <ymh.work@gmail.com>
parents:
608
diff
changeset
|
333 |
"style": { |
|
3fd558fa38b1
correct various small bugs. upgrade renkan. news version
ymh <ymh.work@gmail.com>
parents:
608
diff
changeset
|
334 |
"color": None, |
|
3fd558fa38b1
correct various small bugs. upgrade renkan. news version
ymh <ymh.work@gmail.com>
parents:
608
diff
changeset
|
335 |
}, |
|
436
deb24a52827f
Close #26 - show link between a notice and a ressource
rougeronj
parents:
434
diff
changeset
|
336 |
"from": notice_id, |
|
deb24a52827f
Close #26 - show link between a notice and a ressource
rougeronj
parents:
434
diff
changeset
|
337 |
"to": node["id"], |
|
deb24a52827f
Close #26 - show link between a notice and a ressource
rougeronj
parents:
434
diff
changeset
|
338 |
"project_id": project_id, |
|
deb24a52827f
Close #26 - show link between a notice and a ressource
rougeronj
parents:
434
diff
changeset
|
339 |
}) |
| 314 | 340 |
|
341 |
response = json.dumps(content) |
|
342 |
return HttpResponse(response, content_type="application/json") |
|
343 |
||
|
316
5cc83cd7d1d1
renkan from notice/datasheet and correct renkan from facettes.
cavaliet
parents:
315
diff
changeset
|
344 |
|
|
5cc83cd7d1d1
renkan from notice/datasheet and correct renkan from facettes.
cavaliet
parents:
315
diff
changeset
|
345 |
# If a folder id is set |
|
5cc83cd7d1d1
renkan from notice/datasheet and correct renkan from facettes.
cavaliet
parents:
315
diff
changeset
|
346 |
folder_id = request.GET.get("folder", "") |
|
5cc83cd7d1d1
renkan from notice/datasheet and correct renkan from facettes.
cavaliet
parents:
315
diff
changeset
|
347 |
if folder_id!="": |
|
5cc83cd7d1d1
renkan from notice/datasheet and correct renkan from facettes.
cavaliet
parents:
315
diff
changeset
|
348 |
#TODO : optimize to avoid tag request on each notice |
|
627
3fd558fa38b1
correct various small bugs. upgrade renkan. news version
ymh <ymh.work@gmail.com>
parents:
608
diff
changeset
|
349 |
folder = get_object_or_404(Folder.objects.prefetch_related("datasheets", "datasheets__tags"), pk=folder_id) |
|
316
5cc83cd7d1d1
renkan from notice/datasheet and correct renkan from facettes.
cavaliet
parents:
315
diff
changeset
|
350 |
notices = folder.datasheets.all() |
|
5cc83cd7d1d1
renkan from notice/datasheet and correct renkan from facettes.
cavaliet
parents:
315
diff
changeset
|
351 |
n_tags = [] |
|
5cc83cd7d1d1
renkan from notice/datasheet and correct renkan from facettes.
cavaliet
parents:
315
diff
changeset
|
352 |
notice_tag_dict = {} |
|
5cc83cd7d1d1
renkan from notice/datasheet and correct renkan from facettes.
cavaliet
parents:
315
diff
changeset
|
353 |
tag_uuid_dict = {} |
|
5cc83cd7d1d1
renkan from notice/datasheet and correct renkan from facettes.
cavaliet
parents:
315
diff
changeset
|
354 |
for n in notices: |
|
5cc83cd7d1d1
renkan from notice/datasheet and correct renkan from facettes.
cavaliet
parents:
315
diff
changeset
|
355 |
notice_tag_dict[n.pk] = {"uuid":unicode(uuid.uuid1()), "tags":[] } |
|
5cc83cd7d1d1
renkan from notice/datasheet and correct renkan from facettes.
cavaliet
parents:
315
diff
changeset
|
356 |
for t in n.tags.all()[:5]: |
|
5cc83cd7d1d1
renkan from notice/datasheet and correct renkan from facettes.
cavaliet
parents:
315
diff
changeset
|
357 |
if t.pk not in tag_uuid_dict: |
|
5cc83cd7d1d1
renkan from notice/datasheet and correct renkan from facettes.
cavaliet
parents:
315
diff
changeset
|
358 |
tag_uuid_dict[t.pk] = unicode(uuid.uuid1()) |
|
5cc83cd7d1d1
renkan from notice/datasheet and correct renkan from facettes.
cavaliet
parents:
315
diff
changeset
|
359 |
notice_tag_dict[n.pk]["tags"].append(tag_uuid_dict[t.pk]) |
|
5cc83cd7d1d1
renkan from notice/datasheet and correct renkan from facettes.
cavaliet
parents:
315
diff
changeset
|
360 |
n_tags.append(t) |
|
5cc83cd7d1d1
renkan from notice/datasheet and correct renkan from facettes.
cavaliet
parents:
315
diff
changeset
|
361 |
n_tags = [t.pk for t in n_tags] |
|
5cc83cd7d1d1
renkan from notice/datasheet and correct renkan from facettes.
cavaliet
parents:
315
diff
changeset
|
362 |
all_tags = Tag.objects.filter( pk__in=n_tags ).select_related("dbpedia_fields", "category") |
|
5cc83cd7d1d1
renkan from notice/datasheet and correct renkan from facettes.
cavaliet
parents:
315
diff
changeset
|
363 |
|
| 320 | 364 |
# Get translated labels |
365 |
translations = {} |
|
366 |
if lang not in no_translate_langs: |
|
367 |
transqs = DbpediaFieldsTranslation.objects.filter(master__in = [t.dbpedia_fields if hasattr(t, 'dbpedia_fields') and t.dbpedia_fields else None for t in all_tags], language_code = lang) |
|
|
445
a74ec9e02042
correct #35 + add tag abstract + improve translations
ymh <ymh.work@gmail.com>
parents:
438
diff
changeset
|
368 |
translations = dict([(trans.master_id,trans) for trans in transqs]) |
| 320 | 369 |
|
|
316
5cc83cd7d1d1
renkan from notice/datasheet and correct renkan from facettes.
cavaliet
parents:
315
diff
changeset
|
370 |
# Prepare Node placer : |
|
431
adb0be6dfdcf
Close #37 - circle representation by default in every kind of generated renkan (filter, notice, folder)
rougeronj
parents:
420
diff
changeset
|
371 |
np = CircleNodePlacer() |
|
adb0be6dfdcf
Close #37 - circle representation by default in every kind of generated renkan (filter, notice, folder)
rougeronj
parents:
420
diff
changeset
|
372 |
if shape=="horiz": |
|
adb0be6dfdcf
Close #37 - circle representation by default in every kind of generated renkan (filter, notice, folder)
rougeronj
parents:
420
diff
changeset
|
373 |
np = HorLineNodePlacer() |
|
adb0be6dfdcf
Close #37 - circle representation by default in every kind of generated renkan (filter, notice, folder)
rougeronj
parents:
420
diff
changeset
|
374 |
elif shape=="vert": |
|
adb0be6dfdcf
Close #37 - circle representation by default in every kind of generated renkan (filter, notice, folder)
rougeronj
parents:
420
diff
changeset
|
375 |
np = LineNodePlacer() |
|
adb0be6dfdcf
Close #37 - circle representation by default in every kind of generated renkan (filter, notice, folder)
rougeronj
parents:
420
diff
changeset
|
376 |
|
|
316
5cc83cd7d1d1
renkan from notice/datasheet and correct renkan from facettes.
cavaliet
parents:
315
diff
changeset
|
377 |
np.init({"datasheet": (1, len(notices)), "tags": (2, len(all_tags))}) |
|
445
a74ec9e02042
correct #35 + add tag abstract + improve translations
ymh <ymh.work@gmail.com>
parents:
438
diff
changeset
|
378 |
|
|
316
5cc83cd7d1d1
renkan from notice/datasheet and correct renkan from facettes.
cavaliet
parents:
315
diff
changeset
|
379 |
|
|
5cc83cd7d1d1
renkan from notice/datasheet and correct renkan from facettes.
cavaliet
parents:
315
diff
changeset
|
380 |
# Place notices |
|
5cc83cd7d1d1
renkan from notice/datasheet and correct renkan from facettes.
cavaliet
parents:
315
diff
changeset
|
381 |
for n in notices: |
|
5cc83cd7d1d1
renkan from notice/datasheet and correct renkan from facettes.
cavaliet
parents:
315
diff
changeset
|
382 |
content["nodes"].append({ |
|
5cc83cd7d1d1
renkan from notice/datasheet and correct renkan from facettes.
cavaliet
parents:
315
diff
changeset
|
383 |
"id": notice_tag_dict[n.pk]["uuid"], |
|
5cc83cd7d1d1
renkan from notice/datasheet and correct renkan from facettes.
cavaliet
parents:
315
diff
changeset
|
384 |
"title": n.title, |
|
5cc83cd7d1d1
renkan from notice/datasheet and correct renkan from facettes.
cavaliet
parents:
315
diff
changeset
|
385 |
"description": n.description, |
|
5cc83cd7d1d1
renkan from notice/datasheet and correct renkan from facettes.
cavaliet
parents:
315
diff
changeset
|
386 |
"uri": n.url, |
|
5cc83cd7d1d1
renkan from notice/datasheet and correct renkan from facettes.
cavaliet
parents:
315
diff
changeset
|
387 |
"position": np.get_place("datasheet"), |
| 326 | 388 |
"image": "http://www.histoiredesarts.culture.fr/images/pf/" + n.hda_id + ".jpg", |
|
316
5cc83cd7d1d1
renkan from notice/datasheet and correct renkan from facettes.
cavaliet
parents:
315
diff
changeset
|
389 |
"size": 0, |
|
5cc83cd7d1d1
renkan from notice/datasheet and correct renkan from facettes.
cavaliet
parents:
315
diff
changeset
|
390 |
"project_id": project_id, |
|
627
3fd558fa38b1
correct various small bugs. upgrade renkan. news version
ymh <ymh.work@gmail.com>
parents:
608
diff
changeset
|
391 |
"style": { |
|
3fd558fa38b1
correct various small bugs. upgrade renkan. news version
ymh <ymh.work@gmail.com>
parents:
608
diff
changeset
|
392 |
"color": "#FF0033" |
|
3fd558fa38b1
correct various small bugs. upgrade renkan. news version
ymh <ymh.work@gmail.com>
parents:
608
diff
changeset
|
393 |
}, |
| 333 | 394 |
"shape": shapes["notice"] |
|
316
5cc83cd7d1d1
renkan from notice/datasheet and correct renkan from facettes.
cavaliet
parents:
315
diff
changeset
|
395 |
}) |
|
5cc83cd7d1d1
renkan from notice/datasheet and correct renkan from facettes.
cavaliet
parents:
315
diff
changeset
|
396 |
|
|
5cc83cd7d1d1
renkan from notice/datasheet and correct renkan from facettes.
cavaliet
parents:
315
diff
changeset
|
397 |
# Place tags |
|
5cc83cd7d1d1
renkan from notice/datasheet and correct renkan from facettes.
cavaliet
parents:
315
diff
changeset
|
398 |
for t in all_tags: |
|
5cc83cd7d1d1
renkan from notice/datasheet and correct renkan from facettes.
cavaliet
parents:
315
diff
changeset
|
399 |
img_url = t.dbpedia_fields.thumbnail if hasattr(t, 'dbpedia_fields') and t.dbpedia_fields and t.dbpedia_fields.thumbnail else None |
|
445
a74ec9e02042
correct #35 + add tag abstract + improve translations
ymh <ymh.work@gmail.com>
parents:
438
diff
changeset
|
400 |
translation_obj = translations.get(t.dbpedia_fields.id, None) if t.dbpedia_fields else None |
|
a74ec9e02042
correct #35 + add tag abstract + improve translations
ymh <ymh.work@gmail.com>
parents:
438
diff
changeset
|
401 |
translation = { |
|
a74ec9e02042
correct #35 + add tag abstract + improve translations
ymh <ymh.work@gmail.com>
parents:
438
diff
changeset
|
402 |
'label': translation_obj.label if translation_obj and translation_obj.label else t.label, |
|
a74ec9e02042
correct #35 + add tag abstract + improve translations
ymh <ymh.work@gmail.com>
parents:
438
diff
changeset
|
403 |
'abstract': translation_obj.abstract if translation_obj and translation_obj.abstract else '', |
|
a74ec9e02042
correct #35 + add tag abstract + improve translations
ymh <ymh.work@gmail.com>
parents:
438
diff
changeset
|
404 |
} |
|
a74ec9e02042
correct #35 + add tag abstract + improve translations
ymh <ymh.work@gmail.com>
parents:
438
diff
changeset
|
405 |
|
|
316
5cc83cd7d1d1
renkan from notice/datasheet and correct renkan from facettes.
cavaliet
parents:
315
diff
changeset
|
406 |
if img_url is None and t.category is not None: |
|
5cc83cd7d1d1
renkan from notice/datasheet and correct renkan from facettes.
cavaliet
parents:
315
diff
changeset
|
407 |
img_url = cat_dict[t.category.label] |
|
5cc83cd7d1d1
renkan from notice/datasheet and correct renkan from facettes.
cavaliet
parents:
315
diff
changeset
|
408 |
content["nodes"].append({ |
|
5cc83cd7d1d1
renkan from notice/datasheet and correct renkan from facettes.
cavaliet
parents:
315
diff
changeset
|
409 |
"id": tag_uuid_dict[t.pk], |
|
445
a74ec9e02042
correct #35 + add tag abstract + improve translations
ymh <ymh.work@gmail.com>
parents:
438
diff
changeset
|
410 |
"title": translation['label'], |
|
a74ec9e02042
correct #35 + add tag abstract + improve translations
ymh <ymh.work@gmail.com>
parents:
438
diff
changeset
|
411 |
"description": translation['abstract'], |
|
a74ec9e02042
correct #35 + add tag abstract + improve translations
ymh <ymh.work@gmail.com>
parents:
438
diff
changeset
|
412 |
"uri": t.wikipedia_url, |
|
316
5cc83cd7d1d1
renkan from notice/datasheet and correct renkan from facettes.
cavaliet
parents:
315
diff
changeset
|
413 |
"position": np.get_place("tags"), |
|
5cc83cd7d1d1
renkan from notice/datasheet and correct renkan from facettes.
cavaliet
parents:
315
diff
changeset
|
414 |
"image": img_url, |
|
5cc83cd7d1d1
renkan from notice/datasheet and correct renkan from facettes.
cavaliet
parents:
315
diff
changeset
|
415 |
"size": 0, |
|
5cc83cd7d1d1
renkan from notice/datasheet and correct renkan from facettes.
cavaliet
parents:
315
diff
changeset
|
416 |
"project_id": project_id, |
|
627
3fd558fa38b1
correct various small bugs. upgrade renkan. news version
ymh <ymh.work@gmail.com>
parents:
608
diff
changeset
|
417 |
"style": { |
|
3fd558fa38b1
correct various small bugs. upgrade renkan. news version
ymh <ymh.work@gmail.com>
parents:
608
diff
changeset
|
418 |
"color": "#00FF33" |
|
3fd558fa38b1
correct various small bugs. upgrade renkan. news version
ymh <ymh.work@gmail.com>
parents:
608
diff
changeset
|
419 |
}, |
|
3fd558fa38b1
correct various small bugs. upgrade renkan. news version
ymh <ymh.work@gmail.com>
parents:
608
diff
changeset
|
420 |
"shape": shapes["tag2"] |
|
316
5cc83cd7d1d1
renkan from notice/datasheet and correct renkan from facettes.
cavaliet
parents:
315
diff
changeset
|
421 |
}) |
|
5cc83cd7d1d1
renkan from notice/datasheet and correct renkan from facettes.
cavaliet
parents:
315
diff
changeset
|
422 |
|
|
5cc83cd7d1d1
renkan from notice/datasheet and correct renkan from facettes.
cavaliet
parents:
315
diff
changeset
|
423 |
# Place edges |
|
5cc83cd7d1d1
renkan from notice/datasheet and correct renkan from facettes.
cavaliet
parents:
315
diff
changeset
|
424 |
for n_pk in notice_tag_dict: |
|
5cc83cd7d1d1
renkan from notice/datasheet and correct renkan from facettes.
cavaliet
parents:
315
diff
changeset
|
425 |
for tag_id in notice_tag_dict[n_pk]["tags"]: |
|
5cc83cd7d1d1
renkan from notice/datasheet and correct renkan from facettes.
cavaliet
parents:
315
diff
changeset
|
426 |
content["edges"].append({ |
|
5cc83cd7d1d1
renkan from notice/datasheet and correct renkan from facettes.
cavaliet
parents:
315
diff
changeset
|
427 |
"id": unicode(uuid.uuid1()), |
|
5cc83cd7d1d1
renkan from notice/datasheet and correct renkan from facettes.
cavaliet
parents:
315
diff
changeset
|
428 |
"title": "", |
|
5cc83cd7d1d1
renkan from notice/datasheet and correct renkan from facettes.
cavaliet
parents:
315
diff
changeset
|
429 |
"description": "", |
|
5cc83cd7d1d1
renkan from notice/datasheet and correct renkan from facettes.
cavaliet
parents:
315
diff
changeset
|
430 |
"uri": "", |
|
627
3fd558fa38b1
correct various small bugs. upgrade renkan. news version
ymh <ymh.work@gmail.com>
parents:
608
diff
changeset
|
431 |
"style": { |
|
3fd558fa38b1
correct various small bugs. upgrade renkan. news version
ymh <ymh.work@gmail.com>
parents:
608
diff
changeset
|
432 |
"color": None |
|
3fd558fa38b1
correct various small bugs. upgrade renkan. news version
ymh <ymh.work@gmail.com>
parents:
608
diff
changeset
|
433 |
}, |
|
316
5cc83cd7d1d1
renkan from notice/datasheet and correct renkan from facettes.
cavaliet
parents:
315
diff
changeset
|
434 |
"from": notice_tag_dict[n_pk]["uuid"], |
|
5cc83cd7d1d1
renkan from notice/datasheet and correct renkan from facettes.
cavaliet
parents:
315
diff
changeset
|
435 |
"to": tag_id, |
|
5cc83cd7d1d1
renkan from notice/datasheet and correct renkan from facettes.
cavaliet
parents:
315
diff
changeset
|
436 |
"project_id": project_id, |
|
5cc83cd7d1d1
renkan from notice/datasheet and correct renkan from facettes.
cavaliet
parents:
315
diff
changeset
|
437 |
#"created_by": "de68xf75y6hs5rgjhgghxbm217xk" |
|
5cc83cd7d1d1
renkan from notice/datasheet and correct renkan from facettes.
cavaliet
parents:
315
diff
changeset
|
438 |
}) |
|
5cc83cd7d1d1
renkan from notice/datasheet and correct renkan from facettes.
cavaliet
parents:
315
diff
changeset
|
439 |
|
|
5cc83cd7d1d1
renkan from notice/datasheet and correct renkan from facettes.
cavaliet
parents:
315
diff
changeset
|
440 |
response = json.dumps(content) |
|
5cc83cd7d1d1
renkan from notice/datasheet and correct renkan from facettes.
cavaliet
parents:
315
diff
changeset
|
441 |
return HttpResponse(response, content_type="application/json") |
|
5cc83cd7d1d1
renkan from notice/datasheet and correct renkan from facettes.
cavaliet
parents:
315
diff
changeset
|
442 |
|
|
5cc83cd7d1d1
renkan from notice/datasheet and correct renkan from facettes.
cavaliet
parents:
315
diff
changeset
|
443 |
|
| 314 | 444 |
# Otherwise we build the datas |
445 |
# Get tags and countries |
|
446 |
labels = request.GET.get("label", "").split(",") |
|
447 |
countries = request.GET.get("country", "").split(",") |
|
| 338 | 448 |
period = request.GET.get("period", None) |
| 314 | 449 |
# Tags arrive with french label, countries with dbpedia uri |
450 |
label_list = [t for t in labels if t!=""] |
|
451 |
country_list = [c for c in countries if c!=""] |
|
452 |
all_tags = Tag.objects.filter( Q(label__in=label_list) | Q(dbpedia_uri__in=country_list) ).select_related("dbpedia_fields", "category") |
|
453 |
||
|
437
8269c74d9aa0
Close #40 - get only 8 ressources in the renkan and send the 10 next to the bins for further use
rougeronj
parents:
436
diff
changeset
|
454 |
# Get datasheets from ajax filter search |
|
8269c74d9aa0
Close #40 - get only 8 ressources in the renkan and send the 10 next to the bins for further use
rougeronj
parents:
436
diff
changeset
|
455 |
temp_fitler = filter_generic(lang, period, ",".join(label_list), ",".join(country_list), content_count=18) |
|
8269c74d9aa0
Close #40 - get only 8 ressources in the renkan and send the 10 next to the bins for further use
rougeronj
parents:
436
diff
changeset
|
456 |
filter_output = json.loads(temp_fitler) |
|
8269c74d9aa0
Close #40 - get only 8 ressources in the renkan and send the 10 next to the bins for further use
rougeronj
parents:
436
diff
changeset
|
457 |
filter_output_to_bin = json.loads(temp_fitler) |
|
299
8e00641076e7
remove renkan management to an other django app (see renkan hg repo)
cavaliet
parents:
297
diff
changeset
|
458 |
|
|
437
8269c74d9aa0
Close #40 - get only 8 ressources in the renkan and send the 10 next to the bins for further use
rougeronj
parents:
436
diff
changeset
|
459 |
#Keep only the 8 first ressources to create the graph |
|
8269c74d9aa0
Close #40 - get only 8 ressources in the renkan and send the 10 next to the bins for further use
rougeronj
parents:
436
diff
changeset
|
460 |
#the 10 next are sent to the bins |
|
8269c74d9aa0
Close #40 - get only 8 ressources in the renkan and send the 10 next to the bins for further use
rougeronj
parents:
436
diff
changeset
|
461 |
for i in range(len(filter_output["contents"])): |
|
8269c74d9aa0
Close #40 - get only 8 ressources in the renkan and send the 10 next to the bins for further use
rougeronj
parents:
436
diff
changeset
|
462 |
if (i < 8): |
|
8269c74d9aa0
Close #40 - get only 8 ressources in the renkan and send the 10 next to the bins for further use
rougeronj
parents:
436
diff
changeset
|
463 |
del filter_output_to_bin["contents"][0] |
|
8269c74d9aa0
Close #40 - get only 8 ressources in the renkan and send the 10 next to the bins for further use
rougeronj
parents:
436
diff
changeset
|
464 |
else: |
|
8269c74d9aa0
Close #40 - get only 8 ressources in the renkan and send the 10 next to the bins for further use
rougeronj
parents:
436
diff
changeset
|
465 |
del filter_output["contents"][8] |
|
8269c74d9aa0
Close #40 - get only 8 ressources in the renkan and send the 10 next to the bins for further use
rougeronj
parents:
436
diff
changeset
|
466 |
|
|
8269c74d9aa0
Close #40 - get only 8 ressources in the renkan and send the 10 next to the bins for further use
rougeronj
parents:
436
diff
changeset
|
467 |
content["bins"] = { |
|
8269c74d9aa0
Close #40 - get only 8 ressources in the renkan and send the 10 next to the bins for further use
rougeronj
parents:
436
diff
changeset
|
468 |
"type": "ResourceList", |
|
445
a74ec9e02042
correct #35 + add tag abstract + improve translations
ymh <ymh.work@gmail.com>
parents:
438
diff
changeset
|
469 |
"title": _("Plus de Ressources"), #TODO: Translate |
|
437
8269c74d9aa0
Close #40 - get only 8 ressources in the renkan and send the 10 next to the bins for further use
rougeronj
parents:
436
diff
changeset
|
470 |
"list": filter_output_to_bin["contents"] |
|
8269c74d9aa0
Close #40 - get only 8 ressources in the renkan and send the 10 next to the bins for further use
rougeronj
parents:
436
diff
changeset
|
471 |
} |
|
299
8e00641076e7
remove renkan management to an other django app (see renkan hg repo)
cavaliet
parents:
297
diff
changeset
|
472 |
|
|
8e00641076e7
remove renkan management to an other django app (see renkan hg repo)
cavaliet
parents:
297
diff
changeset
|
473 |
# Prepare other tags |
|
8e00641076e7
remove renkan management to an other django app (see renkan hg repo)
cavaliet
parents:
297
diff
changeset
|
474 |
related_tags = [] |
|
8e00641076e7
remove renkan management to an other django app (see renkan hg repo)
cavaliet
parents:
297
diff
changeset
|
475 |
all_labels = [t.label for t in all_tags] |
|
302
106c33871db4
better presentation and automatic save for renkan from facettes
cavaliet
parents:
301
diff
changeset
|
476 |
title = "Recherche " + ", ".join(all_labels) |
| 339 | 477 |
if period: |
478 |
title += ", " + _("Period") + " " + period |
|
|
302
106c33871db4
better presentation and automatic save for renkan from facettes
cavaliet
parents:
301
diff
changeset
|
479 |
content["title"] = title |
|
299
8e00641076e7
remove renkan management to an other django app (see renkan hg repo)
cavaliet
parents:
297
diff
changeset
|
480 |
related_tags_dict = {} |
|
8e00641076e7
remove renkan management to an other django app (see renkan hg repo)
cavaliet
parents:
297
diff
changeset
|
481 |
for c in filter_output["contents"]: |
|
8e00641076e7
remove renkan management to an other django app (see renkan hg repo)
cavaliet
parents:
297
diff
changeset
|
482 |
c["id"] = unicode(uuid.uuid1()) |
|
8e00641076e7
remove renkan management to an other django app (see renkan hg repo)
cavaliet
parents:
297
diff
changeset
|
483 |
related_tags_dict[c["id"]] = [] |
|
8e00641076e7
remove renkan management to an other django app (see renkan hg repo)
cavaliet
parents:
297
diff
changeset
|
484 |
for t in c["tags"]: |
|
8e00641076e7
remove renkan management to an other django app (see renkan hg repo)
cavaliet
parents:
297
diff
changeset
|
485 |
if t["label"] not in all_labels and t["order"]<6: |
|
8e00641076e7
remove renkan management to an other django app (see renkan hg repo)
cavaliet
parents:
297
diff
changeset
|
486 |
thumbnail_url = "" |
|
8e00641076e7
remove renkan management to an other django app (see renkan hg repo)
cavaliet
parents:
297
diff
changeset
|
487 |
for tt in filter_output["tags"]: |
|
8e00641076e7
remove renkan management to an other django app (see renkan hg repo)
cavaliet
parents:
297
diff
changeset
|
488 |
if tt["label"]==t["label"]: |
|
8e00641076e7
remove renkan management to an other django app (see renkan hg repo)
cavaliet
parents:
297
diff
changeset
|
489 |
thumbnail_url = tt["thumbnail"] |
|
445
a74ec9e02042
correct #35 + add tag abstract + improve translations
ymh <ymh.work@gmail.com>
parents:
438
diff
changeset
|
490 |
related_tags.append({"label": t["label"], "thumbnail":thumbnail_url, "id":t["id"], "url":t["url"], 'wkpd_url': t['wkpd_url']}) |
|
299
8e00641076e7
remove renkan management to an other django app (see renkan hg repo)
cavaliet
parents:
297
diff
changeset
|
491 |
all_labels.append(t["label"]) |
|
316
5cc83cd7d1d1
renkan from notice/datasheet and correct renkan from facettes.
cavaliet
parents:
315
diff
changeset
|
492 |
related_tags_dict[c["id"]].append(t["id"]) |
| 313 | 493 |
|
494 |
||
495 |
# If possible, we search a dbpedia_fields thumbnail or category thumbnail for related tags |
|
496 |
r_tags = [t["label"] for t in related_tags if t["thumbnail"] is None or t["thumbnail"]=="" ] |
|
497 |
r_tags = Tag.objects.filter( label__in=r_tags ).select_related("dbpedia_fields", "category") |
|
498 |
r_tags_dict = {} |
|
499 |
for t in r_tags: |
|
500 |
img_url = t.dbpedia_fields.thumbnail if hasattr(t, 'dbpedia_fields') and t.dbpedia_fields and t.dbpedia_fields.thumbnail else None |
|
501 |
if img_url is None and t.category is not None: |
|
502 |
img_url = cat_dict[t.category.label] |
|
503 |
if img_url: |
|
504 |
r_tags_dict[t.label] = img_url |
|
505 |
# Populate related_tags with found image urls |
|
506 |
for t in related_tags: |
|
507 |
if (t["thumbnail"] is None or t["thumbnail"]=="") and (t["label"] in r_tags_dict): |
|
508 |
t["thumbnail"] = r_tags_dict[t["label"]] |
|
509 |
||
|
299
8e00641076e7
remove renkan management to an other django app (see renkan hg repo)
cavaliet
parents:
297
diff
changeset
|
510 |
|
|
8e00641076e7
remove renkan management to an other django app (see renkan hg repo)
cavaliet
parents:
297
diff
changeset
|
511 |
# Prepare Node placer : |
|
431
adb0be6dfdcf
Close #37 - circle representation by default in every kind of generated renkan (filter, notice, folder)
rougeronj
parents:
420
diff
changeset
|
512 |
np = CircleNodePlacer() |
|
adb0be6dfdcf
Close #37 - circle representation by default in every kind of generated renkan (filter, notice, folder)
rougeronj
parents:
420
diff
changeset
|
513 |
if shape=="horiz": |
|
adb0be6dfdcf
Close #37 - circle representation by default in every kind of generated renkan (filter, notice, folder)
rougeronj
parents:
420
diff
changeset
|
514 |
np = HorLineNodePlacer() |
|
adb0be6dfdcf
Close #37 - circle representation by default in every kind of generated renkan (filter, notice, folder)
rougeronj
parents:
420
diff
changeset
|
515 |
elif shape=="vert": |
|
adb0be6dfdcf
Close #37 - circle representation by default in every kind of generated renkan (filter, notice, folder)
rougeronj
parents:
420
diff
changeset
|
516 |
np = LineNodePlacer() |
|
adb0be6dfdcf
Close #37 - circle representation by default in every kind of generated renkan (filter, notice, folder)
rougeronj
parents:
420
diff
changeset
|
517 |
|
| 338 | 518 |
len_tags = len(all_tags) |
519 |
if period: |
|
520 |
len_tags += 1 |
|
| 340 | 521 |
np.init({"tags": (1, len_tags), "datasheet": (2, len(filter_output["contents"])), "related": (3, len(related_tags)), "northwest":(3 if shape=="circle" else 1, 1)}) |
|
299
8e00641076e7
remove renkan management to an other django app (see renkan hg repo)
cavaliet
parents:
297
diff
changeset
|
522 |
|
|
445
a74ec9e02042
correct #35 + add tag abstract + improve translations
ymh <ymh.work@gmail.com>
parents:
438
diff
changeset
|
523 |
#get tag abstract and label translations |
|
a74ec9e02042
correct #35 + add tag abstract + improve translations
ymh <ymh.work@gmail.com>
parents:
438
diff
changeset
|
524 |
|
|
a74ec9e02042
correct #35 + add tag abstract + improve translations
ymh <ymh.work@gmail.com>
parents:
438
diff
changeset
|
525 |
tags_id = [t.id for t in all_tags] + [t['id'] for t in related_tags] |
|
a74ec9e02042
correct #35 + add tag abstract + improve translations
ymh <ymh.work@gmail.com>
parents:
438
diff
changeset
|
526 |
translations = {} |
|
a74ec9e02042
correct #35 + add tag abstract + improve translations
ymh <ymh.work@gmail.com>
parents:
438
diff
changeset
|
527 |
transqs = DbpediaFieldsTranslation.objects.filter(master__tag__in = tags_id, language_code = lang) |
|
a74ec9e02042
correct #35 + add tag abstract + improve translations
ymh <ymh.work@gmail.com>
parents:
438
diff
changeset
|
528 |
translations = dict([(trans.master.tag.id,trans) for trans in transqs]) |
|
a74ec9e02042
correct #35 + add tag abstract + improve translations
ymh <ymh.work@gmail.com>
parents:
438
diff
changeset
|
529 |
|
|
a74ec9e02042
correct #35 + add tag abstract + improve translations
ymh <ymh.work@gmail.com>
parents:
438
diff
changeset
|
530 |
|
|
299
8e00641076e7
remove renkan management to an other django app (see renkan hg repo)
cavaliet
parents:
297
diff
changeset
|
531 |
for t in all_tags: |
| 312 | 532 |
img_url = t.dbpedia_fields.thumbnail if hasattr(t, 'dbpedia_fields') and t.dbpedia_fields and t.dbpedia_fields.thumbnail else None |
533 |
if img_url is None and t.category is not None: |
|
| 313 | 534 |
img_url = cat_dict[t.category.label] |
|
445
a74ec9e02042
correct #35 + add tag abstract + improve translations
ymh <ymh.work@gmail.com>
parents:
438
diff
changeset
|
535 |
translation_obj = translations.get(t.id, None) |
|
a74ec9e02042
correct #35 + add tag abstract + improve translations
ymh <ymh.work@gmail.com>
parents:
438
diff
changeset
|
536 |
translation = { |
|
a74ec9e02042
correct #35 + add tag abstract + improve translations
ymh <ymh.work@gmail.com>
parents:
438
diff
changeset
|
537 |
'label': filter_output["tagtranslations"][t.label] if t.label in filter_output["tagtranslations"] else t.label, |
|
a74ec9e02042
correct #35 + add tag abstract + improve translations
ymh <ymh.work@gmail.com>
parents:
438
diff
changeset
|
538 |
'abstract': translation_obj.abstract if translation_obj else "" |
|
a74ec9e02042
correct #35 + add tag abstract + improve translations
ymh <ymh.work@gmail.com>
parents:
438
diff
changeset
|
539 |
} |
| 312 | 540 |
|
|
299
8e00641076e7
remove renkan management to an other django app (see renkan hg repo)
cavaliet
parents:
297
diff
changeset
|
541 |
content["nodes"].append({ |
|
8e00641076e7
remove renkan management to an other django app (see renkan hg repo)
cavaliet
parents:
297
diff
changeset
|
542 |
"id": unicode(uuid.uuid1()), |
|
445
a74ec9e02042
correct #35 + add tag abstract + improve translations
ymh <ymh.work@gmail.com>
parents:
438
diff
changeset
|
543 |
"title": translation['label'], |
|
a74ec9e02042
correct #35 + add tag abstract + improve translations
ymh <ymh.work@gmail.com>
parents:
438
diff
changeset
|
544 |
"description": translation['abstract'], |
|
a74ec9e02042
correct #35 + add tag abstract + improve translations
ymh <ymh.work@gmail.com>
parents:
438
diff
changeset
|
545 |
"uri": t.wikipedia_url, |
|
299
8e00641076e7
remove renkan management to an other django app (see renkan hg repo)
cavaliet
parents:
297
diff
changeset
|
546 |
"position": np.get_place("tags"), |
| 312 | 547 |
"image": img_url, |
|
299
8e00641076e7
remove renkan management to an other django app (see renkan hg repo)
cavaliet
parents:
297
diff
changeset
|
548 |
"size": 0, |
|
8e00641076e7
remove renkan management to an other django app (see renkan hg repo)
cavaliet
parents:
297
diff
changeset
|
549 |
"project_id": project_id, |
|
627
3fd558fa38b1
correct various small bugs. upgrade renkan. news version
ymh <ymh.work@gmail.com>
parents:
608
diff
changeset
|
550 |
"style" : { |
|
3fd558fa38b1
correct various small bugs. upgrade renkan. news version
ymh <ymh.work@gmail.com>
parents:
608
diff
changeset
|
551 |
"color": None, |
|
3fd558fa38b1
correct various small bugs. upgrade renkan. news version
ymh <ymh.work@gmail.com>
parents:
608
diff
changeset
|
552 |
}, |
| 333 | 553 |
"shape": shapes["tag1"] |
|
299
8e00641076e7
remove renkan management to an other django app (see renkan hg repo)
cavaliet
parents:
297
diff
changeset
|
554 |
}) |
| 338 | 555 |
if period: |
556 |
content["nodes"].append({ |
|
557 |
"id": unicode(uuid.uuid1()), |
|
| 339 | 558 |
"title": _("Period") + " " + period, |
| 338 | 559 |
"description": "", |
560 |
"uri": "", |
|
561 |
"position": np.get_place("tags"), |
|
562 |
"image": cat_dict[u"Datation"], |
|
563 |
"size": 0, |
|
564 |
"project_id": project_id, |
|
|
627
3fd558fa38b1
correct various small bugs. upgrade renkan. news version
ymh <ymh.work@gmail.com>
parents:
608
diff
changeset
|
565 |
"style": { |
|
3fd558fa38b1
correct various small bugs. upgrade renkan. news version
ymh <ymh.work@gmail.com>
parents:
608
diff
changeset
|
566 |
"color": None |
|
3fd558fa38b1
correct various small bugs. upgrade renkan. news version
ymh <ymh.work@gmail.com>
parents:
608
diff
changeset
|
567 |
}, |
| 338 | 568 |
"shape": shapes["tag1"] |
569 |
}) |
|
|
299
8e00641076e7
remove renkan management to an other django app (see renkan hg repo)
cavaliet
parents:
297
diff
changeset
|
570 |
|
|
8e00641076e7
remove renkan management to an other django app (see renkan hg repo)
cavaliet
parents:
297
diff
changeset
|
571 |
for c in filter_output["contents"]: |
|
8e00641076e7
remove renkan management to an other django app (see renkan hg repo)
cavaliet
parents:
297
diff
changeset
|
572 |
content["nodes"].append({ |
|
8e00641076e7
remove renkan management to an other django app (see renkan hg repo)
cavaliet
parents:
297
diff
changeset
|
573 |
"id": c["id"], |
|
8e00641076e7
remove renkan management to an other django app (see renkan hg repo)
cavaliet
parents:
297
diff
changeset
|
574 |
"title": c["title"], |
|
8e00641076e7
remove renkan management to an other django app (see renkan hg repo)
cavaliet
parents:
297
diff
changeset
|
575 |
"description": c["description"], |
|
8e00641076e7
remove renkan management to an other django app (see renkan hg repo)
cavaliet
parents:
297
diff
changeset
|
576 |
"uri": c["url"], |
|
8e00641076e7
remove renkan management to an other django app (see renkan hg repo)
cavaliet
parents:
297
diff
changeset
|
577 |
"position": np.get_place("datasheet"), |
| 326 | 578 |
"image": "http://www.histoiredesarts.culture.fr/images/pf/" + c["hda_id"]+ ".jpg", |
|
299
8e00641076e7
remove renkan management to an other django app (see renkan hg repo)
cavaliet
parents:
297
diff
changeset
|
579 |
"size": 0, |
|
8e00641076e7
remove renkan management to an other django app (see renkan hg repo)
cavaliet
parents:
297
diff
changeset
|
580 |
"project_id": project_id, |
|
627
3fd558fa38b1
correct various small bugs. upgrade renkan. news version
ymh <ymh.work@gmail.com>
parents:
608
diff
changeset
|
581 |
"style" : { |
|
3fd558fa38b1
correct various small bugs. upgrade renkan. news version
ymh <ymh.work@gmail.com>
parents:
608
diff
changeset
|
582 |
"color": "#FF0033" |
|
3fd558fa38b1
correct various small bugs. upgrade renkan. news version
ymh <ymh.work@gmail.com>
parents:
608
diff
changeset
|
583 |
}, |
| 333 | 584 |
"shape": shapes["notice"] |
|
299
8e00641076e7
remove renkan management to an other django app (see renkan hg repo)
cavaliet
parents:
297
diff
changeset
|
585 |
}) |
|
8e00641076e7
remove renkan management to an other django app (see renkan hg repo)
cavaliet
parents:
297
diff
changeset
|
586 |
|
|
8e00641076e7
remove renkan management to an other django app (see renkan hg repo)
cavaliet
parents:
297
diff
changeset
|
587 |
for t in related_tags: |
|
445
a74ec9e02042
correct #35 + add tag abstract + improve translations
ymh <ymh.work@gmail.com>
parents:
438
diff
changeset
|
588 |
translation_obj = translations.get(t['id'], None) |
|
a74ec9e02042
correct #35 + add tag abstract + improve translations
ymh <ymh.work@gmail.com>
parents:
438
diff
changeset
|
589 |
translation = { |
|
a74ec9e02042
correct #35 + add tag abstract + improve translations
ymh <ymh.work@gmail.com>
parents:
438
diff
changeset
|
590 |
'label': filter_output["tagtranslations"][t["label"]], |
|
a74ec9e02042
correct #35 + add tag abstract + improve translations
ymh <ymh.work@gmail.com>
parents:
438
diff
changeset
|
591 |
'abstract': translation_obj.abstract if translation_obj else "" |
|
a74ec9e02042
correct #35 + add tag abstract + improve translations
ymh <ymh.work@gmail.com>
parents:
438
diff
changeset
|
592 |
} |
|
a74ec9e02042
correct #35 + add tag abstract + improve translations
ymh <ymh.work@gmail.com>
parents:
438
diff
changeset
|
593 |
|
|
299
8e00641076e7
remove renkan management to an other django app (see renkan hg repo)
cavaliet
parents:
297
diff
changeset
|
594 |
content["nodes"].append({ |
|
8e00641076e7
remove renkan management to an other django app (see renkan hg repo)
cavaliet
parents:
297
diff
changeset
|
595 |
"id": t["id"], |
|
445
a74ec9e02042
correct #35 + add tag abstract + improve translations
ymh <ymh.work@gmail.com>
parents:
438
diff
changeset
|
596 |
"title": translation['label'], |
|
a74ec9e02042
correct #35 + add tag abstract + improve translations
ymh <ymh.work@gmail.com>
parents:
438
diff
changeset
|
597 |
"description": translation['abstract'], |
|
a74ec9e02042
correct #35 + add tag abstract + improve translations
ymh <ymh.work@gmail.com>
parents:
438
diff
changeset
|
598 |
"uri": t["wkpd_url"], |
|
299
8e00641076e7
remove renkan management to an other django app (see renkan hg repo)
cavaliet
parents:
297
diff
changeset
|
599 |
"position": np.get_place("related"), |
|
8e00641076e7
remove renkan management to an other django app (see renkan hg repo)
cavaliet
parents:
297
diff
changeset
|
600 |
"image": t["thumbnail"], |
|
8e00641076e7
remove renkan management to an other django app (see renkan hg repo)
cavaliet
parents:
297
diff
changeset
|
601 |
"size": 0, |
|
8e00641076e7
remove renkan management to an other django app (see renkan hg repo)
cavaliet
parents:
297
diff
changeset
|
602 |
"project_id": project_id, |
|
627
3fd558fa38b1
correct various small bugs. upgrade renkan. news version
ymh <ymh.work@gmail.com>
parents:
608
diff
changeset
|
603 |
"style": { |
|
3fd558fa38b1
correct various small bugs. upgrade renkan. news version
ymh <ymh.work@gmail.com>
parents:
608
diff
changeset
|
604 |
"color": "#00FF33" |
|
3fd558fa38b1
correct various small bugs. upgrade renkan. news version
ymh <ymh.work@gmail.com>
parents:
608
diff
changeset
|
605 |
}, |
| 333 | 606 |
"shape": shapes["tag2"] |
|
299
8e00641076e7
remove renkan management to an other django app (see renkan hg repo)
cavaliet
parents:
297
diff
changeset
|
607 |
}) |
|
8e00641076e7
remove renkan management to an other django app (see renkan hg repo)
cavaliet
parents:
297
diff
changeset
|
608 |
|
|
8e00641076e7
remove renkan management to an other django app (see renkan hg repo)
cavaliet
parents:
297
diff
changeset
|
609 |
for c_id in related_tags_dict: |
|
8e00641076e7
remove renkan management to an other django app (see renkan hg repo)
cavaliet
parents:
297
diff
changeset
|
610 |
for tag_id in related_tags_dict[c_id]: |
|
8e00641076e7
remove renkan management to an other django app (see renkan hg repo)
cavaliet
parents:
297
diff
changeset
|
611 |
content["edges"].append({ |
|
8e00641076e7
remove renkan management to an other django app (see renkan hg repo)
cavaliet
parents:
297
diff
changeset
|
612 |
"id": unicode(uuid.uuid1()), |
|
8e00641076e7
remove renkan management to an other django app (see renkan hg repo)
cavaliet
parents:
297
diff
changeset
|
613 |
"title": "", |
|
8e00641076e7
remove renkan management to an other django app (see renkan hg repo)
cavaliet
parents:
297
diff
changeset
|
614 |
"description": "", |
|
8e00641076e7
remove renkan management to an other django app (see renkan hg repo)
cavaliet
parents:
297
diff
changeset
|
615 |
"uri": "", |
|
627
3fd558fa38b1
correct various small bugs. upgrade renkan. news version
ymh <ymh.work@gmail.com>
parents:
608
diff
changeset
|
616 |
"style": { |
|
3fd558fa38b1
correct various small bugs. upgrade renkan. news version
ymh <ymh.work@gmail.com>
parents:
608
diff
changeset
|
617 |
"color": None, |
|
3fd558fa38b1
correct various small bugs. upgrade renkan. news version
ymh <ymh.work@gmail.com>
parents:
608
diff
changeset
|
618 |
}, |
|
299
8e00641076e7
remove renkan management to an other django app (see renkan hg repo)
cavaliet
parents:
297
diff
changeset
|
619 |
"from": c_id, |
|
8e00641076e7
remove renkan management to an other django app (see renkan hg repo)
cavaliet
parents:
297
diff
changeset
|
620 |
"to": tag_id, |
|
8e00641076e7
remove renkan management to an other django app (see renkan hg repo)
cavaliet
parents:
297
diff
changeset
|
621 |
"project_id": project_id, |
|
8e00641076e7
remove renkan management to an other django app (see renkan hg repo)
cavaliet
parents:
297
diff
changeset
|
622 |
#"created_by": "de68xf75y6hs5rgjhgghxbm217xk" |
|
8e00641076e7
remove renkan management to an other django app (see renkan hg repo)
cavaliet
parents:
297
diff
changeset
|
623 |
}) |
|
8e00641076e7
remove renkan management to an other django app (see renkan hg repo)
cavaliet
parents:
297
diff
changeset
|
624 |
|
|
302
106c33871db4
better presentation and automatic save for renkan from facettes
cavaliet
parents:
301
diff
changeset
|
625 |
response = json.dumps(content) |
|
106c33871db4
better presentation and automatic save for renkan from facettes
cavaliet
parents:
301
diff
changeset
|
626 |
|
|
106c33871db4
better presentation and automatic save for renkan from facettes
cavaliet
parents:
301
diff
changeset
|
627 |
return HttpResponse(response, content_type="application/json") |
| 310 | 628 |
|
629 |
||
630 |
def post(self, request): |
|
631 |
||
632 |
rk_id = request.GET.get("rk_id", "") |
|
633 |
#data = json.loads(request.body) |
|
634 |
#logger.debug(data["edges"]) |
|
635 |
#logger.debug(data["nodes"]) |
|
636 |
#logger.debug(request.user.is_authenticated()) |
|
637 |
#logger.debug(request.user.is_anonymous()) |
|
638 |
if rk_id!="": |
|
639 |
rk = get_object_or_404(Renkan, rk_id=rk_id) |
|
640 |
if rk.owner!=request.user: |
|
641 |
return HttpResponseBadRequest("You are not allowed to edit this renkan") |
|
642 |
rk.content = request.body |
|
643 |
data = json.loads(request.body) |
|
644 |
if "title" in data: |
|
645 |
rk.title = data["title"] |
|
646 |
rk.save() |
|
647 |
return HttpResponse("SAVED") |
|
648 |
else: |
|
649 |
# if rk_id was not a get parameter AND if it is set in json data AND if user is authenticated |
|
650 |
# Then we can save the renkan |
|
651 |
data = json.loads(request.body) |
|
652 |
if "id" in data: |
|
653 |
rk_id = data["id"] |
|
654 |
if rk_id != "" and Renkan.objects.filter(rk_id=rk_id).count()==0 and request.user.is_authenticated(): |
|
655 |
rk = Renkan() |
|
656 |
rk.rk_id = rk_id |
|
657 |
rk.title = data["title"] if "title" in data else "" |
|
| 334 | 658 |
rk.content = request.body |
| 310 | 659 |
rk.owner = request.user |
660 |
rk.save() |
|
661 |
hr = HdalabRenkan() |
|
662 |
hr.renkan = rk |
|
663 |
hr.state = HdalabRenkan.EDITION |
|
664 |
hr.save() |
|
665 |
return HttpResponse("rk_id=" + rk_id) |
|
666 |
||
667 |
||
668 |
return HttpResponse("NOT SAVED") |
|
|
299
8e00641076e7
remove renkan management to an other django app (see renkan hg repo)
cavaliet
parents:
297
diff
changeset
|
669 |
|
|
8e00641076e7
remove renkan management to an other django app (see renkan hg repo)
cavaliet
parents:
297
diff
changeset
|
670 |
|
| 301 | 671 |
|
672 |
class HdalabRenkanCopy(View): |
|
673 |
||
|
458
604b887e70c3
add state history to renkan, correct get into post, generally prepare ground for mail management
ymh <ymh.work@gmail.com>
parents:
445
diff
changeset
|
674 |
def post(self, request, rk_id): |
| 301 | 675 |
rk = renkan_copier(request.user, rk_id) |
676 |
hr = HdalabRenkan() |
|
677 |
hr.renkan = rk |
|
678 |
hr.state = HdalabRenkan.EDITION |
|
679 |
hr.save() |
|
|
458
604b887e70c3
add state history to renkan, correct get into post, generally prepare ground for mail management
ymh <ymh.work@gmail.com>
parents:
445
diff
changeset
|
680 |
if "next" in request.POST: |
|
604b887e70c3
add state history to renkan, correct get into post, generally prepare ground for mail management
ymh <ymh.work@gmail.com>
parents:
445
diff
changeset
|
681 |
return redirect(request.POST["next"]) |
| 301 | 682 |
return redirect(reverse('profile_home')) |
683 |
||
684 |
||
685 |
class HdalabRenkanDelete(View): |
|
686 |
||
|
458
604b887e70c3
add state history to renkan, correct get into post, generally prepare ground for mail management
ymh <ymh.work@gmail.com>
parents:
445
diff
changeset
|
687 |
def post(self, request, rk_id): |
| 330 | 688 |
try: |
689 |
hr = HdalabRenkan.objects.get(renkan__rk_id=rk_id) |
|
690 |
except: |
|
691 |
raise Http404('Renkan not found') |
|
| 301 | 692 |
renkan_deleter(request.user, rk_id) |
| 330 | 693 |
hr.delete() |
|
458
604b887e70c3
add state history to renkan, correct get into post, generally prepare ground for mail management
ymh <ymh.work@gmail.com>
parents:
445
diff
changeset
|
694 |
if "next" in request.POST: |
|
604b887e70c3
add state history to renkan, correct get into post, generally prepare ground for mail management
ymh <ymh.work@gmail.com>
parents:
445
diff
changeset
|
695 |
return redirect(request.POST["next"]) |
| 301 | 696 |
return redirect(reverse('profile_home')) |
| 308 | 697 |
|
698 |
||
| 473 | 699 |
class HdalabRenkanModerate(View): |
|
329
ea6268cf8c83
renkan state management for staff members : publish, unpublish, reject.
cavaliet
parents:
326
diff
changeset
|
700 |
|
|
458
604b887e70c3
add state history to renkan, correct get into post, generally prepare ground for mail management
ymh <ymh.work@gmail.com>
parents:
445
diff
changeset
|
701 |
def post(self, request, rk_id): |
|
604b887e70c3
add state history to renkan, correct get into post, generally prepare ground for mail management
ymh <ymh.work@gmail.com>
parents:
445
diff
changeset
|
702 |
form = HdalabRenkanStateForm(request.POST) |
|
604b887e70c3
add state history to renkan, correct get into post, generally prepare ground for mail management
ymh <ymh.work@gmail.com>
parents:
445
diff
changeset
|
703 |
if form.is_valid(): |
|
604b887e70c3
add state history to renkan, correct get into post, generally prepare ground for mail management
ymh <ymh.work@gmail.com>
parents:
445
diff
changeset
|
704 |
logger.debug("FORM DATA %r", form.cleaned_data) |
| 473 | 705 |
renkan_hda = get_object_or_404(HdalabRenkan.objects.select_related(), renkan__rk_id=rk_id) |
|
458
604b887e70c3
add state history to renkan, correct get into post, generally prepare ground for mail management
ymh <ymh.work@gmail.com>
parents:
445
diff
changeset
|
706 |
change_renkan_state(renkan_hda, form.cleaned_data['state'], form.cleaned_data['message'], request.user) |
|
604b887e70c3
add state history to renkan, correct get into post, generally prepare ground for mail management
ymh <ymh.work@gmail.com>
parents:
445
diff
changeset
|
707 |
next_url = form.cleaned_data.get('next', None) |
|
604b887e70c3
add state history to renkan, correct get into post, generally prepare ground for mail management
ymh <ymh.work@gmail.com>
parents:
445
diff
changeset
|
708 |
if next_url: |
|
604b887e70c3
add state history to renkan, correct get into post, generally prepare ground for mail management
ymh <ymh.work@gmail.com>
parents:
445
diff
changeset
|
709 |
return redirect(next_url) |
|
604b887e70c3
add state history to renkan, correct get into post, generally prepare ground for mail management
ymh <ymh.work@gmail.com>
parents:
445
diff
changeset
|
710 |
else: |
|
604b887e70c3
add state history to renkan, correct get into post, generally prepare ground for mail management
ymh <ymh.work@gmail.com>
parents:
445
diff
changeset
|
711 |
redirect(reverse('profile_home')) |
|
604b887e70c3
add state history to renkan, correct get into post, generally prepare ground for mail management
ymh <ymh.work@gmail.com>
parents:
445
diff
changeset
|
712 |
else: |
|
604b887e70c3
add state history to renkan, correct get into post, generally prepare ground for mail management
ymh <ymh.work@gmail.com>
parents:
445
diff
changeset
|
713 |
logger.debug("FORM INVALID %r : %r", request.POST, form.errors) |
|
604b887e70c3
add state history to renkan, correct get into post, generally prepare ground for mail management
ymh <ymh.work@gmail.com>
parents:
445
diff
changeset
|
714 |
return HttpResponseBadRequest("State form invalid") |
|
329
ea6268cf8c83
renkan state management for staff members : publish, unpublish, reject.
cavaliet
parents:
326
diff
changeset
|
715 |
|
| 473 | 716 |
class HdalabRenkanFavorite(View): |
717 |
||
718 |
def post(self, request, rk_id): |
|
719 |
form = HdalabRenkanFavoriteForm(request.POST) |
|
720 |
if form.is_valid(): |
|
721 |
renkan_hda = get_object_or_404(HdalabRenkan.objects.select_related(), renkan__rk_id=rk_id) |
|
722 |
renkan_hda.favorite = form.cleaned_data['favorite'] |
|
723 |
renkan_hda.save() |
|
724 |
return HttpResponse( |
|
725 |
json.dumps({'status': 'ok', 'renkan': {'rk_id': renkan_hda.renkan.rk_id, 'favorite': renkan_hda.favorite}}), |
|
726 |
content_type="application/json" |
|
727 |
) |
|
|
329
ea6268cf8c83
renkan state management for staff members : publish, unpublish, reject.
cavaliet
parents:
326
diff
changeset
|
728 |
|
|
ea6268cf8c83
renkan state management for staff members : publish, unpublish, reject.
cavaliet
parents:
326
diff
changeset
|
729 |
|
| 529 | 730 |
class UserProfileUpdate(UpdateView): |
731 |
fields = ['email'] |
|
732 |
template_name_suffix = '_update_form' |
|
733 |
||
734 |
def get_object(self, queryset=None): |
|
735 |
return self.request.user |
|
736 |
||
737 |
def get_success_url(self): |
|
738 |
return reverse('profile_home') |
|
739 |
||
740 |
||
| 308 | 741 |
# Function copied from django.contrib.auth.views to simplify ajax login |
742 |
@sensitive_post_parameters() |
|
743 |
@csrf_protect |
|
744 |
@never_cache |
|
745 |
def ajax_login(request, template_name='ajax_identification/ajax_login.html', |
|
746 |
redirect_field_name=REDIRECT_FIELD_NAME, |
|
747 |
authentication_form=AuthenticationForm, |
|
748 |
current_app=None, extra_context=None): |
|
749 |
""" |
|
750 |
Displays the login form and handles the login action. |
|
751 |
""" |
|
752 |
redirect_to = request.REQUEST.get(redirect_field_name, '') |
|
753 |
||
754 |
if request.method == "POST": |
|
755 |
form = authentication_form(request, data=request.POST) |
|
756 |
if form.is_valid(): |
|
757 |
||
758 |
# Ensure the user-originating redirection url is safe. |
|
759 |
if not is_safe_url(url=redirect_to, host=request.get_host()): |
|
760 |
redirect_to = resolve_url(settings.LOGIN_REDIRECT_URL) |
|
761 |
||
762 |
# Okay, security check complete. Log the user in. |
|
763 |
auth_login(request, form.get_user()) |
|
764 |
||
765 |
return HttpResponseRedirect(redirect_to) |
|
766 |
else: |
|
767 |
form = authentication_form(request) |
|
768 |
||
769 |
current_site = get_current_site(request) |
|
770 |
||
771 |
context = { |
|
772 |
'form': form, |
|
773 |
redirect_field_name: redirect_to, |
|
774 |
'site': current_site, |
|
775 |
'site_name': current_site.name, |
|
776 |
} |
|
777 |
if extra_context is not None: |
|
778 |
context.update(extra_context) |
|
779 |
return TemplateResponse(request, template_name, context, |
|
780 |
current_app=current_app) |