Improve design, add context
authorymh <ymh.work@gmail.com>
Sun, 16 Jun 2013 19:39:02 +0200
changeset 5 580fd386c4b9
parent 4 ae066d797a66
child 6 ced3c15c79df
Improve design, add context
.settings/org.eclipse.core.resources.prefs
src/core/templatetags/core_extras.py
src/jocondelab/forms.py
src/jocondelab/settings.py
src/jocondelab/static/jocondelab/css/style.css
src/jocondelab/templates/jocondelab/partial/filter.html
src/jocondelab/templates/jocondelab/partial/pagination.html
src/jocondelab/templates/jocondelab/partial/term.html
src/jocondelab/templates/jocondelab/partial/term_list_table.html
src/jocondelab/templates/jocondelab/term_edit.html
src/jocondelab/templates/jocondelab/term_list.html
src/jocondelab/urls.py
src/jocondelab/utils.py
src/jocondelab/views.py
--- a/.settings/org.eclipse.core.resources.prefs	Sun Jun 16 01:03:40 2013 +0200
+++ b/.settings/org.eclipse.core.resources.prefs	Sun Jun 16 19:39:02 2013 +0200
@@ -14,4 +14,5 @@
 encoding//src/jocondelab/management/commands/import_terms.py=utf-8
 encoding//src/jocondelab/management/utils.py=utf-8
 encoding//src/jocondelab/models.py=utf-8
+encoding//src/jocondelab/utils.py=utf-8
 encoding//src/jocondelab/views.py=utf-8
--- a/src/core/templatetags/core_extras.py	Sun Jun 16 01:03:40 2013 +0200
+++ b/src/core/templatetags/core_extras.py	Sun Jun 16 19:39:02 2013 +0200
@@ -22,11 +22,14 @@
 
 
 class AppendParamNode(template.Node):
-    def __init__(self, dict_str):
+    def __init__(self, *params):
+        
         self.dict_pairs = {}
-        for pair in dict_str.split(','):
-            pair = pair.split('=')
-            self.dict_pairs[pair[0]] = template.Variable(pair[1])
+        for dict_str in params:        
+            if dict_str:
+                for pair in dict_str.split(','):
+                    pair = pair.split('=')
+                    self.dict_pairs[pair[0]] = template.Variable(pair[1])
             
     def render(self, context):
         get = context['request'].GET.copy()
@@ -38,12 +41,12 @@
         if len(get):
             path = get.urlencode()
         
-        return path
+        return "?"+path if path else ""
 
 @register.tag()
 @easy_tag
-def append_to_param(_tag_name, dict_val):
-    return AppendParamNode(dict_val)
+def append_to_param(_tag_name, *params):
+    return AppendParamNode(*params)
 
 
 class HiddenParamFilterForm(template.Node):
--- a/src/jocondelab/forms.py	Sun Jun 16 01:03:40 2013 +0200
+++ b/src/jocondelab/forms.py	Sun Jun 16 19:39:02 2013 +0200
@@ -27,12 +27,12 @@
         return bool(int(val))
          
 class TermFilterForm(Form):
-    order_by = fields.ChoiceField(required=False, choices=(('normalized_label','label'),('uri','uri')))
-    order_dir = fields.ChoiceField(required=False, choices=(('asc','asc'), ('desc','desc')))
     thesaurus = ModelChoiceField(required=False, queryset=Thesaurus.objects.all())
     label = fields.CharField(required=False)
     link_status = fields.TypedChoiceField(required=False, empty_value=-1, coerce=int, choices=tuple([(-1,'---------')]+[(v, tr(l)) for v,l in TERM_URL_STATUS_CHOICES]))
     validated = fields.TypedChoiceField(required=False, empty_value=None, coerce=validated_to_bool, choices=(("", "---"),("1", tr("yes")), ("0", tr("no"))))
+    order_by = fields.ChoiceField(required=False, choices=(('normalized_label','label'),('uri','uri')))
+    order_dir = fields.ChoiceField(required=False, choices=(('asc','asc'), ('desc','desc')))
     
     def get_filter_qs(self, base_qs=None):
         qs = base_qs
