]> git.openstreetmap.org Git - osqa.git/commitdiff
Some more changes in node management.
authorhernani <hernani@0cfe37f9-358a-4d5e-be75-b63607b5c754>
Fri, 10 Sep 2010 11:16:14 +0000 (11:16 +0000)
committerhernani <hernani@0cfe37f9-358a-4d5e-be75-b63607b5c754>
Fri, 10 Sep 2010 11:16:14 +0000 (11:16 +0000)
Fixed filter reset after action.
Added inverse sortings.
Added node summary.
Removed sort by title.
Made descending sort by addedt_at as the default sort.

git-svn-id: http://svn.osqa.net/svnroot/osqa/trunk@586 0cfe37f9-358a-4d5e-be75-b63607b5c754

forum/settings/__init__.py
forum/skins/default/templates/osqaadmin/nodeman.html
forum/utils/pagination.py
forum/views/admin.py

index ae09261d2b2fe488a637e857767fbd8201a61595..9b0cbed037702599ddd57605e223b820a896a94f 100644 (file)
@@ -13,6 +13,7 @@ MAINTAINANCE_MODE = Setting('MAINTAINANCE_MODE', None)
 
 SETTINGS_PACK = Setting('SETTINGS_PACK', "default")
 DJSTYLE_ADMIN_INTERFACE = Setting('DJSTYLE_ADMIN_INTERFACE', True)
+NODE_MAN_FILTERS = Setting('NODE_MAN_FILTERS', [])
 
 APP_URL = djsettings.APP_URL
 FORUM_SCRIPT_ALIAS = djsettings.FORUM_SCRIPT_ALIAS
index 174d8bf71f313d085a3139e0d8b8f2ddc4ab6499..18d3a470386634cd512cf253b78d3a129dd61815 100644 (file)
                     $form.submit();
                 }
             });
-            
+
+            $('#filter-name-box').one('focus', function() {
+                $(this).val('');
+                $(this).css('color', 'black');
+            });
+
+
+            $('#save-filter-button').click(function() {
+                var name =  $('#filter-name-box').val();
+                $.ajax({type:'POST', url: window.location, data: {filtername: name}, success: function() {
+                    $('#pre-filter-container').append('<li><a href="#">' + name  +'</a></li>');
+                }});
+                return false;
+            });
         });
     </script>
     <style>
                     {{ filter_form.text_in }}
                 </div>
             </div>
+            <input type="hidden" name="sort" value="{{ nodes.paginator.current_sort }}" />
             <div style="display: none;" id="author-filter-container">
                 {% for u in authors %}
                 <input name="authors" type="hidden" value="{{ u.id }}" />
                 <small>{% trans "Click on the cross next to a tag name to remove it from the filter." %}</small>
             {% endif %}
             <input type="text" size="20" autocomplete="off" id="tag-selector" />
+
+            {% comment %}<h3>{% trans "Pre defined" %}</h3>
+            {% if not settings.NODE_MAN_FILTERS %}
+                <small>{% trans "There are no saved filters. Click bellow to add." %}</small>
+            {% endif %}
+            <ul id="pre-filter-container">
+                {% for uri, name in settings.NODE_MAN_FILTERS %}
+                <li><a href="{% url admin_tools "nodeman" %}{{ uri }}">{{ name }}</a></li>
+                {% endfor %}
+            </ul>
+            <input type="text" size="20" id="filter-name-box" style="color: #AAA;" value="{% trans "Filter name..." %}" />
+            <button name="add-filter" value="0" title="{% trans "Click to save the current filter" %}" id="save-filter-button" class="button">{% trans "Save" %}</button>
+            {% endcomment %}
             {% comment %}<h3>{% trans "Show" %}</h3>
             <form action="" method="get">
                 <div>{{ show_form.show }}</div>
             <table id="result_list" cellspacing="0">
                 <thead>
                     <tr>
