forked from AFPy/PonyConf
f4efcf6dfd
This model allow to write markdown home page
26 lines
845 B
Python
26 lines
845 B
Python
from django.contrib.sites.shortcuts import get_current_site
|
|
from django.db.models import Q, Sum
|
|
from django.db.models.functions import Coalesce
|
|
from django.utils.safestring import mark_safe
|
|
|
|
from accounts.models import Participation
|
|
|
|
from markdown import markdown
|
|
import bleach
|
|
|
|
|
|
def query_sum(queryset, field):
|
|
return queryset.aggregate(s=Coalesce(Sum(field), 0))['s']
|
|
|
|
|
|
def allowed_talks(talks, request):
|
|
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))
|
|
return talks.distinct()
|
|
|
|
def markdown_to_html(md):
|
|
html = markdown(md)
|
|
allowed_tags = bleach.ALLOWED_TAGS + ['p', 'pre', 'span']
|
|
html = bleach.clean(html, tags=allowed_tags)
|
|
return mark_safe(html)
|