--- a/src/jocondelab/settings.py	Sun Jun 16 01:03:40 2013 +0200
+++ b/src/jocondelab/settings.py	Sun Jun 16 19:39:02 2013 +0200
@@ -186,7 +186,8 @@
 WIKIPEDIA_VERSION_PERMALINK_TEMPLATE = "http://fr.wikipedia.org/w/index.php?oldid=%s"
 DBPEDIA_URI_TEMPLATE = "http://fr.dbpedia.org/resource/%s"
 
-TERM_LIST_PAGE_SIZE = 20 
+TERM_LIST_PAGE_SIZE = 20
+PAGINATOR_VISIBLE_RANGE = 7
 
 from .config import *  # @UnusedWildImport
 
--- a/src/jocondelab/static/jocondelab/css/style.css	Sun Jun 16 01:03:40 2013 +0200
+++ b/src/jocondelab/static/jocondelab/css/style.css	Sun Jun 16 19:39:02 2013 +0200
@@ -416,4 +416,37 @@
 
 #page_number {
 	text-align: right;
+}
+
+.term-list-label {
+	width : 500px;
+}
+
+
+#inner_content {
+    padding-left: 30px;    
+}
+
+#term-filter-field-list {
+	list-style-type: none;
+	padding-left: 10px;
+}
+
+#term-filter-field-list li
+{
+    display: inline;
+    list-style-type: none;
+    padding-right: 1px;
+}
+
+#term-filter-top-container {
+	margin-bottom: 20px;
+}
+
+#term-explorer-container {
+	float: left;
+}
+
+#term-detail-container {
+	float: right;
 }
\ No newline at end of file
--- a/src/jocondelab/templates/jocondelab/partial/filter.html	Sun Jun 16 01:03:40 2013 +0200
+++ b/src/jocondelab/templates/jocondelab/partial/filter.html	Sun Jun 16 19:39:02 2013 +0200
@@ -4,8 +4,13 @@
 <form id="term-filter-form" {% if term_filter_action %}action="{{term_filter_action}}"{% endif %}>
 {% hidden_param_filter filter_form %}
 <ul id='term-filter-field-list'>
-{{ filter_form.as_ul }}
+<li id="filter-thesaurus">{{ filter_form.thesaurus }}</li>
+<li id="filter-label">{{ filter_form.label }}</li>
+<li id="filter-link-status">{{ filter_form.link_status }}</li>
+<li id="filter-validated">{{ filter_form.validated }}</li>
+<li id="filter-order-by">{{ filter_form.order_by }}</li>
+<li id="filter-order-dir">{{ filter_form.order_dir }}</li>
+<li><input type="submit" value="{% trans 'Search' %}" /></li>
 </ul>
-<input type="submit" value="{% trans 'Search' %}" />
 </form>
 </div>
\ No newline at end of file
--- a/src/jocondelab/templates/jocondelab/partial/pagination.html	Sun Jun 16 01:03:40 2013 +0200
+++ b/src/jocondelab/templates/jocondelab/partial/pagination.html	Sun Jun 16 19:39:02 2013 +0200
@@ -1,25 +1,29 @@
 {% load i18n %}
 {% load core_extras %}
+{% with page_obj.number as current_page_nb %}
 <div class="pagination">
     {% if page_obj.has_previous %}
-        <a href="?{% append_to_param page=page_obj.previous_page_number %}{{ hashtag }}" class="prev">&lsaquo;&lsaquo; {% trans "previous" %}</a>
+        <a href="{% append_to_param page=1 %}{{ hashtag }}" class="prev">&lsaquo;&lsaquo;</a><a href="{% append_to_param page=page_obj.previous_page_number %}{{ hashtag }}" class="prev">&nbsp;{% trans "previous" %}</a>
     {% else %}
-        <span class="disabled prev">&lsaquo;&lsaquo; {% trans "previous" %}</span>
+        <span class="disabled prev">&lsaquo;&lsaquo;&nbsp;{% trans "previous" %}</span>
     {% endif %}
-    {% for page in page_obj.paginator.page_range %}
+    {% if page_obj.ellipsis_before %}...{% endif %}
+    {% for page in page_obj.visible_page_range %}
         {% if page %}
             {% ifequal page page_obj.number %}
                 <span class="current page">{{ page_obj.number }}</span>
             {% else %}
