add prev and next buttons
authorymh <ymh.work@gmail.com>
Fri, 28 Jun 2013 16:12:24 +0200
changeset 51 8890db197b37
parent 50 ed568fc9c0c2
child 52 a17dd7b33e36
add prev and next buttons
src/jocondelab/forms.py
src/jocondelab/locale/en/LC_MESSAGES/django.mo
src/jocondelab/locale/en/LC_MESSAGES/django.po
src/jocondelab/locale/fr/LC_MESSAGES/django.mo
src/jocondelab/locale/fr/LC_MESSAGES/django.po
src/jocondelab/static/jocondelab/css/style.css
src/jocondelab/static/jocondelab/js/jocondelab.js
src/jocondelab/templates/jocondelab/partial/term_list_table.html
src/jocondelab/templates/jocondelab/term_edit.html
src/jocondelab/views.py
--- a/src/jocondelab/forms.py	Thu Jun 27 22:32:48 2013 +0200
+++ b/src/jocondelab/forms.py	Fri Jun 28 16:12:24 2013 +0200
@@ -67,6 +67,10 @@
         order_dir = self.cleaned_data.get('order_dir', 'asc') or 'asc'
         if order_dir == 'desc':
             order_by = "-"+order_by
-        qs = qs.order_by(order_by)
+        if order_by == "normalized_label" or order_by == "label":
+            order_by = [order_by, 'nb_notice', 'id']
+        else:
+            order_by = [order_by, 'normalized_label', 'id']
+        qs = qs.order_by(*order_by)
         
         return qs
\ No newline at end of file
Binary file src/jocondelab/locale/en/LC_MESSAGES/django.mo has changed
--- a/src/jocondelab/locale/en/LC_MESSAGES/django.po	Thu Jun 27 22:32:48 2013 +0200
+++ b/src/jocondelab/locale/en/LC_MESSAGES/django.po	Fri Jun 28 16:12:24 2013 +0200
@@ -7,7 +7,7 @@
 msgstr ""
 "Project-Id-Version: PACKAGE VERSION\n"
 "Report-Msgid-Bugs-To: \n"
-"POT-Creation-Date: 2013-06-26 16:18+0200\n"
+"POT-Creation-Date: 2013-06-28 16:08+0200\n"
 "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
 "Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
 "Language-Team: LANGUAGE <LL@li.org>\n"
@@ -24,7 +24,7 @@
 msgid "thesaurus"
 msgstr "thesaurus"
 
-#: forms.py:39 forms.py:42 templates/jocondelab/term_edit.html:72
+#: forms.py:39 forms.py:42 templates/jocondelab/term_edit.html:80
 msgid "label"
 msgstr "label"
 
@@ -68,35 +68,45 @@
 msgid "French"
 msgstr "French"
 
-#: templates/jocondelab/term_edit.html:76
+#: templates/jocondelab/term_edit.html:73
+msgid "prev"
+msgstr "prev"
+
+#: templates/jocondelab/term_edit.html:74
+#: templates/jocondelab/partial/pagination.html:27
+#: templates/jocondelab/partial/pagination.html:29
+msgid "next"
+msgstr "next"
+
+#: templates/jocondelab/term_edit.html:84
 msgid "alternative labels"
 msgstr "alternative labels"
 
-#: templates/jocondelab/term_edit.html:86
+#: templates/jocondelab/term_edit.html:94
 msgid "id"
 msgstr "id"
 
-#: templates/jocondelab/term_edit.html:90
+#: templates/jocondelab/term_edit.html:98
 msgid "uri"
 msgstr "uri"
 
-#: templates/jocondelab/term_edit.html:94
+#: templates/jocondelab/term_edit.html:102
 msgid "info wikipedia"
 msgstr "Wikipedia info"
 
-#: templates/jocondelab/term_edit.html:103
+#: templates/jocondelab/term_edit.html:111
 msgid "Créer page WK"
 msgstr "Create WK page"
 
-#: templates/jocondelab/term_edit.html:103
+#: templates/jocondelab/term_edit.html:111
 msgid "Need wikipedia article"
 msgstr "Need wikipedia article"
 
-#: templates/jocondelab/term_edit.html:134
+#: templates/jocondelab/term_edit.html:142
 msgid "Rech. joconde"
 msgstr "Joconde search"
 
