coding utf-8 import cPickle datetime from pytils import translit from

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# -*- coding: utf-8
import cPickle, datetime
from pytils import translit
from django.views.generic.date_based import archive_day, archive_month, archive_year, archive_index
from django.shortcuts import get_object_or_404
from django.http import HttpResponseRedirect
from tagging.models import Tag, TaggedItem
from voting.models import Vote
from common.decorators import render_to, activation_required, paginate_style, by_date
from accounts.models import Profile
from models import Post, PostComments
from forms import PostCommentsForm, CreatePostForm
@render_to('blog/show_post.html')
def show_post(request, year, month, day, slug):
date = datetime.date(int(year), int(month), int(day))
post = get_object_or_404(Post,
date__range=(datetime.datetime.combine(date, datetime.time.min), datetime.datetime.combine(date, datetime.time.max)),
slug=slug)
if request.POST:
data = request.POST.copy()
data['post'] = post.id
data['user'] = request.user.id
form = PostCommentsForm(data)
if form.is_valid():
form.save()
return HttpResponseRedirect(post.show_url())
else:
form = PostCommentsForm()
now = datetime.datetime.now()
online_minimum = now - datetime.timedelta(minutes=15)
new_online = []
try:
online = cPickle.loads(str(post.online))
for user, last_visit in online:
if last_visit > online_minimum and user != request.user:
new_online.append((user, now))
except EOFError:
pass
if request.user.is_authenticated():
new_online.append((request.user, now))
post.online = cPickle.dumps(tuple(new_online))
post.save()
post_score = Vote.objects.get_score(post)
return {'post': post, 'form': form, 'post_score': post_score}