2016-07-11 19:33:34 +00:00
|
|
|
from django.contrib.sites.shortcuts import get_current_site
|
2016-07-03 20:39:29 +00:00
|
|
|
from django.db.models import Q, Sum
|
2016-07-01 23:03:07 +00:00
|
|
|
from django.db.models.functions import Coalesce
|
2016-08-07 10:51:38 +00:00
|
|
|
from django.utils.safestring import mark_safe
|
2016-07-01 23:03:07 +00:00
|
|
|
|
2016-07-03 20:39:29 +00:00
|
|
|
from accounts.models import Participation
|
|
|
|
|
2016-08-07 10:51:38 +00:00
|
|
|
from markdown import markdown
|
|
|
|
import bleach
|
|
|
|
|
2016-07-01 23:03:07 +00:00
|
|
|
|
|
|
|
def query_sum(queryset, field):
|
|
|
|
return queryset.aggregate(s=Coalesce(Sum(field), 0))['s']
|
2016-07-03 20:39:29 +00:00
|
|
|
|
|
|
|
|
|
|
|
def allowed_talks(talks, request):
|
2016-07-11 19:33:34 +00:00
|
|
|
if not Participation.objects.get(site=get_current_site(request), user=request.user).is_orga():
|
|
|
|
talks = talks.filter(Q(topics__reviewers=request.user) | Q(speakers=request.user) | Q(proposer=request.user))
|
2016-07-04 23:16:33 +00:00
|
|
|
return talks.distinct()
|
2016-08-07 10:51:38 +00:00
|
|
|
|
|
|
|
def markdown_to_html(md):
|
|
|
|
html = markdown(md)
|
2016-08-22 18:34:40 +00:00
|
|
|
allowed_tags = bleach.ALLOWED_TAGS + ['p', 'pre', 'span' ] + ['h%d' % i for i in range(1, 7) ]
|
2016-08-07 10:51:38 +00:00
|
|
|
html = bleach.clean(html, tags=allowed_tags)
|
|
|
|
return mark_safe(html)
|