-                <a href="?{% append_to_param page=page %}{{ hashtag }}" class="page">{{ page }}</a>
+                <a href="{% append_to_param page=page %}{{ hashtag }}" class="page">{{ page }}</a>
             {% endifequal %}
         {% else %}
             ...
         {% endif %}
     {% endfor %}
+    {% if page_obj.ellipsis_after %}...{% endif %}
     {% if page_obj.has_next %}
-        <a href="?{% append_to_param page=page_obj.next_page_number %}{{ hashtag }}" class="next">{% trans "next" %} &rsaquo;&rsaquo;</a>
+        <a href="{% append_to_param page=page_obj.next_page_number %}{{ hashtag }}" class="next">{% trans "next" %}&nbsp;</a><a href="{% append_to_param page='last' %}{{ hashtag }}" class="next">&rsaquo;&rsaquo;</a>
     {% else %}
-        <span class="disabled next">{% trans "next" %} &rsaquo;&rsaquo;</span>
+        <span class="disabled next">{% trans "next" %}&nbsp;&rsaquo;&rsaquo;</span>
     {% endif %}
-</div>
\ No newline at end of file
+</div>
+{% endwith %}
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/jocondelab/templates/jocondelab/partial/term_list_table.html	Sun Jun 16 19:39:02 2013 +0200
@@ -0,0 +1,38 @@
+ {% load core_extras %}   
+    <div id="top-pagination">{% include "jocondelab/partial/pagination.html" %}</div>
+    <div id="term-list-table">
+    <table >
+        <thead>
+            <tr><th>Label</th><th>thes</th><th>wk</th><th>dbp</th><th>valid.</th></tr>
+        </thead>
+        <tbody>
+        {% for term in object_list %}
+        <tr class="{% cycle 'hdabooddline' 'hdaboevenline' %}">
+            <td class="{{term.url_status_text}} term-list-label"><a href="{% url 'term' term_id=term.id %}{% append_to_param %}">{{ term.label }}</a></td>
+            <td class="text_centered">{{ term.thesaurus.label }}</td>
+            <td class="text_centered">
+                {% if term.wikipedia_url and term.wikipedia_url != ""  %}
+                <a href="{{term.wikipedia_url}}" target="_blank"><img src="{{STATIC_URL}}jocondelab/img/arrow_right.png" ></a>
+                {% else %}
+                <a href="http://fr.wikipedia.org/w/index.php?search={{term.label}}" target="_blank"><img src="{{STATIC_URL}}jocondelab/img/wikipedia_search.png" ></a>
+                {% endif %}
+            </td>
+            <td class="text_centered">
+                {% if term.dbpedia_uri and term.dbpedia_uri != ""  %}
+                <a href="{{term.dbpedia_uri}}" target="_blank"><img src="{{STATIC_URL}}jocondelab/img/arrow_green_right.png" ></a>
+                {% else %}
+                &nbsp;
+                {% endif %}
+            </td>
+            <td class="text_centered">
+                {% if term.validated %}
+                <input type="checkbox" checked="checked" readonly="readonly" disabled="disabled"/>
+                {% else %}
+                <input type="checkbox" readonly="readonly" disabled="disabled"/>
+                {% endif %}
+            </td>
+         </tr>
+        {% endfor %}
+        </tbody>
+    </table>
+    </div>
\ No newline at end of file
--- a/src/jocondelab/templates/jocondelab/term_edit.html	Sun Jun 16 01:03:40 2013 +0200
+++ b/src/jocondelab/templates/jocondelab/term_edit.html	Sun Jun 16 19:39:02 2013 +0200
@@ -14,11 +14,19 @@
     var term_id = {{ term.id }};
     var modify_wp_link_url = "{% url 'modify_wp_link' %}";
     var remove_wp_link_url = "{% url 'remove_wp_link' %}";
-    var validate_term_url = "{% url 'validate_term' %}";    
+    var validate_term_url = "{% url 'validate_term' %}";
+    var term_list_table_url = "{% url 'term_list_table' %}";
     
     $(document).ready(function(){
         init_term_events();
+        $('#term-filter-form').submit(function(){
+            var values = $('#term-filter-form').serialize();
+            $('#term-explorer-container').load(term_list_table_url, values);
+            return false;
+        });
+        $('#term-filter-form').submit();
     });
