# HG changeset patch # User cavaliet # Date 1308068812 -7200 # Node ID ffd77b2b939fbd9e82e6b1c50e0d3138e218a3ef # Parent 142d0440c9aa73443e768200e333a1063df34a33 First step of tag list. Enhance js function for datasheet context or tag list context. diff -r 142d0440c9aa -r ffd77b2b939f web/hdabo/static/hdabo/css/style.css --- a/web/hdabo/static/hdabo/css/style.css Tue Jun 14 15:28:11 2011 +0200 +++ b/web/hdabo/static/hdabo/css/style.css Tue Jun 14 18:26:52 2011 +0200 @@ -222,11 +222,26 @@ margin-top: 2px; margin-bottom: 2px; border-bottom: 2px solid #707070; + padding-top : 0px; + padding-bottom : 0px; } -#toolbar p { +#toolbar ul{ + padding-left : 0px; + padding-right : 0px; + padding-top : 0px; + padding-bottom : 0px; + margin-left : 0px; + margin-right : 0px; margin-top: 5px; margin-bottom: 5px; } +#toolbar ul li{ + display: inline; + padding-left : 10px; + padding-right : 10px; + padding-top : 0px; + padding-bottom : 0px; +} #inner_content { padding: 5px 0px 50px 0px; diff -r 142d0440c9aa -r ffd77b2b939f web/hdabo/static/hdabo/js/hdabo.js --- a/web/hdabo/static/hdabo/js/hdabo.js Tue Jun 14 15:28:11 2011 +0200 +++ b/web/hdabo/static/hdabo/js/hdabo.js Tue Jun 14 18:26:52 2011 +0200 @@ -5,7 +5,8 @@ $(".up,.down").click(function(){ tag_up_down(this); }); - //activate_wp_cb + + // Tag simple operations : activate/unactivate wp link, reset wp info, remove wp link, remove tag from list $(".activate_wp_cb").click(function(e){ new_checked = $(this).is(':checked'); if(new_checked){ @@ -14,7 +15,8 @@ question = "Confirmez-vous la désactivation du lien Wikipédia pour le tag \"" + $(this).attr('alt') + "\" ?"; } if(confirm(question)){ - validate_wp_link(this); + //validate_wp_link(this); + update_tag(this); } else{ // Since the click event is dispatched after the checked changed, we change the checked changed if confirm is false. @@ -22,13 +24,6 @@ $(this).attr('checked', !new_checked); } }); - - // Tag simple operations : remove tag from list, reset wp info, remove wp link - $(".remove_tag_from_list").click(function(){ - if(confirm("Confirmez-vous la suppression du tag \"" + $(this).attr('alt') + "\" de la liste courante ?")){ - update_tag(this); - } - }); $(".reset_wp_info").click(function(e){ if(confirm("Confirmez-vous le rétablissement du label original de ce tag ?")){ update_tag(this); @@ -39,6 +34,11 @@ update_tag(this); } }); + $(".remove_tag_from_list").click(function(){ + if(confirm("Confirmez-vous la suppression du tag \"" + $(this).attr('alt') + "\" de la liste courante ?")){ + update_tag(this); + } + }); $("#wp_search").autocomplete({ source: function( request, response ) { @@ -89,7 +89,12 @@ type : "autocomplete", tooltip : "Cliquer pour éditer...", onblur : "submit", - submitdata: {csrfmiddlewaretoken:global_csrf_token, datasheet_id:$('#datasheet_id').val()}, + submitdata: { + csrfmiddlewaretoken:global_csrf_token, + datasheet_id:$('#datasheet_id').val(), + num_page:$('#num_page').val(), + nb_by_page:$('#nb_by_page').val() + }, callback : function(value, settings) { $('#tag_table_container').html(value); init_tags_events(); @@ -128,30 +133,9 @@ } -function validate_wp_link(cb) -{ - var url = validate_wp_link_url; - var id_tag = $(cb).attr('id'); - new_checked = $(cb).is(':checked'); - $.ajax({ - url: url, - type: 'POST', - data: {csrfmiddlewaretoken:global_csrf_token, - datasheet_id:$('#datasheet_id').val(), - tag_id:id_tag, - activated:new_checked - }, - // bug with jquery >= 1.5, "json" adds a callback so we don't specify dataType - //dataType: 'json', - success: function(msg, textStatus, XMLHttpRequest) { - $('#tag_table_container').html(msg); - init_tags_events(); - } - }); -} - function update_tag(btn) { + new_checked = false; if ($(btn).is(".remove_tag_from_list")) { var url = remove_tag_from_list_url; var id_tag = $(btn).attr('id'); @@ -159,17 +143,30 @@ else if ($(btn).is(".reset_wp_info")) { var url = reset_wp_info_url; var id_tag = $(btn).html(); + $(btn).html(""); } else if ($(btn).is(".remove_wp_link")) { var url = remove_wp_link_url; var id_tag = $(btn).attr('id'); } + else if ($(btn).is(".activate_wp_cb")) { + var url = validate_wp_link_url; + var id_tag = $(btn).attr('id'); + new_checked = $(btn).is(':checked'); + } + + // 2 cases : + // - ordered tag for one datasheet : $('#datasheet_id') is not null + // - all tags list : $('#datasheet_id') is null and $('#num_page') and $('#nb_by_page') are not null $.ajax({ url: url, type: 'POST', data: {csrfmiddlewaretoken:global_csrf_token, datasheet_id:$('#datasheet_id').val(), - tag_id:id_tag + num_page:$('#num_page').val(), + nb_by_page:$('#nb_by_page').val(), + tag_id:id_tag, + activated:new_checked }, // bug with jquery >= 1.5, "json" adds a callback so we don't specify dataType //dataType: 'json', diff -r 142d0440c9aa -r ffd77b2b939f web/hdabo/templates/all_tags.html --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/web/hdabo/templates/all_tags.html Tue Jun 14 18:26:52 2011 +0200 @@ -0,0 +1,74 @@ +{% extends "hdabo_base.html" %} + {% block title %}HDA - BO : Tous les tags{% endblock %} + + {% block js_import %} + {{block.super}} + + + {% endblock %} + + {% block js_declaration %} + {{block.super}} + {% if valid != "2" %} + + {% endif %} + {% endblock %} + + {% block css_import %} + {{block.super}} + + {% endblock %} + + {% block css_declaration %} + {{block.super}} + + {% endblock %} + + + {% block content %} + {{block.super}} +

