Changeset 2523

Show
Ignore:
Timestamp:
02/04/10 08:43:14 (6 weeks ago)
Author:
JensDiemer
Message:

Limit the blog articles on summery page with django paginator. ticket:345

Location:
branches/0.9/pylucid_project/pylucid_plugins/blog
Files:
3 modified

Legend:

Unmodified
Added
Removed
  • branches/0.9/pylucid_project/pylucid_plugins/blog/preference_forms.py

    r2349 r2523  
    22 
    33from django import forms 
    4 from django.utils.translation import ugettext as _ 
     4from django.utils.translation import ugettext_lazy as _ 
    55 
    66from pylucid_project.utils.site_utils import SitePreselectPreference 
     
    1010 
    1111class BlogPrefForm(SitePreselectPreference, DBPreferencesBaseForm): 
     12    max_anonym_count = forms.IntegerField( 
     13        initial=10, min_value=1, 
     14        help_text=_( 
     15            "The maximal numbers of blog entries, displayed together" 
     16            " for anonymous users" 
     17        ), 
     18    ) 
     19    max_user_count = forms.IntegerField( 
     20        initial=30, min_value=1, 
     21        help_text=_( 
     22            "The maximal numbers of blog entries, displayed together" 
     23            " for logged in PyLucid users." 
     24        ), 
     25    ) 
    1226    class Meta: 
    1327        app_label = 'blog' 
  • branches/0.9/pylucid_project/pylucid_plugins/blog/templates/blog/summary.html

    r2443 r2523  
    77 
    88{% if not entries %}no blog entry exists{% endif %} 
    9 {% for entry in entries %} 
     9{% for entry in entries.object_list %} 
    1010<fieldset class="entry"> 
    1111    <legend class="headline"> 
     
    3434{% endfor %} 
    3535</div> 
     36 
     37<div class="pagination"> 
     38    {% if entries.has_previous %} 
     39        <a href="?page={{ entries.previous_page_number }}" title="{% trans "&lt; goto previous page" %}" class="previous">&#x22D8; {% trans "previous" %}</a> 
     40    {% endif %} 
     41     
     42    <span class="pagelist"> 
     43    {% for entry in entries.paginator.page_range %} 
     44        {% if entry == entries.number %} 
     45            <strong>{{ entry }}</strong> 
     46        {% else %} 
     47            <a href="?page={{ entry }}">{{ entry }}</a> 
     48        {% endif %} 
     49    {% endfor %} 
     50    </span> 
     51  
     52    {% if entries.has_next %} 
     53        <a href="?page={{ entries.next_page_number }}" title="{% trans "goto next page &gt;" %}" class="next">{% trans "next" %} &#x22D9;</a> 
     54    {% endif %} 
     55</div> 
    3656{% endblock content %} 
  • branches/0.9/pylucid_project/pylucid_plugins/blog/views.py

    r2449 r2523  
    3939from django.views.decorators.csrf import csrf_protect 
    4040from django.contrib.comments.views.comments import post_comment 
     41from django.core.paginator import Paginator, InvalidPage, EmptyPage 
    4142 
    42 from pylucid.decorators import render_to 
     43from pylucid_project.apps.pylucid.decorators import render_to 
    4344 
    44 from blog.models import BlogEntry 
     45from pylucid_project.pylucid_plugins.blog.models import BlogEntry 
     46from pylucid_project.pylucid_plugins.blog.preference_forms import BlogPrefForm 
    4547 
    4648# from django-tagging 
     
    8789    Display summary list with all blog entries. 
    8890    """ 
     91    # Get all blog entries, that the current user can see 
    8992    queryset = BlogEntry.on_site 
    9093    queryset = _filter_blog_entries(request, queryset) 
     94 
     95    # Get number of entries allowed by the users see on a page.  
     96    pref_form = BlogPrefForm() 
     97    preferences = pref_form.get_preferences() 
     98    if request.user.is_anonymous(): 
     99        max_count = preferences.get("max_anonym_count", 10) 
     100    else: 
     101        max_count = preferences.get("max_user_count", 30) 
     102 
     103    # Show max_count entries per page 
     104    paginator = Paginator(queryset, max_count) 
     105 
     106    # Make sure page request is an int. If not, deliver first page. 
     107    try: 
     108        page = int(request.GET.get('page', '1')) 
     109    except ValueError: 
     110        page = 1 
     111 
     112    # If page request (9999) is out of range, deliver last page of results. 
     113    try: 
     114        entries = paginator.page(page) 
     115    except (EmptyPage, InvalidPage): 
     116        entries = paginator.page(paginator.num_pages) 
     117 
    91118    context = { 
    92         "entries": queryset, 
     119        "entries": entries, 
    93120        "tag_cloud": _get_tag_cloud(request), 
    94121        "CSS_PLUGIN_CLASS_NAME": settings.PYLUCID.CSS_PLUGIN_CLASS_NAME,