diff --git a/blog/templatetags/pagination_filters.py b/blog/templatetags/pagination_filters.py index df2e4be..1d98eb3 100644 --- a/blog/templatetags/pagination_filters.py +++ b/blog/templatetags/pagination_filters.py @@ -2,9 +2,9 @@ from django import template register = template.Library() + def truncate(paginator, number): - print paginator - print number + if number < 5: truncated_paginator = xrange(1, number+3) elif number > 4 and number < (paginator-3): diff --git a/blog/views.py b/blog/views.py index a8042ab..a4826a8 100644 --- a/blog/views.py +++ b/blog/views.py @@ -11,18 +11,21 @@ from django.contrib.auth.decorators import login_required from taggit.models import Tag import math + def cloud(): min_font = 11 max_font = 28 #size = max(min_font, round((min_font+(tag_list[i]-min_w)*step)*(math.log(tag_list[i])/Math.log(max_w)))) 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)/(max_tag-min_tag) + 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') return tags + def post_list(request, page='1', tag=None): if tag is None: post_list = Post.objects.filter(published_date__lte=timezone.now()).order_by('-published_date')#[int(page)*5-5:int(page)*5] @@ -41,7 +44,7 @@ def post_list(request, page='1', tag=None): posts = paginator.page(1) 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) + #print dir(posts.paginator) return render_to_response('blog/post_list.html', {'posts': posts, 'latest': latest, 'cloud': tag_cloud}) @@ -55,10 +58,11 @@ def post_detail(request, pk): post.delete() return redirect('/') else: - return redirect('/admin/login/?next=/blog/') + return redirect('/admin/login/?next=/post/' + pk) return render(request, 'blog/post_detail.html', {'post': post, 'tags': tags, 'latest': latest, 'cloud': tag_cloud}) -@login_required(login_url="/admin/login/?next=/blog/") + +@login_required(login_url="/admin/login/?next=/") def post_new(request): tag_cloud = cloud() latest = Post.objects.filter(published_date__lte=timezone.now()).order_by('-published_date')[0:9] @@ -76,7 +80,7 @@ def post_new(request): return render(request, 'blog/post_edit.html', {'form': form, 'latest': latest, 'cloud': tag_cloud}) -@login_required(login_url="/admin/login/?next=/blog/") +@login_required(login_url="/admin/login/?next=/") def post_edit(request, pk): tag_cloud = cloud() latest = Post.objects.filter(published_date__lte=timezone.now()).order_by('-published_date')[0:9] diff --git a/mysite/settings.py b/mysite/settings.py index ed6d93e..e0c43b0 100644 --- a/mysite/settings.py +++ b/mysite/settings.py @@ -78,14 +78,24 @@ WSGI_APPLICATION = 'mysite.wsgi.application' # Database # https://docs.djangoproject.com/en/1.9/ref/settings/#databases - +''' DATABASES = { 'default': { 'ENGINE': 'django.db.backends.sqlite3', 'NAME': os.path.join(BASE_DIR, '../db.sqlite3'), } } - +''' +DATABASES = { + 'default': { + 'ENGINE': 'django.db.backends.postgresql_psycopg2', + 'NAME': 'mysite', + 'USER': 'anya', + 'PASSWORD': 'pupsi4ek', + 'HOST': '127.0.0.1', + 'PORT': '5432', + } +} # Password validation # https://docs.djangoproject.com/en/1.9/ref/settings/#auth-password-validators