# HG changeset patch # User cavaliet # Date 1308052943 -7200 # Node ID 2cc86e8db2ecf0cab50709b598200b42433411af # Parent 056c19e37eabb49f7bf791be53d61e2bc6c3d3e1 commit after merge. diff -r 056c19e37eab -r 2cc86e8db2ec web/hdabo/static/hdabo/js/hdabo.js --- a/web/hdabo/static/hdabo/js/hdabo.js Tue Jun 14 13:08:22 2011 +0200 +++ b/web/hdabo/static/hdabo/js/hdabo.js Tue Jun 14 14:02:23 2011 +0200 @@ -29,6 +29,12 @@ } }); + $(".reset_wp_info").click(function(e){ + if(confirm("Confirmez-vous le rétablissement du label original de ce tag ?")){ + reset_wp_info(this); + } + }); + $("#wp_search").autocomplete({ source: function( request, response ) { $.ajax({ @@ -229,4 +235,23 @@ init_tags_events(); } }); +} + +function reset_wp_info(cell) +{ + var tag_id = $(cell).html() + + $.ajax({ + url: reset_wp_info_url, + type: 'POST', + data: { + csrfmiddlewaretoken:global_csrf_token, + datasheet_id:$('#datasheet_id').val(), + tag_id:tag_id + }, + success: function(msg, textStatus, XMLHttpRequest) { + $('#tag_table_container').html(msg); + init_tags_events(); + } + }); } \ No newline at end of file diff -r 056c19e37eab -r 2cc86e8db2ec web/hdabo/templates/list_for_orga.html --- a/web/hdabo/templates/list_for_orga.html Tue Jun 14 13:08:22 2011 +0200 +++ b/web/hdabo/templates/list_for_orga.html Tue Jun 14 14:02:23 2011 +0200 @@ -18,6 +18,7 @@ var remove_tag_from_list_url = "{% url hdabo.views.remove_tag_from_list %}"; var validate_wp_link_url = "{% url hdabo.views.validate_wp_link %}"; var modify_tag_url = "{% url hdabo.views.modify_tag %}"; + var reset_wp_info_url = "{% url hdabo.views.reset_wikipedia_info %}"; var add_tag_url = "{% url hdabo.views.add_tag %}"; $(document).ready(function(){ diff -r 056c19e37eab -r 2cc86e8db2ec web/hdabo/templates/partial/list_for_orga.html --- a/web/hdabo/templates/partial/list_for_orga.html Tue Jun 14 13:08:22 2011 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,84 +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 056c19e37eab -r 2cc86e8db2ec web/hdabo/views.py --- a/web/hdabo/views.py Tue Jun 14 13:08:22 2011 +0200 +++ b/web/hdabo/views.py Tue Jun 14 14:02:23 2011 +0200 @@ -1,5 +1,6 @@ from django.conf import settings from django.contrib.auth.decorators import login_required #@UnusedImport +from django.db.models import Max from django.shortcuts import render_to_response from django.template import RequestContext from hdabo.management.commands.querywikipedia import process_tag @@ -23,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)) @@ -71,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, @@ -199,3 +200,38 @@ process_tag(site, tag, 0) 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) +