# HG changeset patch # User cavaliet # Date 1308049133 -7200 # Node ID 6999575970267e7970c35d8b12d669fe75540528 # Parent 8f84b9bbd22d324af00aa2ddaed1b711e0b5068e Add tag feature finished. Full page templates good placed. diff -r 8f84b9bbd22d -r 699957597026 web/hdabo/static/hdabo/js/hdabo.js --- a/web/hdabo/static/hdabo/js/hdabo.js Tue Jun 14 01:51:26 2011 +0200 +++ b/web/hdabo/static/hdabo/js/hdabo.js Tue Jun 14 12:58:53 2011 +0200 @@ -1,172 +1,232 @@ -// -*- coding: utf-8 -*- -function init_tags_events() -{ - // Up and down management for tag table lines - $(".up,.down").click(function(){ - tag_up_down(this); - }); - // Remove tag for a datasheet's list - $(".remove_tag_from_list").click(function(){ - if(confirm("Confirmez-vous la suppression du tag \"" + $(this).attr('alt') + "\" de la liste courante ?")){ - remove_tag_from_list(this); - } - }); - //activate_wp_cb - $(".activate_wp_cb").click(function(e){ - new_checked = $(this).is(':checked'); - if(new_checked){ - question = "Confirmez-vous l'activation du lien Wikipédia pour le tag \"" + $(this).attr('alt') + "\" ?"; - } else { - question = "Confirmez-vous la désactivation du lien Wikipédia pour le tag \"" + $(this).attr('alt') + "\" ?"; - } - if(confirm(question)){ - validate_wp_link(this); - } - else{ - // Since the click event is dispatched after the checked changed, we change the checked changed if confirm is false. - e.preventDefault(); // unvalidates user's click - $(this).attr('checked', !new_checked); - } - }); - - - $.editable.addInputType('autocomplete', { - element : $.editable.types.text.element, - plugin : function(settings, original) { - $('input', this).autocomplete(settings.autocomplete); - } - }); - - $(".wikipediatag").editable(modify_tag_url, { - indicator : "", - type : "autocomplete", - tooltip : "Cliquer pour éditer...", - onblur : "submit", - submitdata: {csrfmiddlewaretoken:global_csrf_token, datasheet_id:$('#datasheet_id').val()}, - callback : function(value, settings) { - $('#tag_table_container').html(value); - init_tags_events(); - }, - autocomplete : { - source: function( request, response ) { - $.ajax({ - url: "http://fr.wikipedia.org/w/api.php", - dataType: "jsonp", - data: { - action: "opensearch", - limit: "20", - namespace: "0", - format: "json", - search: request.term - }, - success: function( data ) { - response( $.map( data[1], function( item ) { - return { - label: item, - value: item - } - })); - } - }); - }, - minLength: 2, - open: function() { - $( this ).removeClass( "ui-corner-all" ).addClass( "ui-corner-top" ); - }, - close: function() { - $( this ).removeClass( "ui-corner-top" ).addClass( "ui-corner-all" ); - } - } - }); -} - -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 remove_tag_from_list(btn) -{ - var url = remove_tag_from_list_url; - var id_tag = $(btn).attr('id'); - $.ajax({ - url: url, - type: 'POST', - data: {csrfmiddlewaretoken:global_csrf_token, - datasheet_id:$('#datasheet_id').val(), - tag_id:id_tag - }, - // 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 remove_tag_from_list(btn) -{ - var url = remove_tag_from_list_url; - var id_tag = $(btn).attr('id'); - $.ajax({ - url: url, - type: 'POST', - data: {csrfmiddlewaretoken:global_csrf_token, - datasheet_id:$('#datasheet_id').val(), - tag_id:id_tag - }, - // 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 tag_up_down(arrow) -{ - if ($(arrow).is(".up")) { - mv = "u"; - } else { - mv = "d"; - } - var url = tag_up_down_url; - var id_tag = $(arrow).attr('id'); - // This indicates the position (from 0) of the tag in the list. NB : it is different from the TagSheet.order in the database. - var pos_tag = $(arrow).attr('pos'); - $.ajax({ - url: url, - type: 'POST', - data: {csrfmiddlewaretoken:global_csrf_token, - datasheet_id:$('#datasheet_id').val(), - tag_id:id_tag, - move:mv, - tag_pos:pos_tag - }, - // 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(); - } - }); +// -*- coding: utf-8 -*- +function init_tags_events() +{ + // Up and down management for tag table lines + $(".up,.down").click(function(){ + tag_up_down(this); + }); + // Remove tag for a datasheet's list + $(".remove_tag_from_list").click(function(){ + if(confirm("Confirmez-vous la suppression du tag \"" + $(this).attr('alt') + "\" de la liste courante ?")){ + remove_tag_from_list(this); + } + }); + //activate_wp_cb + $(".activate_wp_cb").click(function(e){ + new_checked = $(this).is(':checked'); + if(new_checked){ + question = "Confirmez-vous l'activation du lien Wikipédia pour le tag \"" + $(this).attr('alt') + "\" ?"; + } else { + question = "Confirmez-vous la désactivation du lien Wikipédia pour le tag \"" + $(this).attr('alt') + "\" ?"; + } + if(confirm(question)){ + validate_wp_link(this); + } + else{ + // Since the click event is dispatched after the checked changed, we change the checked changed if confirm is false. + e.preventDefault(); // unvalidates user's click + $(this).attr('checked', !new_checked); + } + }); + + $("#wp_search").autocomplete({ + source: function( request, response ) { + $.ajax({ + url: "http://fr.wikipedia.org/w/api.php", + dataType: "jsonp", + data: { + action: "opensearch", + limit: "20", + namespace: "0", + format: "json", + search: request.term + }, + success: function( data ) { + response( $.map( data[1], function( item ) { + return { + label: item, + value: item + } + })); + } + }); + }, + minLength: 2, + open: function() { + $( this ).removeClass( "ui-corner-all" ).addClass( "ui-corner-top" ); + }, + close: function() { + $( this ).removeClass( "ui-corner-top" ).addClass( "ui-corner-all" ); + $("#ok_search").show(); + } + }); + + $("#ok_search").click(function(){ + if($("#wp_search").val()!=""){ + $("#ok_search").html(""); + var url = add_tag_url; + $.ajax({ + url: url, + type: 'POST', + data: {csrfmiddlewaretoken:global_csrf_token, + datasheet_id:$('#datasheet_id').val(), + value:$("#wp_search").val() + }, + // 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(); + // And scroll to the bottom + $("html").animate({ scrollTop: $(document).height() }, 500); + }, + complete: function(){ + // We empty the input and hide the ok button + $("#wp_search").val(""); + $("#ok_search").hide(); + $("#ok_search").html("OK"); + } + }); + } + }); + + $.editable.addInputType('autocomplete', { + element : $.editable.types.text.element, + plugin : function(settings, original) { + $('input', this).autocomplete(settings.autocomplete); + } + }); + + $(".wikipediatag").editable(modify_tag_url, { + indicator : "", + type : "autocomplete", + tooltip : "Cliquer pour éditer...", + onblur : "submit", + submitdata: {csrfmiddlewaretoken:global_csrf_token, datasheet_id:$('#datasheet_id').val()}, + callback : function(value, settings) { + $('#tag_table_container').html(value); + init_tags_events(); + }, + autocomplete : { + source: function( request, response ) { + $.ajax({ + url: "http://fr.wikipedia.org/w/api.php", + dataType: "jsonp", + data: { + action: "opensearch", + limit: "20", + namespace: "0", + format: "json", + search: request.term + }, + success: function( data ) { + response( $.map( data[1], function( item ) { + return { + label: item, + value: item + } + })); + } + }); + }, + minLength: 2, + open: function() { + $( this ).removeClass( "ui-corner-all" ).addClass( "ui-corner-top" ); + }, + close: function() { + $( this ).removeClass( "ui-corner-top" ).addClass( "ui-corner-all" ); + } + } + }); +} + +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 remove_tag_from_list(btn) +{ + var url = remove_tag_from_list_url; + var id_tag = $(btn).attr('id'); + $.ajax({ + url: url, + type: 'POST', + data: {csrfmiddlewaretoken:global_csrf_token, + datasheet_id:$('#datasheet_id').val(), + tag_id:id_tag + }, + // 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 remove_tag_from_list(btn) +{ + var url = remove_tag_from_list_url; + var id_tag = $(btn).attr('id'); + $.ajax({ + url: url, + type: 'POST', + data: {csrfmiddlewaretoken:global_csrf_token, + datasheet_id:$('#datasheet_id').val(), + tag_id:id_tag + }, + // 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 tag_up_down(arrow) +{ + if ($(arrow).is(".up")) { + mv = "u"; + } else { + mv = "d"; + } + var url = tag_up_down_url; + var id_tag = $(arrow).attr('id'); + // This indicates the position (from 0) of the tag in the list. NB : it is different from the TagSheet.order in the database. + var pos_tag = $(arrow).attr('pos'); + $.ajax({ + url: url, + type: 'POST', + data: {csrfmiddlewaretoken:global_csrf_token, + datasheet_id:$('#datasheet_id').val(), + tag_id:id_tag, + move:mv, + tag_pos:pos_tag + }, + // 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(); + } + }); } \ No newline at end of file diff -r 8f84b9bbd22d -r 699957597026 web/hdabo/templates/hdabo_base.html --- a/web/hdabo/templates/hdabo_base.html Tue Jun 14 01:51:26 2011 +0200 +++ b/web/hdabo/templates/hdabo_base.html Tue Jun 14 12:58:53 2011 +0200 @@ -1,79 +1,80 @@ -{% load i18n %} -{% comment %}{% load logintag %}{% endcomment %} -{% comment %}{% load navigation %}{% endcomment %} - - - - -{% block head %} - - - - {% block title %}HDA-BO{% endblock %} - {% block js_import %} - - - - - - - {% endblock %} - - {% block css_declaration %} - - {% endblock %} - - {% block css_import %} - - - - {% endblock %} - - {% block js_declaration %} - {% endblock %} - -{% endblock %} - - -{% block body %} -
- -
-
- {% block toolbar %} -