Tags {{ current_page.start_index }} à {{ current_page.end_index }} sur {{ nb_total }}

+
+

<<   + <   + {{ num_page }}/{{ last_page }}   + >   + >>

+
+ + +
+ {% include "partial/all_tags_table.html" %} +
+
+

<<   + <   + bli/bla   + >   + >>

+
+ {% endblock %} diff -r 142d0440c9aa -r ffd77b2b939f web/hdabo/templates/hdabo_base.html --- a/web/hdabo/templates/hdabo_base.html Tue Jun 14 15:28:11 2011 +0200 +++ b/web/hdabo/templates/hdabo_base.html Tue Jun 14 18:26:52 2011 +0200 @@ -55,7 +55,8 @@
{% block toolbar %} -

home

+ {% endblock %}
diff -r 142d0440c9aa -r ffd77b2b939f web/hdabo/templates/partial/all_tags_table.html --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/web/hdabo/templates/partial/all_tags_table.html Tue Jun 14 18:26:52 2011 +0200 @@ -0,0 +1,35 @@ +{% block tag_table %} + + + + {% comment %}{% endcomment %} + + + + + + {% for tag in tags %} + + + + {% comment %}{% endcomment %} + + + + + + {% endfor %} +
idlabeloriginal_labelLien WFacetteLien W activéSupprimer
le lien W
Alias
{{tag.id}}{{tag.label}}{{tag.original_label}} + {% if tag.wikipedia_url and tag.wikipedia_url != "" %} + + {% else %} + + {% endif %}{{tag.label}}{{tag.alias}}
+{% endblock %} diff -r 142d0440c9aa -r ffd77b2b939f web/hdabo/templates/partial/one_sheet.html --- a/web/hdabo/templates/partial/one_sheet.html Tue Jun 14 15:28:11 2011 +0200 +++ b/web/hdabo/templates/partial/one_sheet.html Tue Jun 14 18:26:52 2011 +0200 @@ -26,9 +26,7 @@       le {{ds.validation_date}} {% endif %} {% if valid != "2" %} - Ajouter un tag : - OK - + Ajouter un tag : OK {% endif %}

