diff --git a/blog/models.py b/blog/models.py index ba56b64..63970c6 100644 --- a/blog/models.py +++ b/blog/models.py @@ -4,6 +4,8 @@ from django.db import models from django.utils import timezone from tinymce.models import HTMLField from taggit.managers import TaggableManager +from taggit.models import Tag +from django.db.models import Count, Max, Min class Post(models.Model): author = models.ForeignKey('auth.User') @@ -22,3 +24,16 @@ class Post(models.Model): def __unicode__(self): return self.title + +def font_size(self): + min_font = 12 + max_font = 28 + v = Tag.objects.all().annotate(c = Count('post')).filter(c__gt = 0).aggregate(Min('c'), Max('c')) + max_tag, min_tag = v["c__max"], v["c__min"] + step = (max_font - min_font)/float(max_tag-min_tag) + tag_count = Post.objects.filter(tags__name=self.name).count() + #print Tag.objects.filter(name=self.name).annotate(c = Count('post')) + font = int(min_font + (tag_count-min_tag)*step) + return font + +Tag.f = font_size diff --git a/blog/static/css/new.css b/blog/static/css/new.css index 4187179..7ba10b5 100644 --- a/blog/static/css/new.css +++ b/blog/static/css/new.css @@ -136,16 +136,17 @@ display: inline; margin-right: 10px; } - .paginator { - font-size: 20px; + #pagination { + font-size: 16px; list-style: none; - text-align: center; + //text-align: center; } - .paginator a { + #pagination a { display: inline-block; padding: 2 1; text-decoration:none; - text-align: center; + //text-align: center; } + div.post { font-size: 16px;} .post { box-shadow: 0 0.005em 0.01em 0 rgba(0, 0, 0, 0.12), 0 2px 10px 0 rgba(0, 0, 0, 0.12); box-sizing: border-box; @@ -153,8 +154,6 @@ color: #1a1a1a; display: block; font-family: 'Open Sans' - font-size: 14px; - font-weight: 300; line-height: 26px; margin: 0 0 10px 0; diff --git a/blog/templates/blog/base.html b/blog/templates/blog/base.html index 299f49a..2e217cd 100644 --- a/blog/templates/blog/base.html +++ b/blog/templates/blog/base.html @@ -5,7 +5,7 @@
- {% if posts.has_previous %} предыдущая{% endif %} - {% if posts.has_next %}следующая {% endif %} + {% if posts.has_previous %} <-предыдущая{% endif %} + {% if posts.has_next %}следующая-> {% endif %}
{% if posts.has_other_pages %} - Страницы: - |<< + |<< {% for page in posts.paginator.num_pages|truncate:posts.number %} {% if page == posts.number %} {{page}} - {% else %} {{page}} {% endif %} {% endfor %} - >>| + {% else %} {{page}} {% endif %} {% endfor %} + >>| {% endif %} + {% comment %} diff --git a/blog/templatetags/pagination_filters.py b/blog/templatetags/pagination_filters.py index 1d98eb3..d9fdcee 100644 --- a/blog/templatetags/pagination_filters.py +++ b/blog/templatetags/pagination_filters.py @@ -4,13 +4,12 @@ register = template.Library() def truncate(paginator, number): - if number < 5: - truncated_paginator = xrange(1, number+3) + truncated_paginator = xrange(1, min(paginator+1, number+3)) elif number > 4 and number < (paginator-3): truncated_paginator = xrange(number-3, number+3) else: - truncated_paginator = xrange(number-3, paginator) + truncated_paginator = xrange(number-3, paginator+1) return truncated_paginator register.filter('truncate', truncate) diff --git a/blog/views.py b/blog/views.py index a4826a8..a31c90f 100644 --- a/blog/views.py +++ b/blog/views.py @@ -20,9 +20,12 @@ def cloud(): max_tag, min_tag = v["c__max"], v["c__min"] step = (max_font - min_font)/float(max_tag-min_tag) #print step + """ tags = Tag.objects.all().annotate( c = Count('post'), f=min_font + (Count('post')-min_tag)*step).filter( c__gt = 0).order_by('name') + """ + tags = Tag.objects.all().annotate(c = Count('post')).order_by('name').filter(c__gt = 0) return tags @@ -31,7 +34,9 @@ def post_list(request, page='1', tag=None): post_list = Post.objects.filter(published_date__lte=timezone.now()).order_by('-published_date')#[int(page)*5-5:int(page)*5] else: post_list = Post.objects.filter(tags__name=tag).order_by('-published_date') + search_query = '' if request.GET.get('search'): + search_query = request.GET.get('search') post_list = Post.objects.filter(Q(title__contains = request.GET.get('search')) | Q(text__contains = request.GET.get('search'))).order_by('-published_date') paginator = Paginator(post_list, 5) page = request.GET.get('page') @@ -45,7 +50,7 @@ def post_list(request, page='1', tag=None): except EmptyPage: # If page is out of range (e.g. 9999), deliver last page of results. posts = paginator.page(paginator.num_pages) #print dir(posts.paginator) - return render_to_response('blog/post_list.html', {'posts': posts, 'latest': latest, 'cloud': tag_cloud}) + return render_to_response('blog/post_list.html', {'posts': posts, 'latest': latest, 'cloud': tag_cloud, 'search_query': search_query}) def post_detail(request, pk):