fix: multisite issue with proposed categories
This commit is contained in:
parent
4412af7eaf
commit
2f2ce124c3
|
@ -9,6 +9,12 @@ from .models import Conference, Participant, Talk, TalkCategory, Track
|
||||||
class ConferenceAdmin(SiteAdminMixin, admin.ModelAdmin):
|
class ConferenceAdmin(SiteAdminMixin, admin.ModelAdmin):
|
||||||
filter_horizontal = ('staff',)
|
filter_horizontal = ('staff',)
|
||||||
|
|
||||||
|
def has_add_permission(self, request):
|
||||||
|
return False
|
||||||
|
|
||||||
|
def has_delete_permission(self, request, obj=None):
|
||||||
|
return False
|
||||||
|
|
||||||
|
|
||||||
class ParticipantAdmin(SiteAdminMixin, admin.ModelAdmin):
|
class ParticipantAdmin(SiteAdminMixin, admin.ModelAdmin):
|
||||||
pass
|
pass
|
||||||
|
|
20
cfp/forms.py
20
cfp/forms.py
|
@ -1,12 +1,22 @@
|
||||||
from django import forms
|
from django import forms
|
||||||
from django.forms.models import modelform_factory
|
from django.forms.models import modelform_factory
|
||||||
|
|
||||||
from .models import Participant, Talk
|
from .models import Participant, Talk, TalkCategory
|
||||||
|
|
||||||
|
|
||||||
class ProposeForm(forms.Form):
|
class TalkForm(forms.ModelForm):
|
||||||
pass
|
def __init__(self, *args, **kwargs):
|
||||||
|
conference = kwargs.pop('conference')
|
||||||
|
staff = kwargs.pop('staff')
|
||||||
|
super().__init__(*args, **kwargs)
|
||||||
|
if staff:
|
||||||
|
self.fields['category'].queryset = TalkCategory.objects.filter(site=conference.site)
|
||||||
|
else:
|
||||||
|
self.fields['category'].queryset = conference.opened_categories
|
||||||
|
|
||||||
|
class Meta:
|
||||||
|
model = Talk
|
||||||
|
fields = ('category', 'title', 'description','notes')
|
||||||
|
|
||||||
|
|
||||||
ParticipantForm = modelform_factory(Participant, fields=['email'])
|
ParticipantForm = modelform_factory(Participant, fields=('name','email', 'biography'))
|
||||||
TalkForm = modelform_factory(Talk, fields=['title'])
|
|
||||||
|
|
|
@ -49,12 +49,12 @@ class Conference(models.Model):
|
||||||
# events = Event.objects.filter(site=self.site)
|
# events = Event.objects.filter(site=self.site)
|
||||||
# return any(map(lambda x: x.is_open(), events))
|
# return any(map(lambda x: x.is_open(), events))
|
||||||
|
|
||||||
#@property
|
@property
|
||||||
#def opened_events(self):
|
def opened_categories(self):
|
||||||
# now = timezone.now()
|
now = timezone.now()
|
||||||
# return Event.objects.filter(site=self.site)\
|
return TalkCategory.objects.filter(site=self.site)\
|
||||||
# .filter(Q(opening_date__isnull=True) | Q(opening_date__lte=now))\
|
.filter(Q(opening_date__isnull=True) | Q(opening_date__lte=now))\
|
||||||
# .filter(Q(closing_date__isnull=True) | Q(closing_date__gte=now))
|
.filter(Q(closing_date__isnull=True) | Q(closing_date__gte=now))
|
||||||
|
|
||||||
def from_email(self):
|
def from_email(self):
|
||||||
return self.name+' <'+self.contact_email+'>'
|
return self.name+' <'+self.contact_email+'>'
|
||||||
|
|
|
@ -37,4 +37,5 @@ def markdown_to_html(md):
|
||||||
|
|
||||||
|
|
||||||
def is_staff(request, user):
|
def is_staff(request, user):
|
||||||
return user.is_authenticated and (user.is_superuser or user in site.conference.staff)
|
conference = get_current_conf(request)
|
||||||
|
return user.is_authenticated and (user.is_superuser or conference.staff.filter(pk=user.pk).exists())
|
||||||
|
|
|
@ -1,6 +1,5 @@
|
||||||
from django.core.mail import send_mail
|
from django.core.mail import send_mail
|
||||||
from django.core.urlresolvers import reverse_lazy
|
from django.core.urlresolvers import reverse_lazy
|
||||||
from django.forms.models import modelform_factory
|
|
||||||
from django.shortcuts import get_object_or_404, redirect, render
|
from django.shortcuts import get_object_or_404, redirect, render
|
||||||
from django.urls import reverse
|
from django.urls import reverse
|
||||||
from django.utils.translation import ugettext_lazy as _
|
from django.utils.translation import ugettext_lazy as _
|
||||||
|
@ -8,7 +7,9 @@ from django.views.generic import FormView, TemplateView
|
||||||
from django.contrib import messages
|
from django.contrib import messages
|
||||||
|
|
||||||
from cfp.decorators import staff_required
|
from cfp.decorators import staff_required
|
||||||
|
from .utils import is_staff
|
||||||
from .models import Participant, Talk, Vote
|
from .models import Participant, Talk, Vote
|
||||||
|
from .forms import TalkForm, ParticipantForm
|
||||||
|
|
||||||
|
|
||||||
def home(request, conference):
|
def home(request, conference):
|
||||||
|
@ -28,10 +29,8 @@ def talk_proposal(request, conference, talk_id=None, participant_id=None):
|
||||||
talk = get_object_or_404(Talk, token=talk_id, site=site)
|
talk = get_object_or_404(Talk, token=talk_id, site=site)
|
||||||
participant = get_object_or_404(Participant, token=participant_id, site=site)
|
participant = get_object_or_404(Participant, token=participant_id, site=site)
|
||||||
|
|
||||||
ParticipantForm = modelform_factory(Participant, fields=('name','email', 'biography'))
|
|
||||||
participant_form = ParticipantForm(request.POST or None, instance=participant)
|
participant_form = ParticipantForm(request.POST or None, instance=participant)
|
||||||
TalkForm = modelform_factory(Talk, fields=('category', 'title', 'description','notes'))
|
talk_form = TalkForm(request.POST or None, conference=conference, staff=is_staff(request, request.user), instance=talk)
|
||||||
talk_form = TalkForm(request.POST or None, instance=talk)
|
|
||||||
|
|
||||||
if request.method == 'POST' and talk_form.is_valid() and participant_form.is_valid():
|
if request.method == 'POST' and talk_form.is_valid() and participant_form.is_valid():
|
||||||
talk = talk_form.save(commit=False)
|
talk = talk_form.save(commit=False)
|
||||||
|
@ -98,7 +97,6 @@ def talk_proposal_speaker_edit(request, conference, talk_id, participant_id=None
|
||||||
if participant_id:
|
if participant_id:
|
||||||
participant = get_object_or_404(Participant, token=participant_id, site=conference.site)
|
participant = get_object_or_404(Participant, token=participant_id, site=conference.site)
|
||||||
|
|
||||||
ParticipantForm = modelform_factory(Participant, fields=('name','email', 'biography'))
|
|
||||||
participant_form = ParticipantForm(request.POST or None, instance=participant)
|
participant_form = ParticipantForm(request.POST or None, instance=participant)
|
||||||
|
|
||||||
if request.method == 'POST' and participant_form.is_valid():
|
if request.method == 'POST' and participant_form.is_valid():
|
||||||
|
|
Loading…
Reference in New Issue