+    
     </script>
     {% endblock %}
     
@@ -43,6 +51,13 @@
 
 
 {% block content %}
+<div id="filter-container">
+{% include "jocondelab/partial/filter.html" %}
+</div>
+<div id="term-container">
+<div id='term-explorer-container'>
+</div>
+<div id="term-detail-container">
 <div id="tags_commands" style="float:left;width: 100%" >
     <div style="float:left;"><input type="radio" name="gr_validated{{term.id}}" id="not_validated" value="not_validated" {% if not term.validated %}checked{% endif %}/>En cours
     <input type="radio" name="gr_validated{{term.id}}" id="validated" value="validated" {% if term.validated %}checked{% endif %} />Validé
@@ -52,32 +67,53 @@
     </div>
     {% csrf_token %}
 </div>
+
 <table>
     <tr>
-        <td>{{term.id}}</td>
+        <td>{% trans 'Term label' %}</td>
         <td class="{{term.url_status_text}}">{{term.label}}</td>
-        <td class="text_centered">
+    </tr>
+    <tr>
+        <td>{% trans 'Term id' %}</td>
+        <td>{{term.id}}</td>       
+    </tr>
+    <tr>
+        <td>{% trans 'Term uri' %}</td>
+        <td>{{term.uri}}</td>
+    </tr>
+    <tr>
+        <td>{% trans 'url wikipedia' %}</td>
+        <td>
             {% if term.wikipedia_url and term.wikipedia_url != ""  %}
             <a href="{{term.wikipedia_url}}" target="_blank"><img src="{{STATIC_URL}}jocondelab/img/arrow_right.png" ></a>
             {% else %}
             <a href="http://fr.wikipedia.org/w/index.php?search={{term.label}}" target="_blank"><img src="{{STATIC_URL}}jocondelab/img/wikipedia_search.png" ></a>
             {% endif %}
         </td>
-        <td class="text_centered">
+    </tr>
+    <tr>
+        <td>{% trans 'Wikipedia revision id' %}</td>
+        <td>
             {% if term.wikipedia_revision_id  %}
             <a href="{{term.wikipedia_revision_permalink}}" target="_blank"><img src="{{STATIC_URL}}jocondelab/img/clock_arrow.png" ></a>
             {% else %}
             &nbsp;
             {% endif %}
-        </td>           
-        <td class="text_centered">
+        </td>
+    </tr>
+    <tr>
+        <td>{% trans 'DBpedia url' %}</td>
+        <td>
             {% if term.dbpedia_uri and term.dbpedia_uri != ""  %}
             <a href="{{term.dbpedia_uri}}" target="_blank"><img src="{{STATIC_URL}}jocondelab/img/arrow_green_right.png" ></a>
             {% else %}
             &nbsp;
             {% endif %}
-        </td>        
-        <td class="text_centered">
+        </td>
+    </tr>
+    <tr>
+        <td>{% trans 'remove wikipedia link' %}</td>    
+        <td>
             {% if term.wikipedia_url and term.wikipedia_url != ""  %}
               {% if term.validated %}
               <img src="{{STATIC_URL}}jocondelab/img/red_cross_disabled.png" class="remove_wp_link_disabled" id="{{term.id}}" alt="{{term.label}}" />
@@ -88,17 +124,25 @@
             &nbsp;
             {% endif %}
         </td>
-        <td class="text_centered">
+    </tr>
+    <tr>
+        <td>{% trans 'edit wikipedia link' %}</td>
+        <td>
         {% if term.validated %}
         <span>{% trans "Select Wikipedia page" %} : <input type="text" name="wp_search" id="wp_search" size="35" disabled="disabled" /> <span id="ok_search_disabled" class="hand_cursor_disabled"><b>OK</b></span></span>
         {% else %}
         <span>{% trans "Select Wikipedia page" %} : <input type="text" name="wp_search" id="wp_search" size="35" /> <span id="ok_search" class="hand_cursor"><b>OK</b></span></span>
         {% endif %}
         </td>