+                        {% declare %}
+                            current_sort = nodes.paginator.current_sort
+                            added_at = current_sort == "added_at" and "descending" or (current_sort == "added_at_asc" and "ascending" or "")
+                            score = current_sort == "score" and "descending" or (current_sort == "score_asc" and "ascending" or "")
+                            act_at = current_sort == "act_at" and "descending" or (current_sort == "act_at_asc" and "ascending" or "")
+
+                            added_at_link = current_sort == "added_at" and nodes.paginator.added_at_asc_sort_link or nodes.paginator.added_at_sort_link
+                            score_link = current_sort == "score" and nodes.paginator.score_asc_sort_link or nodes.paginator.score_sort_link
+                            act_at_link = current_sort == "act_at" and nodes.paginator.act_at_asc_sort_link or nodes.paginator.act_at_sort_link
+                        {% enddeclare %}
                         {% spaceless %}
                         <th class="action-checkbox-column">
                             <input type="checkbox" id="action-toggle" style="display: inline;" />
                         {% ifequal filter_form.node_type.data "all" %}
                             <th>{% trans "Type" %}</th>
                         {% endifequal %}
-                        <th class="sorted{% ifequal nodes.paginator.current_sort "title" %} ascending{% endifequal %}">
-                            <a href="{{ nodes.paginator.title_sort_link }}">{% trans "Title" %}</a>
-                        </th>
+                        <th>{% trans "Summary" %}</th>
+                        <th>{% trans "State" %}</th>
                         <th>{% trans "Author" %}</th>
-                        <th class="sorted{% ifequal nodes.paginator.current_sort "added_at" %} ascending{% endifequal %}">
-                            <a href="{{ nodes.paginator.added_at_sort_link }}">{% trans "Added at" %}</a>
+                        <th class="sorted {{ added_at }}">
+                            <a href="{{ added_at_link }}">{% trans "Added at" %}</a>
                         </th>
-                        <th class="sorted{% ifequal nodes.paginator.current_sort "score" %} ascending{% endifequal %}">
-                            <a href="{{ nodes.paginator.score_sort_link }}">{% trans "Score" %}</a>
+                        <th class="sorted {{ score }}">
+                            <a href="{{ score_link }}">{% trans "Score" %}</a>
                         </th>
                         <th>{% trans "Last acivity by" %}</th>
-                        <th class="sorted{% ifequal nodes.paginator.current_sort "act_at" %} ascending{% endifequal %}">
-                            <a href="{{ nodes.paginator.act_at_sort_link }}">{% trans "Last activity at" %}</a>
+                        <th class="sorted {{ act_at }}">
+                            <a href="{{ act_at_link }}">{% trans "Last activity at" %}</a>
                         </th>
                         <th>{% trans "Tags" %}</th>
-                        <th>{% trans "State" %}</th>
                         {% endspaceless %}
                     </tr>
                 </thead>
                         {% ifequal filter_form.node_type.data "all" %}
                             <th>{{ node.friendly_name }}</th>
                         {% endifequal %}
-                        <td><a href="{{ node.get_absolute_url }}" title="{{ node.summary }}" target="_blank">{{ node.headline }}</a></td>
+                        <td>
+                            <a href="{{ node.get_absolute_url }}" target="_blank">{{ node.headline }}</a><br />
+                            {{ node.summary }}
+                        </td>
+                        <td>{{ node.state_list|join:", " }}</td>
                         <td><a href="{{ node.author.get_absolute_url  }}">{{ node.author.username }}</a></td>
                         <td>{% diff_date node.added_at %}</td>
                         <td>{{ node.score }}</td>
                                 {% else %}{{ t.name }}{% endif %}
                             {% endfor %}
                         </td>
-                        <td>{{ node.state_list|join:", " }}</td>
                     </tr>
                 {% endfor %}
                 </tbody>
