fnp
/
wolnelektury.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Update picture viewer.
[wolnelektury.git]
/
apps
/
social
/
templatetags
/
social_tags.py
diff --git
a/apps/social/templatetags/social_tags.py
b/apps/social/templatetags/social_tags.py
index
29a4309
..
d6d3f71
100755
(executable)
--- a/
apps/social/templatetags/social_tags.py
+++ b/
apps/social/templatetags/social_tags.py
@@
-2,6
+2,7
@@
# This file is part of Wolnelektury, licensed under GNU Affero GPLv3 or later.
# Copyright © Fundacja Nowoczesna Polska. See NOTICE for more information.
#
# This file is part of Wolnelektury, licensed under GNU Affero GPLv3 or later.
# Copyright © Fundacja Nowoczesna Polska. See NOTICE for more information.
#
+from random import randint
from django import template
from catalogue.models import Book
from social.models import Cite
from django import template
from catalogue.models import Book
from social.models import Cite
@@
-12,9
+13,9
@@
register = template.Library()
register.filter('likes', likes)
register.filter('likes', likes)
-@register.
inclusion_tag('social/cite_promo.html',
takes_context=True)
-def c
ite_promo(context, ctx=None, fallback=Fals
e):
- """Choose"""
+@register.
assignment_tag(
takes_context=True)
+def c
hoose_cite(context, ctx=Non
e):
+ """Choose
a cite for main page, for book or for set of tags.
"""
try:
request = context['request']
assert request.user.is_staff
try:
request = context['request']
assert request.user.is_staff
@@
-29,10
+30,30
@@
def cite_promo(context, ctx=None, fallback=False):
cites = cites_for_tags([ctx.book_tag()])
else:
cites = cites_for_tags(ctx)
cites = cites_for_tags([ctx.book_tag()])
else:
cites = cites_for_tags(ctx)
- cite = cites.order_by('?')[0] if cites.exists() else None
+ stickies = cites.filter(sticky=True)
+ count = stickies.count()
+ if count:
+ cite = stickies[randint(0, count - 1)]
+ else:
+ count = cites.count()
+ if count:
+ cite = cites[randint(0, count - 1)]
+ else:
+ cite = None
+ return cite
+
+@register.inclusion_tag('social/cite_promo.html')
+def render_cite(cite):
return {
'cite': cite,
return {
'cite': cite,
+ }
+
+
+@register.inclusion_tag('social/cite_promo.html', takes_context=True)
+def cite_promo(context, ctx=None, fallback=False):
+ return {
+ 'cite': choose_cite(context, ctx),
'fallback': fallback,
'ctx': ctx,
}
'fallback': fallback,
'ctx': ctx,
}