home

- {% endblock %} -
-
- {% block content %} - {% endblock %} -
-
- -
-{% endblock %} - - +{% load i18n %} +{% comment %}{% load logintag %}{% endcomment %} +{% comment %}{% load navigation %}{% endcomment %} + + + + +{% block head %} + + + + {% block title %}HDA-BO{% endblock %} + {% block js_import %} + + + + + + + + {% endblock %} + + {% block css_declaration %} + + {% endblock %} + + {% block css_import %} + + + + {% endblock %} + + {% block js_declaration %} + {% endblock %} + +{% endblock %} + + +{% block body %} +
+ +
+
+ {% block toolbar %} +

home

+ {% endblock %} +
+
+ {% block content %} + {% endblock %} +
+
+ +
+{% endblock %} + + diff -r 8f84b9bbd22d -r 699957597026 web/hdabo/templates/list_for_orga.html --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/web/hdabo/templates/list_for_orga.html Tue Jun 14 12:58:53 2011 +0200 @@ -0,0 +1,78 @@ +{% extends "hdabo_base.html" %} + {% block title %}HDA - BO : Fiches pour {{ orga_name }}{% 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}} +

Fiche(s) pour l'organisation {{ orga_name }} : {{nb_sheets}} fiche(s)

+ {% if valid != "2" %} +
+