-#: templates/jocondelab/term_edit.html:140
+#: templates/jocondelab/term_edit.html:148
 msgid "Edition wk"
 msgstr "WK Edition"
 
@@ -131,11 +141,6 @@
 msgid "previous"
 msgstr "previous"
 
-#: templates/jocondelab/partial/pagination.html:27
-#: templates/jocondelab/partial/pagination.html:29
-msgid "next"
-msgstr "next"
-
 #: templates/registration/login.html:6
 msgid "Sorry, that's not a valid username or password."
 msgstr "Sorry, that's not a valid username or password."
Binary file src/jocondelab/locale/fr/LC_MESSAGES/django.mo has changed
--- a/src/jocondelab/locale/fr/LC_MESSAGES/django.po	Thu Jun 27 22:32:48 2013 +0200
+++ b/src/jocondelab/locale/fr/LC_MESSAGES/django.po	Fri Jun 28 16:12:24 2013 +0200
@@ -7,7 +7,7 @@
 msgstr ""
 "Project-Id-Version: PACKAGE VERSION\n"
 "Report-Msgid-Bugs-To: \n"
-"POT-Creation-Date: 2013-06-26 16:18+0200\n"
+"POT-Creation-Date: 2013-06-28 16:08+0200\n"
 "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
 "Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
 "Language-Team: LANGUAGE <LL@li.org>\n"
@@ -25,7 +25,7 @@
 msgid "thesaurus"
 msgstr "thésaurus"
 
-#: forms.py:39 forms.py:42 templates/jocondelab/term_edit.html:72
+#: forms.py:39 forms.py:42 templates/jocondelab/term_edit.html:80
 msgid "label"
 msgstr "label"
 
@@ -69,35 +69,45 @@
 msgid "French"
 msgstr "Français"
 
-#: templates/jocondelab/term_edit.html:76
+#: templates/jocondelab/term_edit.html:73
+msgid "prev"
+msgstr "préc."
+
+#: templates/jocondelab/term_edit.html:74
+#: templates/jocondelab/partial/pagination.html:27
+#: templates/jocondelab/partial/pagination.html:29
+msgid "next"
+msgstr "suiv."
+
+#: templates/jocondelab/term_edit.html:84
 msgid "alternative labels"
 msgstr "Autres labels"
 
-#: templates/jocondelab/term_edit.html:86
+#: templates/jocondelab/term_edit.html:94
 msgid "id"
 msgstr "id"
 
-#: templates/jocondelab/term_edit.html:90
+#: templates/jocondelab/term_edit.html:98
 msgid "uri"
 msgstr "uri"
 
-#: templates/jocondelab/term_edit.html:94
+#: templates/jocondelab/term_edit.html:102
 msgid "info wikipedia"
 msgstr "info wikipedia"
 
-#: templates/jocondelab/term_edit.html:103
+#: templates/jocondelab/term_edit.html:111
 msgid "Créer page WK"
 msgstr "Créer page WK"
 
-#: templates/jocondelab/term_edit.html:103
+#: templates/jocondelab/term_edit.html:111
 msgid "Need wikipedia article"
 msgstr "Besoin article Wikipedia"
 
-#: templates/jocondelab/term_edit.html:134
+#: templates/jocondelab/term_edit.html:142
 msgid "Rech. joconde"
 msgstr "Rech. Joconde"
 
-#: templates/jocondelab/term_edit.html:140
+#: templates/jocondelab/term_edit.html:148
 msgid "Edition wk"
 msgstr "Edition wk"
 
@@ -132,11 +142,6 @@
 msgid "previous"
 msgstr "préc."
 
-#: templates/jocondelab/partial/pagination.html:27
-#: templates/jocondelab/partial/pagination.html:29
-msgid "next"
-msgstr "suiv."
-
 #: templates/registration/login.html:6
 msgid "Sorry, that's not a valid username or password."
 msgstr ""
--- a/src/jocondelab/static/jocondelab/css/style.css	Thu Jun 27 22:32:48 2013 +0200
+++ b/src/jocondelab/static/jocondelab/css/style.css	Fri Jun 28 16:12:24 2013 +0200
@@ -535,4 +535,20 @@
 	max-height: 60px;
 	margin: 5px 2px 2px 0px;
 	padding-right: 5px;
