--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/web/hdabo/templates/generic_sheet.html Fri Jul 08 01:41:50 2011 +0200
@@ -0,0 +1,82 @@
+{% extends "hdabo_base.html" %}
+ {% block title %}HDA - BO : Fiches pour {{ orga_name }}{% endblock %}
+
+ {% block js_import %}
+ {{block.super}}
+ <script type="text/javascript" src="{{STATIC_URL}}hdabo/js/jquery.tablednd_0_5.js"></script>
+ <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 modify_tag_url = "{% url hdabo.views.modify_tag_datasheet %}";
+ 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 %}";
+ var validate_datasheet_url = "{% url hdabo.views.validate_datasheet %}";
+ var update_tag_alias_url = "{% url hdabo.views.update_tag_alias %}";
+ var update_tag_category_url = "{% url hdabo.views.update_tag_category %}";
+ var categories_list = '{{categories|safe}}';
+
+ $(document).ready(function(){
+ init_tags_events();
+ init_datasheet_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>
+ {% if tag %} Fiche(s) concernées par le tag <b>{{ tag.label }}</b>
+ {% else %} Fiche(s) {% if valid %}<b>validées</b>{% else %}<b>non validées</b>{% endif %} pour l'organisation <b>{{ orga_name }}</b>
+ {% endif %} : {{nb_sheets}} fiche(s)</p>
+ <div id="count_nav_top">
+ <p><a href="{% url hdabo.views.display_datasheet ds_id=zero_id %}?{% if tag %}tag={{tag.id}}{% endif %}&nb_sheets={{nb_sheets}}&index=0"><<</a>
+ <a href="{% url hdabo.views.display_datasheet ds_id=prev_id%}?{% if tag %}tag={{tag.id}}{% endif %}&nb_sheets={{nb_sheets}}&index={{prev_index}}"><</a>
+ {{displayed_index}}/{{nb_sheets}}
+ <a href="{% url hdabo.views.display_datasheet ds_id=next_id%}?{% if tag %}tag={{tag.id}}{% endif %}&nb_sheets={{nb_sheets}}&index={{next_index}}">></a>
+ <a href="{% url hdabo.views.display_datasheet ds_id=last_id%}?{% if tag %}tag={{tag.id}}{% endif %}&nb_sheets={{nb_sheets}}&index={{last_index}}">>></a></p>
+ </div>
+ <table>
+ <tr class="imageline {% cycle 'hdabosimpleevenline' 'hdabosimpleoddline' %}"><td>
+ {% include "partial/one_sheet.html" %}
+ </td></tr>
+ </table>
+ <div id="count_nav_bottom">
+ <p><a href="{% url hdabo.views.display_datasheet ds_id=zero_id %}?{% if tag %}tag={{tag.id}}{% endif %}&nb_sheets={{nb_sheets}}&index=0"><<</a>
+ <a href="{% url hdabo.views.display_datasheet ds_id=prev_id%}?{% if tag %}tag={{tag.id}}{% endif %}&nb_sheets={{nb_sheets}}&index={{prev_index}}"><</a>
+ {{displayed_index}}/{{nb_sheets}}
+ <a href="{% url hdabo.views.display_datasheet ds_id=next_id%}?{% if tag %}tag={{tag.id}}{% endif %}&nb_sheets={{nb_sheets}}&index={{next_index}}">></a>
+ <a href="{% url hdabo.views.display_datasheet ds_id=last_id%}?{% if tag %}tag={{tag.id}}{% endif %}&nb_sheets={{nb_sheets}}&index={{last_index}}">>></a></p>
+ </div>
+ {% endblock %}
--- a/web/hdabo/templates/hdabo_base.html Fri Jul 08 01:39:02 2011 +0200
+++ b/web/hdabo/templates/hdabo_base.html Fri Jul 08 01:41:50 2011 +0200
@@ -66,7 +66,7 @@
<div id="inner_content">
{% block content %}
{% endblock %}
- </div>
+ </div>
</div>
<div id="footer" class="span-24 last">
{% block footer %}
--- a/web/hdabo/templates/organisation_list.html Fri Jul 08 01:39:02 2011 +0200
+++ b/web/hdabo/templates/organisation_list.html Fri Jul 08 01:41:50 2011 +0200
@@ -16,11 +16,11 @@
<td class="contenttitle">{{ item.organisation.name|default:"_" }} (<a href="{{item.organisation.website}}" target="_blank">lien</a>)</td>
<td class="contenttitle">
{% if item.nb_unval > 0 %}
- <a class="contenttitlelink" href="{% url hdabo.views.list_for_orga orga_id=item.organisation.id valid=0 %}">{{item.nb_unval}}</a>
+ <a class="contenttitlelink" href="{% url hdabo.views.display_datasheet ds_id=item.first_id_unval %}">{{item.nb_unval}}</a>
{% else %}0{% endif %}</td>
<td class="contenttitle">
{% if item.nb_val > 0 %}
- <a class="contenttitlelink" href="{% url hdabo.views.list_for_orga orga_id=item.organisation.id valid=1 %}">{{item.nb_val}}</a>
+ <a class="contenttitlelink" href="{% url hdabo.views.display_datasheet ds_id=item.first_id_val %}">{{item.nb_val}}</a>
{% else %}0{% endif %}</td>
<td class="contenttitle">
{% if item.nb_all > 0 %}
--- a/web/hdabo/templates/partial/all_tags_table.html Fri Jul 08 01:39:02 2011 +0200
+++ b/web/hdabo/templates/partial/all_tags_table.html Fri Jul 08 01:41:50 2011 +0200
@@ -32,7 +32,13 @@
<td class="tag_category" id="{{tag.id}}">{% if tag.category %}{{ tag.category }}{% 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 class="tag_alias" id="{{tag.id}}" >{% if tag.alias %}{{tag.alias}}{% endif %}</td>
- <td class="text_centered">{{tag.num_ds}}</td>
+ <td class="text_centered">
+ {% if tag.num_ds > 0 %}
+ <a href="{% url hdabo.views.display_datasheet %}?tag={{tag.id}}" >{{tag.num_ds}}</a>
+ {% else %}
+ {{tag.num_ds}}
+ {% endif %}
+ </td>
<td class="text_centered">{{tag.popularity}}</td></tr>
{% endfor %}
</table>
--- a/web/hdabo/templates/partial/one_sheet.html Fri Jul 08 01:39:02 2011 +0200
+++ b/web/hdabo/templates/partial/one_sheet.html Fri Jul 08 01:41:50 2011 +0200
@@ -22,14 +22,14 @@
<p><input type="radio" name="gr_validated{{ds.hda_id}}" id="not_validated" value="not_validated" {% if not ds.validated %}checked{% endif %} {% if valid == "2" %}disabled{% endif %} />En cours
<input type="radio" name="gr_validated{{ds.hda_id}}" id="validated" value="validated" {% if ds.validated %}checked{% endif %} {% if valid == "2" %}disabled{% endif %} />Validé
{% if ds.validated %}
- par {{ds.validator.username}} le {{ds.validation_date|date:"d/m/Y"}}
+ par {{ds.validator.username}} le {{ds.validation_date|date:"d/m/Y"}}
{% endif %}
{% if valid != "2" %}
<span style="float:right;">Ajouter un tag : <input type="text" name="wp_search" id="wp_search" size="60" /> <span id="ok_search" class="hand_cursor"><b>OK</b></span></span>
{% endif %}
</p>
{% csrf_token %}
- <input type="hidden" name="datasheet_id" value="{{ds.id}}" id="datasheet_id" />
+ <input type="hidden" name="datasheet_id" value="{{ds.hda_id}}" id="datasheet_id" />
<div id="tag_table_container">
{% include "partial/tag_table.html" %}
</div>
--- a/web/hdabo/urls.py Fri Jul 08 01:39:02 2011 +0200
+++ b/web/hdabo/urls.py Fri Jul 08 01:41:50 2011 +0200
@@ -24,6 +24,8 @@
url(r'^list/(?P<orga_id>[\w-]+)/(?P<valid>[\w-]+)/$', 'hdabo.views.list_for_orga', name='list_for_orga'),
url(r'^list/(?P<orga_id>[\w-]+)/(?P<valid>[\w-]+)/(?P<start_index>[\w-]+)/$', 'hdabo.views.list_for_orga', name='list_for_orga'),
url(r'^list/(?P<orga_id>[\w-]+)/(?P<valid>[\w-]+)/(?P<start_index>[\w-]+)/(?P<length>[\w-]+)/$', 'hdabo.views.list_for_orga', name='list_for_orga'),
+ url(r'^data$', 'hdabo.views.display_datasheet', name='display_datasheet'),
+ url(r'^data/(?P<ds_id>[\w-]+)$', 'hdabo.views.display_datasheet', name='display_datasheet'),
url(r'^tagupdown$', 'hdabo.views.tag_up_down'),
url(r'^removetagfromlist$', 'hdabo.views.remove_tag_from_list'),
url(r'^modifytag$', 'hdabo.views.modify_tag'),
--- a/web/hdabo/views.py Fri Jul 08 01:39:02 2011 +0200
+++ b/web/hdabo/views.py Fri Jul 08 01:41:50 2011 +0200
@@ -4,7 +4,7 @@
from django.contrib.auth.decorators import login_required #@UnusedImport
from django.core.paginator import Paginator
from django.db import connection
-from django.db.models import Max, Count
+from django.db.models import Max, Count, Min
from django.http import HttpResponseBadRequest
from django.shortcuts import render_to_response, redirect
from django.template import RequestContext
@@ -28,14 +28,21 @@
org_list = []
all_ds_mapping = dict([(res['organisation'],res['nb_all']) for res in Datasheet.objects.values("organisation").annotate(nb_all=Count("organisation"))])
- validated_ds_mapping = dict([(res['organisation'],res['nb_val']) for res in Datasheet.objects.filter(validated=True).values("organisation").annotate(nb_val=Count("organisation"))])
- unvalidated_ds_mapping = dict([(res['organisation'],res['nb_unval']) for res in Datasheet.objects.filter(validated=False).values("organisation").annotate(nb_unval=Count("organisation"))])
-
+ validated_ds_mapping = dict([(res['organisation'],[res['nb_val'],res['first_id_val']]) for res in Datasheet.objects.filter(validated=True).values("organisation").annotate(nb_val=Count("organisation")).annotate(first_id_val=Min("id"))])
+ unvalidated_ds_mapping = dict([(res['organisation'],[res['nb_unval'],res['first_id_unval']]) for res in Datasheet.objects.filter(validated=False).values("organisation").annotate(nb_unval=Count("organisation")).annotate(first_id_unval=Min("id"))])
+ # We get the hda_id from the id
+ val_hda_ids = dict([(res.id,res.hda_id) for res in Datasheet.objects.filter(id__in=[v[1] for v in validated_ds_mapping.values()]).only("id","hda_id")])
+ unval_hda_ids = dict([(res.id,res.hda_id) for res in Datasheet.objects.filter(id__in=[v[1] for v in unvalidated_ds_mapping.values()]).only("id","hda_id")])
+
for orga in orgas :
nb_all = all_ds_mapping.get(orga.id,0)
- nb_val = validated_ds_mapping.get(orga.id,0)
- nb_unval = unvalidated_ds_mapping.get(orga.id,0)
- org_list.append({'organisation':orga, 'nb_all':nb_all, 'nb_val':nb_val, 'nb_unval':nb_unval})
+ duo_val = validated_ds_mapping.get(orga.id,[0,None])
+ nb_val = duo_val[0]
+ first_id_val = val_hda_ids.get(duo_val[1], None)
+ duo_unval = unvalidated_ds_mapping.get(orga.id,[0,None])
+ nb_unval = duo_unval[0]
+ first_id_unval = unval_hda_ids.get(duo_unval[1], None)
+ org_list.append({'organisation':orga, 'nb_all':nb_all, 'nb_val':nb_val, 'first_id_val':first_id_val, 'nb_unval':nb_unval, 'first_id_unval':first_id_unval})
return render_to_response("organisation_list.html",
{'organisations':org_list},
@@ -43,6 +50,86 @@
@login_required
+def display_datasheet(request, ds_id=None):
+
+ if ds_id :
+ ds = Datasheet.objects.get(hda_id=ds_id)
+
+ # In this function the context is given by the get parameters.
+ if "index" in request.GET :
+ try:
+ index = int(request.GET["index"])
+ except :
+ index = 0
+ else :
+ index = 0
+ if "nb_sheets" in request.GET :
+ try:
+ nb_sheets = int(request.GET["nb_sheets"])
+ except :
+ nb_sheets = None
+ else :
+ nb_sheets = None
+ # If there is tag parameter, it means that we display all the ds tagged by one particular tag
+ tag = None
+ if "tag" in request.GET :
+ tag = Tag.objects.get(id=int(request.GET["tag"]))
+ datasheets_qs = Datasheet.objects.filter(tags__in=[tag]).order_by("organisation__name","original_creation_date").select_related("format")
+ # If tag is set and if ds_id is None, it means that we have to display the first ds
+ if not ds_id :
+ index = 0
+ ds = datasheets_qs[0]
+ else :
+ # The current list depends on the ds's validation state
+ datasheets_qs = Datasheet.objects.filter(organisation=ds.organisation).filter(validated=ds.validated).order_by("id").select_related("format")
+ # We calculate the number of sheets if necessary
+ if not nb_sheets :
+ nb_sheets = datasheets_qs.count()
+
+ # We get only the prev/current/next sheets
+ if nb_sheets > 1 :
+ if index == 0 :
+ select_qs = datasheets_qs[:2]
+ prev_index = 0
+ prev_id = select_qs[0].hda_id
+ next_index = 1
+ next_id = select_qs[1].hda_id
+ elif index == (nb_sheets - 1) :
+ select_qs = datasheets_qs[nb_sheets-2:]
+ prev_index = nb_sheets - 2
+ prev_id = select_qs[0].hda_id
+ next_index = nb_sheets - 1
+ next_id = select_qs[1].hda_id
+ else :
+ select_qs = datasheets_qs[index-1:index+2]
+ prev_index = index - 1
+ prev_id = select_qs[0].hda_id
+ next_index = index + 1
+ next_id = select_qs[2].hda_id
+ else :
+ prev_index = next_index = 0
+ prev_id = next_id = datasheets_qs[0].hda_id
+
+ # We get the ORDERED tags if we display one sheet (case valid = 0 and 1)
+ ordered_tags = TaggedSheet.objects.filter(datasheet=ds).select_related("tag").order_by('order')
+
+ displayed_index = index + 1;
+ zero_id = datasheets_qs[0].hda_id
+ last_index = max(nb_sheets - 1, 0)
+ last_id = datasheets_qs[last_index].hda_id
+
+ return render_to_response("generic_sheet.html",
+ {'ds':ds, 'orga_name':ds.organisation.name,
+ 'nb_sheets':nb_sheets, 'ordered_tags':ordered_tags,
+ 'zero_id':zero_id, 'prev_index':prev_index, 'prev_id':prev_id,
+ 'next_index':next_index, 'next_id':next_id,
+ 'last_index':last_index, 'last_id':last_id,
+ 'displayed_index':displayed_index, 'tag':tag, 'valid':ds.validated,
+ 'categories':json.dumps(get_categories())},
+ context_instance=RequestContext(request))
+
+
+@login_required
def list_for_orga(request, orga_id=None, valid=None, start_index=None):
orga = Organisation.objects.get(id=orga_id)
@@ -144,7 +231,7 @@
new_order = int(request.POST["new_order"]) - 1
old_order = int(request.POST["old_order"]) - 1
# 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'))
+ ordered_tags = list(TaggedSheet.objects.filter(datasheet=Datasheet.objects.get(hda_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]
@@ -163,7 +250,7 @@
ts = ordered_tags[i]
ts.order = ts.order + 1
ts.save()
- ds = Datasheet.objects.get(id=ds_id)
+ ds = Datasheet.objects.get(hda_id=ds_id)
ds.manual_order = True
ds.save()
@@ -173,7 +260,7 @@
@login_required
def get_tag_table(request=None, ds_id=None, valid=None):
- ordered_tags = TaggedSheet.objects.filter(datasheet=Datasheet.objects.filter(id=ds_id)[0]).order_by('order')
+ ordered_tags = TaggedSheet.objects.filter(datasheet=Datasheet.objects.filter(hda_id=ds_id)[0]).order_by('order')
return render_to_response("partial/tag_table.html",
{'ordered_tags':ordered_tags, 'valid':valid},
@@ -232,12 +319,12 @@
ds_id = request.POST["datasheet_id"]
tag_id = request.POST["tag_id"]
# First we get the datasheet's TaggedSheets
- ds_tags = TaggedSheet.objects.filter(datasheet=Datasheet.objects.filter(id=ds_id)[0])
+ ds_tags = TaggedSheet.objects.filter(datasheet=Datasheet.objects.filter(hda_id=ds_id)[0])
# We get the current TaggedSheet and we delete it
ts = ds_tags.filter(tag=Tag.objects.filter(id=tag_id))[0]
ts.delete()
- ds = Datasheet.objects.get(id=ds_id)
+ ds = Datasheet.objects.get(hda_id=ds_id)
ds.manual_order = True
ds.save()
@@ -286,7 +373,7 @@
tag = Tag.objects.get(id=tag_id)
- ds = Datasheet.objects.get(id=ds_id)
+ ds = Datasheet.objects.get(hda_id=ds_id)
if tag.label != tag_label:
@@ -344,7 +431,7 @@
ds_id = request.POST["datasheet_id"]
tag_label = request.POST["value"]
- ds = Datasheet.objects.get(id=ds_id)
+ ds = Datasheet.objects.get(hda_id=ds_id)
if tag_label.lower() in [t.label.lower() for t in ds.tags.all()]:
return HttpResponseBadRequest(json.dumps({'error': 'duplicate_tag', 'message': u"Le tag %s existe déjà pour cette fiche." % (tag_label)}), mimetype="application/json")
@@ -396,22 +483,17 @@
else:
user = None
- ds = Datasheet.objects.get(id=ds_id)
+ ds = Datasheet.objects.get(hda_id=ds_id)
if valid :
ds.validate(user)
else :
ds.unvalidate()
ds.save()
+
# If there are still some unvalidated/validated ds for the ds's orga, we display the first one
same_organisation_ds = Datasheet.objects.filter(organisation=ds.organisation).filter(validated=not valid)
- if valid :
- # We ask to display the unvalidated ds
- valid_req = 0
- else :
- # We ask to display the validated ds
- valid_req = 1
if len(same_organisation_ds) > 0 :
- return redirect('list_for_orga', orga_id=ds.organisation.id, valid=valid_req)
+ return redirect('display_datasheet', ds_id=same_organisation_ds[0].hda_id)
else :
return redirect('home')