<<   + <   + {{displayed_index}}/{{nb_sheets}}   + >   + >>

+
+ {% endif %} + + {% for ds in datasheets %} + + {% endfor %} +
+ {% include "partial/one_sheet.html" %} +
+ {% if valid != "2" %} +
+

<<   + <   + {{displayed_index}}/{{nb_sheets}}   + >   + >>

+
+ {% endif %} + {% endblock %} diff -r 8f84b9bbd22d -r 699957597026 web/hdabo/templates/organisation_list.html --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/web/hdabo/templates/organisation_list.html Tue Jun 14 12:58:53 2011 +0200 @@ -0,0 +1,32 @@ +{% extends "hdabo_base.html" %} + {% block title %}HDA-BO : Liste des organisations{% endblock %} + + {% block content %} + {{block.super}} +

Afficher les fiches non validées pour les lieux suivants :

+ + + + + + + + {% for item in organisations %} + + + + + + + {% endfor %} +
NomFiches non validéesFiches validéesToutes les fiches
{{ item.organisation.name|default:"_" }} (lien) + {% if item.nb_unval > 0 %} + {{item.nb_unval}} + {% else %}0{% endif %} + {% if item.nb_val > 0 %} + {{item.nb_val}} + {% else %}0{% endif %} + {% if item.nb_all > 0 %} + {{item.nb_all}} + {% else %}0{% endif %}
+ {% endblock %} diff -r 8f84b9bbd22d -r 699957597026 web/hdabo/templates/partial/list_for_orga.html --- a/web/hdabo/templates/partial/list_for_orga.html Tue Jun 14 01:51:26 2011 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,77 +0,0 @@ -{% extends "hdabo_base.html" %} - {% block title %}HDA - BO : Fiches pour {{ orga_name }}{% 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}} -

Fiche(s) pour l'organisation {{ orga_name }} : {{nb_sheets}} fiche(s)

- {% if valid != "2" %} -
-

<<   - <   - {{displayed_index}}/{{nb_sheets}}   - >   - >>

-
- {% endif %} - - {% for ds in datasheets %} - - {% endfor %} -
- {% include "partial/one_sheet.html" %} -
- {% if valid != "2" %} -
-

<<   - <   - {{displayed_index}}/{{nb_sheets}}   - >   - >>

-
- {% endif %} - {% endblock %} diff -r 8f84b9bbd22d -r 699957597026 web/hdabo/templates/partial/one_sheet.html --- a/web/hdabo/templates/partial/one_sheet.html Tue Jun 14 01:51:26 2011 +0200 +++ b/web/hdabo/templates/partial/one_sheet.html Tue Jun 14 12:58:53 2011 +0200 @@ -25,6 +25,11 @@       par :       le {{ds.validation_date}} {% endif %} + {% if valid != "2" %} + Ajouter un tag : + + + {% endif %}

