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