-        <td class="text_centered">
+    </tr>
+    <tr>
+        <td>{% trans 'Recherche joconde' %}</td>
+        <td>
         <a href='http://www.culture.gouv.fr/public/mistral/joconde_fr?FIELD_1={{term.thesaurus.label}}&VALUE_1={{term.label|urlencode:""}}&ACTION=CHERCHER' target="_blank">Recherche joconde</a>
         </td>
    </tr>
 </table>
+</div>
+</div>
 
 {% endblock %}
\ No newline at end of file
--- a/src/jocondelab/templates/jocondelab/term_list.html	Sun Jun 16 01:03:40 2013 +0200
+++ b/src/jocondelab/templates/jocondelab/term_list.html	Sun Jun 16 19:39:02 2013 +0200
@@ -4,13 +4,38 @@
     <div id="term-filter-top-container">{% include "jocondelab/partial/filter.html" %}</div>
     <div id="top-pagination">{% include "jocondelab/partial/pagination.html" %}</div>
     <div id="term-list-table">
-    <table>
+    <table >
         <thead>
-            <tr><th>Label</th><th>thesaurus</th><th>uri</th></tr>
+            <tr><th>Label</th><th>thesaurus</th><th>wikipedia</th><th>dbpedia</th><th>valid.</th></tr>
         </thead>
         <tbody>
         {% for term in object_list %}
-            <tr><td><a href="{% url 'term' term_id=term.id %}">{{ term.label }}</a></td><td>{{ term.thesaurus.label }}</td><td>{{ term.uri }}</td></tr>
+        <tr class="{% cycle 'hdabooddline' 'hdaboevenline' %}">
+            <td class="{{term.url_status_text}} term-list-label"><a href="{% url 'term' term_id=term.id %}">{{ term.label }}</a></td>
+            <td class="text_centered">{{ term.thesaurus.label }}</td>            
+            <td class="text_centered">
+                {% if term.wikipedia_url and term.wikipedia_url != ""  %}
+                <a href="{{term.wikipedia_url}}" target="_blank"><img src="{{STATIC_URL}}jocondelab/img/arrow_right.png" ></a>
+                {% else %}
+                <a href="http://fr.wikipedia.org/w/index.php?search={{term.label}}" target="_blank"><img src="{{STATIC_URL}}jocondelab/img/wikipedia_search.png" ></a>
+                {% endif %}
+            </td>
+            <td class="text_centered">
+                {% if term.dbpedia_uri and term.dbpedia_uri != ""  %}
+                <a href="{{term.dbpedia_uri}}" target="_blank"><img src="{{STATIC_URL}}jocondelab/img/arrow_green_right.png" ></a>
+                {% else %}
+                &nbsp;
+                {% endif %}
+            </td>
+            <td class="text_centered">
+                {% if term.validated %}
+                <input type="checkbox" checked="checked" readonly="readonly" disabled="disabled"/>
+                {% else %}
+                <input type="checkbox" readonly="readonly" disabled="disabled"/>
+                {% endif %}
+            </td>
+                    
+         </tr>
         {% endfor %}
         </tbody>
     </table>
--- a/src/jocondelab/urls.py	Sun Jun 16 01:03:40 2013 +0200
+++ b/src/jocondelab/urls.py	Sun Jun 16 19:39:02 2013 +0200
@@ -3,6 +3,7 @@
 from django.contrib import admin
 from django.contrib.auth.decorators import login_required
 from django.contrib.auth import urls as auth_url
+from jocondelab.views import TermListTableView
 
 admin.autodiscover()
 
@@ -11,6 +12,7 @@
     url(r'^logout/$', 'django.contrib.auth.views.logout_then_login', name='joconde_logout'),
     url(r'^admin/', include(admin.site.urls)),
     url(r'^$', login_required(TermListView.as_view()), name='home'),
