434
434
sort_by = sort_by_default
436
436
# Executed on every request (POST and GET)
437
search_date = date.today() - timedelta(int(days))
439
# Create a QuerySet with only public posts
440
last_posts = Post.objects.public(date_from=search_date)
442
posts_count = len(last_posts)
444
if sort_by == 'topic':
445
# The use of an OrderedDict makes sure the ordering of
446
# last_posts get not arbitrary
447
topics = OrderedDict()
448
for post in last_posts:
449
if post.topic not in topics:
450
# Create a new key with a list as value
451
topics[post.topic] = [post]
453
# key exists, just add the post
454
topics[post.topic].append(post)
458
elif sort_by == 'forum':
459
forums = OrderedDict()
460
for post in last_posts:
461
if post.topic.forum.name not in forums:
462
forums[post.topic.forum.name] = OrderedDict({post.topic: [post]})
463
elif post.topic not in forums[post.topic.forum.name]:
464
forums[post.topic.forum.name].update({post.topic: [post]})
466
forums[post.topic.forum.name][post.topic].append(post)
437
# We need a try clause here, because one can set invalid values for
440
search_date = date.today() - timedelta(int(days))
442
# Create a QuerySet with only public posts
443
last_posts = Post.objects.public(date_from=search_date)
445
posts_count = len(last_posts)
447
if sort_by == 'topic':
448
# The use of an OrderedDict makes sure the ordering of
449
# last_posts get not arbitrary
450
topics = OrderedDict()
451
for post in last_posts:
452
if post.topic not in topics:
453
# Create a new key with a list as value
454
topics[post.topic] = [post]
456
# key exists, just add the post
457
topics[post.topic].append(post)
461
elif sort_by == 'forum':
462
forums = OrderedDict()
463
for post in last_posts:
464
if post.topic.forum.name not in forums:
465
forums[post.topic.forum.name] = OrderedDict({post.topic: [post]})
466
elif post.topic not in forums[post.topic.forum.name]:
467
forums[post.topic.forum.name].update({post.topic: [post]})
469
forums[post.topic.forum.name][post.topic].append(post)
473
except UnboundLocalError:
477
sort_by = sort_by_default
471
480
'object_list': object_list,
472
481
'posts_count': posts_count,