- {% if ordered_tags %}
- {# ordered_tags is a list of TaggedSheet #}
- {% for t in ordered_tags %}
-
-
{{forloop.counter}}
- {% if valid != "2" %}
-
{% if not forloop.first %}{% endif %}
-
{% if not forloop.last %}{% endif %}
- {% endif %}
-
{{t.tag.id}}
-
{{t.tag.label}}
- {% comment %}
{{t.tag.original_label}}
{% endcomment %}
-
- {% if t.tag.wikipedia_url and t.tag.wikipedia_url != "" %}
-
- {% else %}
-
- {% endif %}
-
-
-
-
{% if t.tag.alias %}{{t.tag.alias}}{% endif %}
-
- {% endfor %}
- {% else %}
- {# ds is a DataSheet #}
- {% for t in ds.tags.all %}
-
-
{{forloop.counter}}
- {% if valid != "2" and ordered_tags %}
-
{% if not forloop.first %}{% endif %}
-
{% if not forloop.last %}{% endif %}
- {% endif %}
-
{{t.id}}
-
{{t.label}}
- {% comment %}
{{t.original_label}}
{% endcomment %}
-
- {% if t.wikipedia_url and t.wikipedia_url != "" %}
-
- {% else %}
-
- {% endif %}
-
facette
-
-
-
{{t.alias}}
-
- {% endfor %}
- {% endif %}
-
-{% endblock %}
+{% block tag_table %}
+
+
#
+ {% if valid != "2" and ordered_tags %}
+
+ {% endif %}
+
id
+
label
+ {% comment %}
original_label
{% endcomment %}
+
Lien W
+
Facette
+
Supprimer le lien W
+
Alias
+
Retirer le tag de la liste
+ {% if ordered_tags %}
+ {# ordered_tags is a list of TaggedSheet #}
+ {% for t in ordered_tags %}
+
+
{{forloop.counter}}
+ {% if valid != "2" %}
+
+ {% endif %}
+
{{t.tag.id}}
+
{{t.tag.label}}
+ {% comment %}
{{t.tag.original_label}}
{% endcomment %}
+
+ {% if t.tag.wikipedia_url and t.tag.wikipedia_url != "" %}
+
+ {% else %}
+
+ {% endif %}
+
{% if t.tag.category %}{{ t.tag.category }}{% endif %}
+
+
{% if t.tag.alias %}{{t.tag.alias}}{% endif %}
+
+ {% endfor %}
+ {% else %}
+ {# ds is a DataSheet #}
+ {% for t in ds.tags.all %}
+
+
{{forloop.counter}}
+ {% if valid != "2" and ordered_tags %}
+
+ {% endif %}
+
{{t.id}}
+
{{t.label}}
+ {% comment %}
{{t.original_label}}
{% endcomment %}
+
+ {% if t.wikipedia_url and t.wikipedia_url != "" %}
+
+ {% else %}
+
+ {% endif %}
+
{% if t.category %}{{ t.category }}{% endif %}
+
+
{{t.alias}}
+
+ {% endfor %}
+ {% endif %}
+
+{% endblock %}
diff -r e0812bc3ef44 -r 244d805b4921 web/hdabo/urls.py
--- a/web/hdabo/urls.py Fri Jun 17 14:17:49 2011 +0200
+++ b/web/hdabo/urls.py Fri Jun 17 17:14:09 2011 +0200
@@ -34,4 +34,6 @@
url(r'^validatedatasheet/(?P[\w-]+)$', 'hdabo.views.validate_datasheet'),
url(r'^validatedatasheet/(?P[\w-]+)/(?P[\w-]+)/$', 'hdabo.views.validate_datasheet'),
url(r'^updatetagalias$', 'hdabo.views.update_tag_alias'),
+ url(r'^updatetagcategory$', 'hdabo.views.update_tag_category'),
+ url(r'^getcategories$', 'hdabo.views.get_categories'),
)
diff -r e0812bc3ef44 -r 244d805b4921 web/hdabo/views.py
--- a/web/hdabo/views.py Fri Jun 17 14:17:49 2011 +0200
+++ b/web/hdabo/views.py Fri Jun 17 17:14:09 2011 +0200
@@ -4,7 +4,7 @@
from django.contrib.auth.decorators import login_required #@UnusedImport
from django.core.paginator import Paginator
from django.db.models import Max
-from django.http import HttpResponseBadRequest
+from django.http import HttpResponse, HttpResponseBadRequest
from django.shortcuts import render_to_response, redirect
from django.template import RequestContext
from haystack.constants import DJANGO_ID
@@ -12,7 +12,7 @@
from hdabo.management.commands.querywikipedia import process_tag
from hdabo.wp_utils import (normalize_tag, query_wikipedia_title,
get_or_create_tag)
-from models import Organisation, Datasheet, TaggedSheet, Tag
+from models import Datasheet, Organisation, Tag, TagCategory, TaggedSheet
from wikitools import wiki
import django.utils.simplejson as json
@@ -126,30 +126,31 @@
#@login_required
def tag_up_down(request):
ds_id = request.POST["datasheet_id"]
- #tag_id = request.POST["tag_id"]
- # tag_pos indicates the position (from 0) of the tag in the list. NB : it is different from the TagSheet.order in the database.
- tag_pos = int(request.POST["tag_pos"])
- # move can be "u" or "d", for up and down
- move = request.POST["move"]
- # First we get the datasheet's TaggedSheets
- ordered_tags = TaggedSheet.objects.filter(datasheet=Datasheet.objects.filter(id=ds_id)[0]).order_by('order')
- # We get the current TaggedSheet and its's order
- #ts = ordered_tags.filter(tag=Tag.objects.filter(id=tag_id))[0]
- ts = ordered_tags[tag_pos]
- tag_order = ts.order
- # We get the other TaggedSheet that will be moved
- if move == "u" :
- other_ts = ordered_tags[tag_pos - 1]
- elif move == "d" :
- other_ts = ordered_tags[tag_pos + 1]
+ # post vars new_order and old_order indicate the position (from 1) of the tag in the list.
+ # NB : it is different from the TagSheet.order in the database.
+ new_order = int(request.POST["new_order"]) - 1
+ old_order = int(request.POST["old_order"]) - 1
+ s = "new_order = " + str(new_order) + ", old_order = " + str(old_order)
+ # First we get the datasheet's TaggedSheets (list to force evaluation)
+ ordered_tags = list(TaggedSheet.objects.filter(datasheet=Datasheet.objects.get(id=ds_id)).order_by('order'))
+ # We change the moved TaggedSheets's order
+ new_ts_order = ordered_tags[new_order].order
+ moved_ts = ordered_tags[old_order]
+ moved_ts.order = new_ts_order
+ moved_ts.save()
+ # We move the TaggedSheets's order
+ if new_order > old_order :
+ # And we decrease the other ones
+ for i in range(old_order+1,new_order+1) :
+ ts = ordered_tags[i]
+ ts.order = ts.order - 1
+ ts.save()
else :
- other_ts = None
- # We switch the orders
- if other_ts :
- ts.order = other_ts.order
- other_ts.order = tag_order
- ts.save()
- other_ts.save()
+ # And we increase the other ones
+ for i in range(new_order,old_order) :
+ ts = ordered_tags[i]
+ ts.order = ts.order + 1
+ ts.save()
return get_tag_table(request=request, ds_id=ds_id, valid=0)
@@ -215,6 +216,7 @@
if tag.label != tag_label:
+
tag.label = tag_label
site = wiki.Wiki(settings.WIKIPEDIA_API_URL) #@UndefinedVariable
@@ -379,4 +381,26 @@
else :
return get_all_tags_table(request=request, num_page=request.POST["num_page"], nb_by_page=request.POST["nb_by_page"])
+
+def get_categories(request):
+
+ resp = "{" + '"":"",' + ", ".join([('"' + c.label + '":"' + c.label + '"') for c in TagCategory.objects.all()]) + "}"
+
+ return HttpResponse(json.dumps(resp), mimetype="application/json")
+
+
+#@login_required
+def update_tag_category(request):
+
+ tag_id = request.POST["id"]
+ cat = request.POST["value"]
+ tag = Tag.objects.get(id=tag_id)
+ if cat and cat != "" :
+ tag.category = TagCategory.objects.get(label=cat)
+ else :
+ tag.category = None
+ tag.save()
+ # This function is available only in all_tags_table context
+ return get_all_tags_table(request=request, num_page=request.POST["num_page"], nb_by_page=request.POST["nb_by_page"])
+
\ No newline at end of file