+    url(r'^bo/term/list/table$', login_required(TermListTableView.as_view()), name='term_list_table'),
     url(r'^bo/term/(?P<term_id>\d+)/$', login_required(TermEditView.as_view()), name='term'),
     url(r'^bo/term/modify-wp/$', login_required(TermModifyWpLink.as_view()), name='modify_wp_link'),
     url(r'^bo/term/remove-wp/$', login_required(TermRemoveWpLink.as_view()), name='remove_wp_link'),
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/jocondelab/utils.py	Sun Jun 16 19:39:02 2013 +0200
@@ -0,0 +1,57 @@
+# -*- coding: utf-8 -*-
+'''
+Created on Jun 16, 2013
+
+@author: ymh
+'''
+
+from django.conf import settings
+from django.core.paginator import Paginator, Page, PageNotAnInteger, EmptyPage
+import logging
+
+logger = logging.getLogger(__name__)
+
+
+class JocondePaginator(Paginator):
+
+    def validate_number(self, number):
+        "Validates the given 1-based page number."
+        try:
+            number = int(number)
+        except (TypeError, ValueError):
+            raise PageNotAnInteger('That page number is not an integer')
+        if number < 1:
+            return 1
+        if number > self.num_pages:
+            if number == 1 and self.allow_empty_first_page:
+                return 1
+            elif self.num_pages > 0: 
+                return self.num_pages
+            else:
+                raise EmptyPage('That page contains no results')
+        return number
+
+    
+    def page(self, number):        
+        page = super(JocondePaginator, self).page(number)
+        return JocondePage(page.object_list, page.number, self)
+
+
+class JocondePage(Page):
+    
+    def __get_start_range(self):
+        return max(1,self.number-settings.PAGINATOR_VISIBLE_RANGE/2)
+    
+    def __get_end_range(self):
+        return min(self.paginator.num_pages, self.number+settings.PAGINATOR_VISIBLE_RANGE/2) + 1
+    
+    def visible_page_range(self):
+        start = self.__get_start_range()
+        end = self.__get_end_range()
+        return range(start , end) 
+    
+    def ellipsis_before(self):
+        return self.__get_start_range() > 1
+    
+    def ellipsis_after(self):
+        return self.__get_end_range() < self.paginator.num_pages
--- a/src/jocondelab/views.py	Sun Jun 16 01:03:40 2013 +0200
+++ b/src/jocondelab/views.py	Sun Jun 16 19:39:02 2013 +0200
@@ -7,6 +7,7 @@
 
 from .forms import (ModifyWpLinkForm, ValidateTermForm, RemoveWpLinkForm, 
     TermFilterForm)
+from .utils import JocondePaginator
 from core.models import Term, TERM_URL_STATUS_DICT
 from core.wp_utils import process_term as wp_process_term
 from django.conf import settings
@@ -20,8 +21,9 @@
     
     model = Term
     paginate_by = settings.TERM_LIST_PAGE_SIZE
+    paginator_class = JocondePaginator
     template_name = "jocondelab/term_list.html"
-    form_class = TermFilterForm
+    filter_form_class = TermFilterForm
     
     def get_filter_form(self):
         initial = { 'order_by':'label',
@@ -30,7 +32,7 @@
                     'label': None,
                     'link_status': -1,
                     'validated': None}
-        return self.form_class(self.request.GET, initial=initial, auto_id=True)
+        return self.filter_form_class(self.request.GET, initial=initial, auto_id=True)
     
     def get_context_data(self, **kwargs):
         context = ListView.get_context_data(self, **kwargs)
@@ -45,12 +47,34 @@
         else:
             return None
 
+class TermListTableView(TermListView):
+    
+    template_name = "jocondelab/partial/term_list_table.html"
+    
+    
+
 class TermEditView(DetailView):
     
     queryset = Term.objects.select_related()
     pk_url_kwarg = "term_id"
     context_object_name = "term"
     template_name = "jocondelab/term_edit.html"
+    filter_form_class = TermFilterForm
+    
+    def get_filter_form(self):
+        initial = { 'order_by':'label',
+                    'order_dir': 'asc',
+                    'thesaurus': None,
+                    'label': None,
+                    'link_status': -1,
+                    'validated': None}
+        return self.filter_form_class(self.request.GET, initial=initial, auto_id=True)
+
+    
+    def get_context_data(self, **kwargs):        
+        context = DetailView.get_context_data(self, **kwargs)
+        context['filter_form'] = self.get_filter_form()
+        return context