{% csrf_token %} diff -r 142d0440c9aa -r ffd77b2b939f web/hdabo/urls.py --- a/web/hdabo/urls.py Tue Jun 14 15:28:11 2011 +0200 +++ b/web/hdabo/urls.py Tue Jun 14 18:26:52 2011 +0200 @@ -27,4 +27,7 @@ url(r'^resetwpinfo$', 'hdabo.views.reset_wikipedia_info'), url(r'^addtag$', 'hdabo.views.add_tag'), url(r'^removewplink$', 'hdabo.views.remove_wp_link'), + url(r'^alltags$', 'hdabo.views.all_tags'), + url(r'^alltags/(?P[\w-]+)$', 'hdabo.views.all_tags'), + url(r'^alltags/(?P[\w-]+)/(?P[\w-]+)/$', 'hdabo.views.all_tags'), ) diff -r 142d0440c9aa -r ffd77b2b939f web/hdabo/views.py --- a/web/hdabo/views.py Tue Jun 14 15:28:11 2011 +0200 +++ b/web/hdabo/views.py Tue Jun 14 18:26:52 2011 +0200 @@ -1,5 +1,6 @@ from django.conf import settings from django.contrib.auth.decorators import login_required #@UnusedImport +from django.core.paginator import Paginator from django.db.models import Max from django.shortcuts import render_to_response from django.template import RequestContext @@ -13,7 +14,7 @@ def home(request): # Get all organisations - orgas = Organisation.objects.all() + orgas = Organisation.objects.all().order_by('name') # Count all validated, unvalidated sheets for each organisation org_list = [] for orga in orgas : @@ -23,7 +24,6 @@ nb_unval = len(all_datasheets.filter(validated=False)) org_list.append({'organisation':orga, 'nb_all':nb_all, 'nb_val':nb_val, 'nb_unval':nb_unval}) - return render_to_response("organisation_list.html", {'organisations':org_list}, context_instance=RequestContext(request)) @@ -79,6 +79,41 @@ 'start_index':start_index, 'displayed_index':displayed_index, 'valid':valid}, context_instance=RequestContext(request)) + +#@login_required +def all_tags(request, num_page=None, nb_by_page=None): + + alltags = Tag.objects.order_by('label') + nb_total = len(alltags) + # We build the paginator for the requested list + if nb_by_page : + try: + nb_by_page = int(nb_by_page) + except : + nb_by_page = 25 + else : + nb_by_page = 25 + if num_page : + try: + num_page = int(num_page) + except : + num_page = 1 + else : + num_page = 1 + p = Paginator(alltags, nb_by_page) + current_page = p.page(num_page) + + prev_page = max(num_page - 1, 1) + next_page = min(num_page + 1, p.num_pages) + last_page = p.num_pages + + return render_to_response("all_tags.html", + {'nb_total':nb_total, 'tags':current_page.object_list, 'current_page':current_page, + 'prev_page':prev_page, 'next_page':next_page, 'last_page':last_page, + 'num_page':num_page, 'nb_by_page':nb_by_page}, + context_instance=RequestContext(request)) + + #@login_required def tag_up_down(request): ds_id = request.POST["datasheet_id"] @@ -121,6 +156,33 @@ #@login_required +def get_all_tags_table(request, num_page=None, nb_by_page=None): + + alltags = Tag.objects.order_by('label') + # We build the paginator for the requested list + if nb_by_page : + try: + nb_by_page = int(nb_by_page) + except : + nb_by_page = 25 + else : + nb_by_page = 25 + if num_page : + try: + num_page = int(num_page) + except : + num_page = 1 + else : + num_page = 1 + p = Paginator(alltags, nb_by_page) + current_page = p.page(num_page) + + return render_to_response("partial/all_tags_table.html", + {'tags':current_page.object_list}, + context_instance=RequestContext(request)) + + +#@login_required def remove_tag_from_list(request=None): ds_id = request.POST["datasheet_id"] @@ -136,8 +198,9 @@ #@login_required def validate_wp_link(request=None): - - ds_id = request.POST["datasheet_id"] + # 2 cases : + # - ordered tag for one datasheet : POST["datasheet_id"] is not null + # - all tags list : POST["datasheet_id"] is null and POST["num_page"] and POST["nb_by_page"] are not null tag_id = request.POST["tag_id"] if request.POST["activated"] != "false" : wp_activ = True @@ -148,14 +211,19 @@ tag.wikipedia_activated = wp_activ tag.save() - return get_tag_table(request=request, ds_id=ds_id, valid=0) + if u"datasheet_id" in request.POST : + return get_tag_table(request=request, ds_id=request.POST["datasheet_id"], valid=0) + else : + return get_all_tags_table(request=request, num_page=request.POST["num_page"], nb_by_page=request.POST["nb_by_page"]) + #@login_required def modify_tag(request): - + # 2 cases : + # - ordered tag for one datasheet : POST["datasheet_id"] is not null + # - all tags list : POST["datasheet_id"] is null and POST["num_page"] and POST["nb_by_page"] are not null tag_id = request.POST["id"] tag_label = request.POST["value"] - ds_id = request.POST["datasheet_id"] tag = Tag.objects.get(id=tag_id) @@ -183,14 +251,18 @@ tag.save() - return get_tag_table(request=request, ds_id=ds_id, valid=0) + if u"datasheet_id" in request.POST : + return get_tag_table(request=request, ds_id=request.POST["datasheet_id"], valid=0) + else : + return get_all_tags_table(request=request, num_page=request.POST["num_page"], nb_by_page=request.POST["nb_by_page"]) #@login_required def reset_wikipedia_info(request): - + # 2 cases : + # - ordered tag for one datasheet : POST["datasheet_id"] is not null + # - all tags list : POST["datasheet_id"] is null and POST["num_page"] and POST["nb_by_page"] are not null tag_id = request.POST["tag_id"] - ds_id = request.POST["datasheet_id"] tag = Tag.objects.get(id=tag_id) site = wiki.Wiki(settings.WIKIPEDIA_API_URL) #@UndefinedVariable @@ -199,7 +271,10 @@ process_tag(site, tag, 0) - return get_tag_table(request=request, ds_id=ds_id, valid=0) + if u"datasheet_id" in request.POST : + return get_tag_table(request=request, ds_id=request.POST["datasheet_id"], valid=0) + else : + return get_all_tags_table(request=request, num_page=request.POST["num_page"], nb_by_page=request.POST["nb_by_page"]) #@login_required @@ -242,7 +317,9 @@ #@login_required def remove_wp_link(request=None): - ds_id = request.POST["datasheet_id"] + # 2 cases : + # - ordered tag for one datasheet : POST["datasheet_id"] is not null + # - all tags list : POST["datasheet_id"] is null and POST["num_page"] and POST["nb_by_page"] are not null tag_id = request.POST["tag_id"] tag = Tag.objects.filter(id=tag_id)[0] tag.wikipedia_activated = False @@ -251,4 +328,7 @@ tag.url_status = 0; tag.save() - return get_tag_table(request=request, ds_id=ds_id, valid=0) + if u"datasheet_id" in request.POST : + return get_tag_table(request=request, ds_id=request.POST["datasheet_id"], valid=0) + else : + return get_all_tags_table(request=request, num_page=request.POST["num_page"], nb_by_page=request.POST["nb_by_page"])