index 4dda6647924689d318eb7a568cdee20e3197f4f0..c36ad2fb35cacc104597306d8ed4d20c2c52d50d 100644 (file)
@@ -4,11 +4,21 @@ from django import template
 from django.core.paginator import Paginator, EmptyPage
 from django.utils.translation import ugettext as _
 from django.http import Http404
+from django.utils.http import urlquote
 from django.utils.safestring import mark_safe
 from django.utils.html import strip_tags
 
 import logging
 
+def generate_uri(querydict, exclude=None):
+    all = []
+
+    for k, l in querydict.iterlists():
+        if (not exclude) or (not k in exclude):
+            all += ["%s=%s" % (k, urlquote(v)) for v in l]
+        
+    return "&".join(all)
+
 class SortBase(object):
     def __init__(self, label, description=''):
         self.label = label
@@ -189,10 +199,10 @@ def _paginated(request, objects, context):
         base_path = context.base_path
     else:
         base_path = request.path
-        get_params = ["%s=%s" % (k, v) for k, v in request.GET.items() if not k in (context.PAGE, context.PAGESIZE, context.SORT)]
+        get_params = generate_uri(request.GET, (context.PAGE, context.PAGESIZE, context.SORT))
 
         if get_params:
-            base_path += "?" + "&".join(get_params)
+            base_path += "?" + get_params
 
     url_joiner = "?" in base_path and "&" or "?"
 
index b131d8fea11cd92c808a34375613b1559c56e7ee..4ed85925ac8e5b8132415a5859d070cfe0541b66 100644 (file)
@@ -410,14 +410,26 @@ def create_user(request):
 class NodeManagementPaginatorContext(pagination.PaginatorContext):
     def __init__(self, id='QUESTIONS_LIST', prefix='', default_pagesize=100):
         super (NodeManagementPaginatorContext, self).__init__(id, sort_methods=(
-            (_('title'), pagination.SimpleSort(_('title'), '-title', "")),
             (_('added_at'), pagination.SimpleSort(_('added_at'), '-added_at', "")),
+            (_('added_at_asc'), pagination.SimpleSort(_('added_at_asc'), 'added_at', "")),
             (_('score'), pagination.SimpleSort(_('score'), '-score', "")),
+            (_('score_asc'), pagination.SimpleSort(_('score_asc'), 'score', "")),
             (_('act_at'), pagination.SimpleSort(_('act_at'), '-last_activity_at', "")),
-        ), pagesizes=(default_pagesize,), default_pagesize=default_pagesize, prefix=prefix)
+            (_('act_at_asc'), pagination.SimpleSort(_('act_at_asc'), 'last_activity_at', "")),
+        ), pagesizes=(default_pagesize,), force_sort='added_at', default_pagesize=default_pagesize, prefix=prefix)
 
 @admin_tools_page(_("nodeman"), _("Node management"))
 def node_management(request):
+    if request.is_ajax():
+        if request.POST and request.POST.get('filtername', None) and request.GET:
+            params = pagination.generate_uri(request.GET, ('page',))
+            current_filters = settings.NODE_MAN_FILTERS.value
+            current_filters.add((request.POST['filtername'], params))
+            settings.NODE_MAN_FILTERS.set_value(current_filters)
+            return HttpResponse('OK')
+
+        return HttpResponse('ERROR')
+
     if request.POST:
         selected_nodes = request.POST.getlist('_selected_node')
 
@@ -454,7 +466,9 @@ def node_management(request):
                 message = _("All selected nodes deleted")
 
             request.user.message_set.create(message=message)
-            return HttpResponseRedirect(reverse("admin_tools", kwargs={'name': 'nodeman'}))
+
+            params = pagination.generate_uri(request.GET, ('page',))
+            return HttpResponseRedirect(reverse("admin_tools", kwargs={'name': 'nodeman'}) + "?" + params)
 
 
     nodes = Node.objects.all()
@@ -517,5 +531,3 @@ def node_management(request):
 
 
 
-
-