upd
This commit is contained in:
parent
67306c6032
commit
925e62be0c
|
@ -4,6 +4,8 @@ from django.db import models
|
||||||
from django.utils import timezone
|
from django.utils import timezone
|
||||||
from tinymce.models import HTMLField
|
from tinymce.models import HTMLField
|
||||||
from taggit.managers import TaggableManager
|
from taggit.managers import TaggableManager
|
||||||
|
from taggit.models import Tag
|
||||||
|
from django.db.models import Count, Max, Min
|
||||||
|
|
||||||
class Post(models.Model):
|
class Post(models.Model):
|
||||||
author = models.ForeignKey('auth.User')
|
author = models.ForeignKey('auth.User')
|
||||||
|
@ -22,3 +24,16 @@ class Post(models.Model):
|
||||||
def __unicode__(self):
|
def __unicode__(self):
|
||||||
return self.title
|
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
|
||||||
|
|
|
@ -136,16 +136,17 @@
|
||||||
display: inline;
|
display: inline;
|
||||||
margin-right: 10px;
|
margin-right: 10px;
|
||||||
}
|
}
|
||||||
.paginator {
|
#pagination {
|
||||||
font-size: 20px;
|
font-size: 16px;
|
||||||
list-style: none;
|
list-style: none;
|
||||||
text-align: center;
|
//text-align: center;
|
||||||
}
|
}
|
||||||
.paginator a {
|
#pagination a {
|
||||||
display: inline-block;
|
display: inline-block;
|
||||||
padding: 2 1; text-decoration:none;
|
padding: 2 1; text-decoration:none;
|
||||||
text-align: center;
|
//text-align: center;
|
||||||
}
|
}
|
||||||
|
div.post { font-size: 16px;}
|
||||||
.post {
|
.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-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;
|
box-sizing: border-box;
|
||||||
|
@ -153,8 +154,6 @@
|
||||||
color: #1a1a1a;
|
color: #1a1a1a;
|
||||||
display: block;
|
display: block;
|
||||||
font-family: 'Open Sans'
|
font-family: 'Open Sans'
|
||||||
font-size: 14px;
|
|
||||||
|
|
||||||
font-weight: 300;
|
font-weight: 300;
|
||||||
line-height: 26px;
|
line-height: 26px;
|
||||||
margin: 0 0 10px 0;
|
margin: 0 0 10px 0;
|
||||||
|
|
|
@ -5,7 +5,7 @@
|
||||||
<title>BLOG</title>
|
<title>BLOG</title>
|
||||||
<meta charset="utf-8">
|
<meta charset="utf-8">
|
||||||
<meta name="viewport" content="width=device-width, initial-scale=1">
|
<meta name="viewport" content="width=device-width, initial-scale=1">
|
||||||
<link rel="stylesheet" href="{% static 'css/blog.css' %}">
|
<!--link rel="stylesheet" href="{% static 'css/blog.css' %}"-->
|
||||||
<link rel="stylesheet" href="{% static 'css/new.css' %}">
|
<link rel="stylesheet" href="{% static 'css/new.css' %}">
|
||||||
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.3.0/css/font-awesome.min.css">
|
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.3.0/css/font-awesome.min.css">
|
||||||
</head>
|
</head>
|
||||||
|
@ -48,7 +48,7 @@
|
||||||
<h2> Теги </h2>
|
<h2> Теги </h2>
|
||||||
|
|
||||||
{% for tag in cloud %}
|
{% for tag in cloud %}
|
||||||
<a href="{% url 'post_list' tag=tag %}" style="font-size: {{tag.f}}; margin: 2px ">{{ tag.name }}({{ tag.c }})</a>
|
<a href="{% url 'post_list' tag=tag %}" style="font-size: {{tag.f}}px; margin: 2px ">{{ tag.name }}</a>
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
|
@ -57,18 +57,18 @@
|
||||||
</div>
|
</div>
|
||||||
<div id="pagination">
|
<div id="pagination">
|
||||||
<p>
|
<p>
|
||||||
{% if posts.has_previous %} <a href="?page={{ posts.previous_page_number }}">предыдущая</a>{% endif %}
|
{% if posts.has_previous %} <a href="?page={{ posts.previous_page_number }}{% if search_query != '' %}&search={{ search_query }} {% endif %}"><-предыдущая</a>{% endif %}
|
||||||
{% if posts.has_next %}<a href="?page={{ posts.next_page_number }}">следующая</a> {% endif %}
|
{% if posts.has_next %}<a href="?page={{ posts.next_page_number }}{% if search_query != '' %}&search={{ search_query }} {% endif %}">следующая-></a> {% endif %}
|
||||||
</p>
|
</p>
|
||||||
{% if posts.has_other_pages %}
|
{% if posts.has_other_pages %}
|
||||||
Страницы:
|
<a href="?page=1{% if search_query != '' %}&search={{ search_query }} {% endif %}">|<<</a>
|
||||||
<a href="?page=1">|<<</a>
|
|
||||||
{% for page in posts.paginator.num_pages|truncate:posts.number %}
|
{% for page in posts.paginator.num_pages|truncate:posts.number %}
|
||||||
{% if page == posts.number %} {{page}}
|
{% if page == posts.number %} {{page}}
|
||||||
{% else %} <a href="?page={{page}}">{{page}}</a> {% endif %} {% endfor %}
|
{% else %} <a href="?page={{page}}{% if search_query != '' %}&search={{ search_query }} {% endif %}">{{page}}</a> {% endif %} {% endfor %}
|
||||||
<a href="?page={{ posts.paginator.num_pages }}"> >>| </a>
|
<a href="?page={{ posts.paginator.num_pages }}{% if search_query != '' %}&search={{ search_query }} {% endif %}"> >>| </a>
|
||||||
|
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
{% comment %}
|
||||||
<ul class="menu_top paginator">
|
<ul class="menu_top paginator">
|
||||||
|
|
||||||
{% if posts.has_previous %}
|
{% if posts.has_previous %}
|
||||||
|
@ -80,7 +80,8 @@
|
||||||
<li> <a href="?page={{ posts.next_page_number }}"> {{ posts.next_page_number }}</a> </li>
|
<li> <a href="?page={{ posts.next_page_number }}"> {{ posts.next_page_number }}</a> </li>
|
||||||
<!--li> <a href="?page={{ posts.next_page_number|add:1 }}">{{ posts.next_page_number|add:1 }}</a></li-->
|
<!--li> <a href="?page={{ posts.next_page_number|add:1 }}">{{ posts.next_page_number|add:1 }}</a></li-->
|
||||||
<li> <a href="?page={{ posts.paginator.num_pages }}"> >> </a></li> {% endif %}
|
<li> <a href="?page={{ posts.paginator.num_pages }}"> >> </a></li> {% endif %}
|
||||||
{% comment %}
|
{% endcomment %}
|
||||||
|
{% comment %}
|
||||||
<!--li> {% for i in posts.paginator.page_range %} </li-->
|
<!--li> {% for i in posts.paginator.page_range %} </li-->
|
||||||
{% endcomment %}
|
{% endcomment %}
|
||||||
</ul>
|
</ul>
|
||||||
|
|
|
@ -4,13 +4,12 @@ register = template.Library()
|
||||||
|
|
||||||
|
|
||||||
def truncate(paginator, number):
|
def truncate(paginator, number):
|
||||||
|
|
||||||
if number < 5:
|
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):
|
elif number > 4 and number < (paginator-3):
|
||||||
truncated_paginator = xrange(number-3, number+3)
|
truncated_paginator = xrange(number-3, number+3)
|
||||||
else:
|
else:
|
||||||
truncated_paginator = xrange(number-3, paginator)
|
truncated_paginator = xrange(number-3, paginator+1)
|
||||||
return truncated_paginator
|
return truncated_paginator
|
||||||
|
|
||||||
register.filter('truncate', truncate)
|
register.filter('truncate', truncate)
|
||||||
|
|
|
@ -20,9 +20,12 @@ def cloud():
|
||||||
max_tag, min_tag = v["c__max"], v["c__min"]
|
max_tag, min_tag = v["c__max"], v["c__min"]
|
||||||
step = (max_font - min_font)/float(max_tag-min_tag)
|
step = (max_font - min_font)/float(max_tag-min_tag)
|
||||||
#print step
|
#print step
|
||||||
|
"""
|
||||||
tags = Tag.objects.all().annotate(
|
tags = Tag.objects.all().annotate(
|
||||||
c = Count('post'), f=min_font + (Count('post')-min_tag)*step).filter(
|
c = Count('post'), f=min_font + (Count('post')-min_tag)*step).filter(
|
||||||
c__gt = 0).order_by('name')
|
c__gt = 0).order_by('name')
|
||||||
|
"""
|
||||||
|
tags = Tag.objects.all().annotate(c = Count('post')).order_by('name').filter(c__gt = 0)
|
||||||
return tags
|
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]
|
post_list = Post.objects.filter(published_date__lte=timezone.now()).order_by('-published_date')#[int(page)*5-5:int(page)*5]
|
||||||
else:
|
else:
|
||||||
post_list = Post.objects.filter(tags__name=tag).order_by('-published_date')
|
post_list = Post.objects.filter(tags__name=tag).order_by('-published_date')
|
||||||
|
search_query = ''
|
||||||
if request.GET.get('search'):
|
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')
|
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)
|
paginator = Paginator(post_list, 5)
|
||||||
page = request.GET.get('page')
|
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.
|
except EmptyPage: # If page is out of range (e.g. 9999), deliver last page of results.
|
||||||
posts = paginator.page(paginator.num_pages)
|
posts = paginator.page(paginator.num_pages)
|
||||||
#print dir(posts.paginator)
|
#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):
|
def post_detail(request, pk):
|
||||||
|
|
Loading…
Reference in New Issue
Block a user