Add Conference model

This model allow to write markdown home page
This commit is contained in:
Élie Bouttier 2016-08-07 12:51:38 +02:00
parent 10f2ec72df
commit f4efcf6dfd
9 changed files with 74 additions and 5 deletions

View File

@ -1,6 +1,7 @@
from django.contrib import admin
from proposals.models import Talk, Topic
from proposals.models import Conference, Talk, Topic
admin.site.register(Conference)
admin.site.register(Topic)
admin.site.register(Talk)

View File

@ -3,3 +3,6 @@ from django.apps import AppConfig
class ProposalsConfig(AppConfig):
name = 'proposals'
def ready(self):
import proposals.signals # noqa

View File

@ -0,0 +1,25 @@
# -*- coding: utf-8 -*-
# Generated by Django 1.10 on 2016-08-07 10:45
from __future__ import unicode_literals
from django.db import migrations, models
import django.db.models.deletion
class Migration(migrations.Migration):
dependencies = [
('sites', '0002_alter_domain_unique'),
('proposals', '0006_topic_description'),
]
operations = [
migrations.CreateModel(
name='Conference',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('home', models.TextField(blank=True, default='')),
('site', models.OneToOneField(on_delete=django.db.models.deletion.CASCADE, to='sites.Site')),
],
),
]

View File

@ -15,6 +15,15 @@ from ponyconf.utils import PonyConfModel, enum_to_choices
from .utils import query_sum
class Conference(models.Model):
site = models.OneToOneField(Site, on_delete=models.CASCADE)
home = models.TextField(blank=True, default="")
def __str__(self):
return str(self.site)
class Topic(PonyConfModel):
site = models.ForeignKey(Site, on_delete=models.CASCADE)

View File

@ -1,14 +1,21 @@
from django.db.models.signals import m2m_changed
from django.db.models.signals import m2m_changed, post_migrate
from django.dispatch import Signal, receiver
from django.contrib.sites.models import Site
from accounts.models import Participation
from .models import Talk, Topic
from .models import Conference, Talk, Topic
talk_added = Signal(providing_args=["sender", "instance", "author"])
talk_edited = Signal(providing_args=["sender", "instance", "author"])
@receiver(post_migrate)
def create_conference(sender, **kwargs):
for site in Site.objects.all():
Conference.objects.get_or_create(site=site)
@receiver(m2m_changed, sender=Talk.speakers.through, dispatch_uid="Create Participation for speakers")
def create_participation_for_speakers(sender, instance, action, reverse, model, pk_set, using, **kwargs):
if action != "pre_add":

View File

@ -1,6 +1,6 @@
{% extends 'base.html' %}
{% load i18n %}
{% load proposals_tags i18n %}
{% block hometab %} class="active"{% endblock %}
@ -8,6 +8,6 @@
<div class="h1">{% blocktrans with confname=site.name %}Welcome to {{ confname }}!{% endblocktrans %}</div>
Some general informations about the conference {{ site.name }}.
{% markdown site.conference.home %}
{% endblock %}

View File

@ -0,0 +1,11 @@
from django import template
from proposals.utils import markdown_to_html
register = template.Library()
@register.simple_tag
def markdown(value):
return markdown_to_html(value)

View File

@ -1,9 +1,13 @@
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']
@ -13,3 +17,9 @@ 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)

View File

@ -7,4 +7,7 @@ django-registration-redux
django-select2
django-avatar
markdown
bleach
-e git://github.com/Nim65s/django-YummyEmailOrUsernameInsensitiveAuth.git#egg=django-yeouia