+}
+
+#prev-next-prev-link {
+	float: left;
+}
+
+#prev-next-next-link {
+    float: right;
+}
+
+#prev-next-clear {
+	clear: both; 
+}
+
+#prev-next {
+	height: 25px;
 }
\ No newline at end of file
--- a/src/jocondelab/static/jocondelab/js/jocondelab.js	Thu Jun 27 22:32:48 2013 +0200
+++ b/src/jocondelab/static/jocondelab/js/jocondelab.js	Fri Jun 28 16:12:24 2013 +0200
@@ -10,7 +10,6 @@
     });
     
     $(".wikipedia_edition").click(function(e) {
-        console.log(term_wikipedia_edition_url,$(this),$(this).is(':checked'));
         $.post(term_wikipedia_edition_url,
             {
                 csrfmiddlewaretoken:global_csrf_token, 
@@ -88,7 +87,6 @@
                 },
                 dataType: "json",
                 success: function(data) {
-                    console.log(data);
                     res = data.results.bindings.length>0?data.results.bindings[0]:{y:"",l:"http://fr.wikipedia.org/"+page_name,t:""};
                     var item = {
                         abstract: res.y?res.y.value:"",
@@ -135,7 +133,6 @@
     // Validate sheet management : the radiobutton name has is "'gr_validated' + datasheet.hda_id"
     $("input[type='radio'][name='gr_validated']").click(function(e){
         e.preventDefault();
-        console.log(e);
         val = $("input[type='radio'][name='gr_validated']:checked").val();
         if(val === 'True') {
             msg = gettext("Confirmez-vous la validation de ce terme ?");            
@@ -210,21 +207,23 @@
     $('#term-filter-form').submit(function(){
         var values = $('#term-filter-form').serialize();
         $('#term-explorer-container').load(term_list_table_url, values, function() {
-            $('#term-list-table #term-'+term_id).addClass('currenttermline');
+            init_edit_page();
         });
         return false;
     });
 }
 
-function init_edit_page(page) {
-    var values = $('#term-filter-form').serialize();
-    // add page
-    if(typeof(page) !== "undefined" && page) { 
-        values += "&page="+page;
-    }
-    $('#term-explorer-container').load(term_list_table_url, values, function() {
-        $('#term-list-table #term-'+term_id).addClass('currenttermline');
+function init_edit_page() {
+    $('#term-list-table #term-'+term_id).addClass('currenttermline');
+
+    $('.pagination a').click(function(e) {
+        e.preventDefault();
+        console.log(this);
+        var values = this.href.slice(window.location.href.indexOf('?') + 1) 
+        $('#term-explorer-container').load(term_list_table_url, values, function() {
+            init_edit_page();
+        });
+        return false;
     });
-
 }
 
--- a/src/jocondelab/templates/jocondelab/partial/term_list_table.html	Thu Jun 27 22:32:48 2013 +0200
+++ b/src/jocondelab/templates/jocondelab/partial/term_list_table.html	Fri Jun 28 16:12:24 2013 +0200
@@ -1,4 +1,4 @@
- {% load core_extras %}   
+ {% load core_extras %}
     <div id="top-pagination">{% include "jocondelab/partial/pagination.html" %}</div>
     <div id="term-list-table-div">
     <table id="term-list-table">
--- a/src/jocondelab/templates/jocondelab/term_edit.html	Thu Jun 27 22:32:48 2013 +0200
+++ b/src/jocondelab/templates/jocondelab/term_edit.html	Fri Jun 28 16:12:24 2013 +0200
@@ -1,5 +1,6 @@
 {% extends "jocondelab/base.html" %}
 {% load i18n %}
+{% load core_extras %}
     {% block js_import %}
     {{block.super}}
     <script type="text/javascript" src="{{STATIC_URL}}jocondelab/lib/jquery-ui.min.js"></script>
@@ -22,7 +23,7 @@
     $(document).ready(function(){
         init_term_events();
         init_filter_events();
-        init_edit_page('{{request.GET.page}}');
+        init_edit_page();
     });
     
     </script>
@@ -56,6 +57,7 @@
 </div>
 <div id="term-container">
 <div id='term-explorer-container'>
+{% include "jocondelab/partial/term_list_table.html" %}
 </div>
 <div id="term-detail-container">
 <div id="tags_commands">
@@ -67,6 +69,11 @@
     </div>
     {% csrf_token %}
 </div>
+<div id="prev-next">
+    {% if prev_id %}<span id="prev-next-prev-link"><a href="{% url 'term' term_id=prev_id %}{% append_to_param page=prev_page %}"><img alt="{% trans 'prev' %}" src="{{STATIC_URL}}jocondelab/img/prev.gif" /></a></span>{% endif %}
+    {% if next_id %}<span id="prev-next-next-link"><a href="{% url 'term' term_id=next_id %}{% append_to_param page=next_page %}"><img alt="{% trans 'next' %}" src="{{STATIC_URL}}jocondelab/img/next.gif" /></a></span>{% endif %}
+    <span id="prev-next-clear"/>
+</div>
 
 <table id="term-table">
     <tr>
--- a/src/jocondelab/views.py	Thu Jun 27 22:32:48 2013 +0200
+++ b/src/jocondelab/views.py	Fri Jun 28 16:12:24 2013 +0200
@@ -18,6 +18,7 @@
 from jocondelab.forms import WikipediaEditionForm, LinkSemanticLevelForm
 import logging
 import urllib
+from django.views.generic.list import MultipleObjectMixin
 
 logger = logging.getLogger(__name__)
 
@@ -57,13 +58,32 @@
     
     
 
-class TermEditView(DetailView):
+class TermEditView(DetailView, MultipleObjectMixin):
     
     queryset = Term.objects.select_related()
     pk_url_kwarg = "term_id"
     context_object_name = "term"
     template_name = "jocondelab/term_edit.html"
     filter_form_class = TermFilterForm
+    model = Term
+    paginate_by = settings.TERM_LIST_PAGE_SIZE
+    paginator_class = JocondePaginator
+
+    def get_object(self, queryset=None):
+        
+        if queryset is None:
+            queryset = self.queryset 
+        
+        return DetailView.get_object(self, queryset)
+
+    def get_queryset(self):
+        qs = self.queryset._clone()
+        filter_form = self.get_filter_form()
+        if filter_form.is_valid():
+            return filter_form.get_filter_qs(qs)
+        else:
+            return None
+
     
     def get_filter_form(self):
         initial = { 'order_by':'label',
@@ -76,7 +96,15 @@
 
     
     def get_context_data(self, **kwargs):        
+        
+        self.object_list = self.get_queryset()
+        if kwargs is None :
+            kwargs = {}
+        kwargs['object_list'] = self.object_list         
+
+        # Beware: because of multiple inheritance this call MultipleObjectMixin.get_context_data(self, **context)
         context = DetailView.get_context_data(self, **kwargs)
+                 
         context['filter_form'] = self.get_filter_form()
         context['link_semantic_level_choice'] = TERM_WK_LINK_SEMANTIC_LEVEL_CHOICES
         
@@ -100,7 +128,41 @@
         context['encoded_term_label_query_parameter'] = urllib. urlencode({
                 'FIELD_%d' % field_index: field_name.encode('latin1'),
                 'VALUE_%d' % field_index: encoded_label}).replace('+','%20')
-        return context
+                
+        #prev_id, nex_id, prev_page, next_page
+        page = context['page_obj']
+        
+        prev_id = None
+        prev_page = 0
+        next_id = None
+        next_page = 0
+        
+        
+        object_list_ids = [obj.id for obj in list(page.object_list)]
+        current_index = object_list_ids.index(self.object.id)
+
+        if current_index > 0:
+            prev_id = object_list_ids[current_index-1]
+            prev_page = page.number
+        elif page.has_previous():
+            prev_page = page.previous_page_number()
+            prev_id = page.paginator.object_list[page.start_index() - 2].id
+
+        if current_index < (len(page)-1):
+            next_id = object_list_ids[current_index+1]
+            next_page = page.number
+        elif page.has_next():
+            next_page = page.next_page_number()
+            next_id = page.paginator.object_list[page.end_index()].id
+
+        context.update({
+            'prev_id': prev_id,
+            'prev_page': prev_page,
+            'next_id': next_id,
+            'next_page': next_page
+        })
+
+        return context