First step of tag list. Enhance js function for datasheet context or tag list context.
--- 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;
--- 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("<img src='"+static_url+"hdabo/img/indicator.gif'>");
}
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',
--- /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}}
+ <script type="text/javascript" src="{{STATIC_URL}}hdabo/js/jquery-ui.min.js"></script>
+ <script type="text/javascript" src="{{STATIC_URL}}hdabo/js/jquery.jeditable.js"></script>
+ {% endblock %}
+
+ {% block js_declaration %}
+ {{block.super}}
+ {% if valid != "2" %}
+ <script type="text/javascript">
+
+ var global_csrf_token = "{{ csrf_token }}";
+ var static_url = "{{STATIC_URL}}";
+ var tag_up_down_url = "{% url hdabo.views.tag_up_down %}";
+ 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 %}";
+ var remove_wp_link_url = "{% url hdabo.views.remove_wp_link %}";
+
+ $(document).ready(function(){
+ init_tags_events();
+ });
+ </script>
+ {% endif %}
+ {% endblock %}
+
+ {% block css_import %}
+ {{block.super}}
+ <link rel="stylesheet" href="{{STATIC_URL}}hdabo/css/smoothness/jquery-ui-1.8.13.custom.css" type="text/css"/>
+ {% endblock %}
+
+ {% block css_declaration %}
+ {{block.super}}
+ <style type="text/css">
+ .ui-autocomplete {
+ max-height: 100px;
+ overflow-y: auto;
+ /* prevent horizontal scrollbar */
+ overflow-x: hidden;
+ /* add padding to account for vertical scrollbar */
+ padding-right: 20px;
+ }
+ </style>
+ {% endblock %}
+
+
+ {% block content %}
+ {{block.super}}
+ <p>Tags {{ current_page.start_index }} à {{ current_page.end_index }} sur {{ nb_total }}</p>
+ <div id="count_nav_top">
+ <p><a href="{% url hdabo.views.all_tags num_page=1, nb_by_page=nb_by_page %}"><<</a>
+ <a href="{% url hdabo.views.all_tags num_page=prev_page, nb_by_page=nb_by_page %}"><</a>
+ {{ num_page }}/{{ last_page }}
+ <a href="{% url hdabo.views.all_tags num_page=next_page, nb_by_page=nb_by_page %}">></a>
+ <a href="{% url hdabo.views.all_tags num_page=last_page, nb_by_page=nb_by_page %}">>></a></p>
+ </div>
+ <input type="hidden" name="num_page" value="{{num_page}}" id="num_page" />
+ <input type="hidden" name="nb_by_page" value="{{nb_by_page}}" id="nb_by_page" />
+ <div id="tag_table_container">
+ {% include "partial/all_tags_table.html" %}
+ </div>
+ <div id="count_nav_bottom">
+ <p><a href="{% url hdabo.views.all_tags %}"><<</a>
+ <a href="{% url hdabo.views.all_tags %}"><</a>
+ bli/bla
+ <a href="{% url hdabo.views.all_tags %}">></a>
+ <a href="{% url hdabo.views.all_tags %}">>></a></p>
+ </div>
+ {% endblock %}
--- 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 @@
<div id="content" class="span-24 last">
<div id="toolbar">
{% block toolbar %}
- <p><a href="{% url hdabo.views.home %}">home</a></p>
+ <ul><li><a href="{% url hdabo.views.home %}">Home</a></li>
+ <li><a href="{% url hdabo.views.all_tags %}">Tous les tags</a></li></ul>
{% endblock %}
</div>
<div id="inner_content">
--- /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 %}
+ <table id="all_tags_table">
+ <tr><th>id</th>
+ <th>label</th>
+ {% comment %}<th>original_label</th>{% endcomment %}
+ <th class="text_centered">Lien W</th>
+ <th>Facette</th>
+ <th class="large_25 text_centered">Lien W activé</th>
+ <th class="large_25 text_centered">Supprimer<br/>le lien W</th>
+ <th>Alias</th></tr>
+ {% for tag in tags %}
+ <tr class="imageline {% cycle 'hdabooddline' 'hdaboevenline' %}">
+ <td class="reset_wp_info">{{tag.id}}</td>
+ <td class="{{tag.url_status_text}} wikipediatag" id="{{tag.id}}" >{{tag.label}}</td>
+ {% comment %}<td>{{tag.original_label}}</td>{% endcomment %}
+ <td class="text_centered">
+ {% if tag.wikipedia_url and tag.wikipedia_url != "" %}
+ <a href="{{tag.wikipedia_url}}" target="_blank"><img src="{{STATIC_URL}}hdabo/img/arrow_right.png" ></a>
+ {% else %}
+ <a href="http://fr.wikipedia.org/w/index.php?search={{tag.label}}" target="_blank"><img src="{{STATIC_URL}}hdabo/img/wikipedia_search.png" ></a>
+ {% endif %}</td>
+ <td><select name="facette">
+ <option value="" selected></option>
+ <option value="datation">Datation</option>
+ <option value="localisation">Localisation</option>
+ <option value="createur">Créateur</option>
+ <option value="ecole">Ecole/Mouvement</option>
+ <option value="discipline">Discipline artistique</option>
+ </select></td>
+ <td class="text_centered"><input type="checkbox" class="activate_wp_cb" id="{{tag.id}}" alt="{{tag.label}}" {% if tag.wikipedia_activated %}checked{% endif %} /></td>
+ <td class="text_centered"><img src="{{STATIC_URL}}hdabo/img/red_cross.png" class="remove_wp_link" id="{{tag.id}}" alt="{{tag.label}}" /></td>
+ <td>{{tag.alias}}</td></tr>
+ {% endfor %}
+ </table>
+{% endblock %}
--- 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" %}
- <span style="float:right;">Ajouter un tag : <input type="text" name="wp_search" id="wp_search" />
- <span id="ok_search" /><b>OK</b></span>
- </span>
+ <span style="float:right;">Ajouter un tag : <input type="text" name="wp_search" id="wp_search" /><span id="ok_search" /><b>OK</b></span></span>
{% endif %}
</p>
{% csrf_token %}
--- 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<num_page>[\w-]+)$', 'hdabo.views.all_tags'),
+ url(r'^alltags/(?P<num_page>[\w-]+)/(?P<nb_by_page>[\w-]+)/$', 'hdabo.views.all_tags'),
)
--- 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"])