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