bornhack-website/src/program/signal_handlers.py

21 lines
973 B
Python
Raw Normal View History

2017-01-23 17:57:30 +00:00
from django.core.exceptions import ValidationError
2017-07-09 14:54:21 +00:00
def check_speaker_event_camp_consistency(sender, instance, **kwargs):
2017-01-23 17:57:30 +00:00
if kwargs['action'] == 'pre_add':
# loop over speakers being added to this event
2017-01-23 17:57:30 +00:00
for pk in kwargs['pk_set']:
# check if this speaker belongs to a different event than the event does
from program.models import Speaker
speaker = Speaker.objects.get(id=pk)
2017-07-09 14:54:21 +00:00
if speaker.camp != instance.camp:
raise ValidationError({'speakers': 'The speaker (%s) belongs to a different camp (%s) than the event does (%s)' % (speaker, speaker.camp, instance.camp)})
2017-01-23 17:57:30 +00:00
def check_speaker_camp_change(sender, instance, **kwargs):
2017-01-25 22:48:37 +00:00
if instance.pk:
for event in instance.events.all():
if event.camp != instance.camp:
raise ValidationError({'camp': 'You cannot change the camp a speaker belongs to if the speaker is associated with one or more events.'})
2017-01-23 17:57:30 +00:00