{% csrf_token %} diff -r 8f84b9bbd22d -r 699957597026 web/hdabo/templates/partial/organisation_list.html --- a/web/hdabo/templates/partial/organisation_list.html Tue Jun 14 01:51:26 2011 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,32 +0,0 @@ -{% extends "hdabo_base.html" %} - {% block title %}HDA-BO : Liste des organisations{% endblock %} - - {% block content %} - {{block.super}} -

Afficher les fiches non validées pour les lieux suivants :

- - - - - - - - {% for item in organisations %} - - - - - - - {% endfor %} -
NomFiches non validéesFiches validéesToutes les fiches
{{ item.organisation.name|default:"_" }} (lien) - {% if item.nb_unval > 0 %} - {{item.nb_unval}} - {% else %}0{% endif %} - {% if item.nb_val > 0 %} - {{item.nb_val}} - {% else %}0{% endif %} - {% if item.nb_all > 0 %} - {{item.nb_all}} - {% else %}0{% endif %}
- {% endblock %} diff -r 8f84b9bbd22d -r 699957597026 web/hdabo/urls.py --- a/web/hdabo/urls.py Tue Jun 14 01:51:26 2011 +0200 +++ b/web/hdabo/urls.py Tue Jun 14 12:58:53 2011 +0200 @@ -24,4 +24,5 @@ url(r'^removetagfromlist$', 'hdabo.views.remove_tag_from_list'), url(r'^validatelink$', 'hdabo.views.validate_wp_link'), url(r'^modifytag$', 'hdabo.views.modify_tag'), + url(r'^addtag$', 'hdabo.views.add_tag'), ) diff -r 8f84b9bbd22d -r 699957597026 web/hdabo/views.py --- a/web/hdabo/views.py Tue Jun 14 01:51:26 2011 +0200 +++ b/web/hdabo/views.py Tue Jun 14 12:58:53 2011 +0200 @@ -1,5 +1,7 @@ from django.conf import settings from django.contrib.auth.decorators import login_required #@UnusedImport +from django.db.models import Max +from django.http import HttpResponse from django.shortcuts import render_to_response from django.template import RequestContext from hdabo.wp_utils import query_wikipedia_title @@ -22,7 +24,7 @@ org_list.append({'organisation':orga, 'nb_all':nb_all, 'nb_val':nb_val, 'nb_unval':nb_unval}) - return render_to_response("partial/organisation_list.html", + return render_to_response("organisation_list.html", {'organisations':org_list}, context_instance=RequestContext(request)) @@ -70,7 +72,7 @@ next_index = min(nb_sheets - 1, start_index + 1); last_index = max(nb_sheets - 1, 0); - return render_to_response("partial/list_for_orga.html", + return render_to_response("list_for_orga.html", {'datasheets':datasheets, 'orga_name':orga_name, 'nb_sheets':nb_sheets, 'orga_id':orga_id, 'ordered_tags':ordered_tags, 'prev_index':prev_index, 'next_index':next_index, 'last_index':last_index, @@ -174,3 +176,37 @@ tag.save() return get_tag_table(request=request, ds_id=ds_id, valid=0) + + +#@login_required +def add_tag(request=None): + + ds_id = request.POST["datasheet_id"] + tag_label = request.POST["value"] + # We get the wikipedia references for the tag_label + site = wiki.Wiki(settings.WIKIPEDIA_API_URL) #@UndefinedVariable + new_label, status, url, pageid, response = query_wikipedia_title(site, tag_label) #@UnusedVariable + # We get or create the tag object + tag, created = Tag.objects.get_or_create(label=new_label) + # We save the datas + if new_label is not None: + tag.label = new_label + tag.original_label = new_label + if status is not None: + tag.url_status = status + if url is not None: + tag.wikipedia_url = url + tag.wikipedia_activated = True + if pageid is not None: + tag.wikipedia_pageid = pageid + tag.save() + # We put the tag at the bottom of the datasheet's tag list + # if the tag is created or if the tag is not in the list + ds = Datasheet.objects.filter(id=ds_id)[0] + list_ts = TaggedSheet.objects.filter(datasheet=ds) + if created or len(list_ts.filter(tag=tag))==0 : + new_order = list_ts.aggregate(Max('order'))['order__max'] + 1 + ts = TaggedSheet.objects.create(datasheet=ds, tag=tag, original_order=new_order, order=new_order) + ts.save() + + return get_tag_table(request=request, ds_id=ds_id, valid=0)