fix 144
This commit is contained in:
parent
cc43b0cb4d
commit
973bdc575c
|
@ -1,12 +1,25 @@
|
||||||
from django.apps import AppConfig
|
from django.apps import AppConfig
|
||||||
from django.db.models.signals import m2m_changed, pre_save
|
from django.db.models.signals import m2m_changed, pre_save
|
||||||
from .signal_handlers import check_speaker_event_camp_consistency, check_speaker_camp_change
|
|
||||||
|
|
||||||
class ProgramConfig(AppConfig):
|
class ProgramConfig(AppConfig):
|
||||||
name = 'program'
|
name = 'program'
|
||||||
|
|
||||||
def ready(self):
|
def ready(self):
|
||||||
from .models import Speaker
|
from .models import (
|
||||||
m2m_changed.connect(check_speaker_event_camp_consistency, sender=Speaker.events.through)
|
Speaker,
|
||||||
|
SpeakerProposal,
|
||||||
|
EventProposal
|
||||||
|
)
|
||||||
|
from .signal_handlers import (
|
||||||
|
check_speaker_event_camp_consistency,
|
||||||
|
check_speaker_camp_change,
|
||||||
|
notify_proposal_submitted
|
||||||
|
)
|
||||||
|
m2m_changed.connect(
|
||||||
|
check_speaker_event_camp_consistency,
|
||||||
|
sender=Speaker.events.through
|
||||||
|
)
|
||||||
pre_save.connect(check_speaker_camp_change, sender=Speaker)
|
pre_save.connect(check_speaker_camp_change, sender=Speaker)
|
||||||
|
pre_save.connect(notify_proposal_submitted, sender=SpeakerProposal)
|
||||||
|
pre_save.connect(notify_proposal_submitted, sender=EventProposal)
|
||||||
|
|
|
@ -12,18 +12,14 @@ from django.db import models
|
||||||
from django.core.exceptions import ObjectDoesNotExist, ValidationError
|
from django.core.exceptions import ObjectDoesNotExist, ValidationError
|
||||||
from django.dispatch import receiver
|
from django.dispatch import receiver
|
||||||
from django.utils.text import slugify
|
from django.utils.text import slugify
|
||||||
from django.utils import timezone
|
|
||||||
from django.conf import settings
|
from django.conf import settings
|
||||||
from django.core.urlresolvers import reverse_lazy
|
from django.core.urlresolvers import reverse_lazy
|
||||||
from django.core.files.storage import FileSystemStorage
|
from django.core.files.storage import FileSystemStorage
|
||||||
from django.urls import reverse
|
from django.urls import reverse
|
||||||
from django.apps import apps
|
from django.apps import apps
|
||||||
from django.core.files.base import ContentFile
|
from django.core.files.base import ContentFile
|
||||||
from django.db.models.signals import post_save
|
|
||||||
|
|
||||||
from utils.models import CreatedUpdatedModel, CampRelatedModel
|
from utils.models import CreatedUpdatedModel, CampRelatedModel
|
||||||
from .email import add_new_speakerproposal_email, add_new_eventproposal_email
|
|
||||||
from ircbot.models import OutgoingIrcMessage
|
|
||||||
logger = logging.getLogger("bornhack.%s" % __name__)
|
logger = logging.getLogger("bornhack.%s" % __name__)
|
||||||
|
|
||||||
|
|
||||||
|
@ -287,40 +283,6 @@ class EventProposal(UserSubmittedModel):
|
||||||
self.proposal_status = eventproposalmodel.PROPOSAL_APPROVED
|
self.proposal_status = eventproposalmodel.PROPOSAL_APPROVED
|
||||||
self.save()
|
self.save()
|
||||||
|
|
||||||
|
|
||||||
@receiver(post_save, sender=EventProposal)
|
|
||||||
@receiver(post_save, sender=SpeakerProposal)
|
|
||||||
def notify_proposals(sender, created, instance, **kwargs):
|
|
||||||
target = settings.IRCBOT_CHANNELS['orga'] if 'orga' in settings.IRCBOT_CHANNELS else settings.IRCBOT_CHANNELS['default']
|
|
||||||
|
|
||||||
if created and isinstance(instance, SpeakerProposal):
|
|
||||||
if not add_new_speakerproposal_email(instance):
|
|
||||||
logger.error(
|
|
||||||
'Error adding speaker proposal email to outgoing queue for {}'.format(instance)
|
|
||||||
)
|
|
||||||
OutgoingIrcMessage.objects.create(
|
|
||||||
target=target,
|
|
||||||
message="New speaker proposal: {} - https://bornhack.dk/admin/program/speakerproposal/{}/change/".format(
|
|
||||||
instance.name,
|
|
||||||
instance.uuid
|
|
||||||
),
|
|
||||||
timeout=timezone.now()+timedelta(minutes=10)
|
|
||||||
)
|
|
||||||
|
|
||||||
if created and isinstance(instance, EventProposal):
|
|
||||||
if not add_new_eventproposal_email(instance):
|
|
||||||
logger.error(
|
|
||||||
'Error adding event proposal email to outgoing queue for {}'.format(instance)
|
|
||||||
)
|
|
||||||
OutgoingIrcMessage.objects.create(
|
|
||||||
target=target,
|
|
||||||
message="New event proposal: {} - https://bornhack.dk/admin/program/eventproposal/{}/change/".format(
|
|
||||||
instance.title,
|
|
||||||
instance.uuid
|
|
||||||
),
|
|
||||||
timeout=timezone.now()+timedelta(minutes=10)
|
|
||||||
)
|
|
||||||
|
|
||||||
###############################################################################
|
###############################################################################
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -1,4 +1,15 @@
|
||||||
|
import logging
|
||||||
|
|
||||||
|
from datetime import timedelta
|
||||||
|
|
||||||
from django.core.exceptions import ValidationError
|
from django.core.exceptions import ValidationError
|
||||||
|
from django.utils import timezone
|
||||||
|
from django.conf import settings
|
||||||
|
|
||||||
|
from .email import add_new_speakerproposal_email, add_new_eventproposal_email
|
||||||
|
from .models import EventProposal, SpeakerProposal
|
||||||
|
from ircbot.models import OutgoingIrcMessage
|
||||||
|
logger = logging.getLogger("bornhack.%s" % __name__)
|
||||||
|
|
||||||
|
|
||||||
def check_speaker_event_camp_consistency(sender, instance, **kwargs):
|
def check_speaker_event_camp_consistency(sender, instance, **kwargs):
|
||||||
|
@ -26,3 +37,42 @@ def check_speaker_camp_change(sender, instance, **kwargs):
|
||||||
if event.camp != instance.camp:
|
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.'})
|
raise ValidationError({'camp': 'You cannot change the camp a speaker belongs to if the speaker is associated with one or more events.'})
|
||||||
|
|
||||||
|
|
||||||
|
# pre_save signal that notifies if a proposal changes status from draft to
|
||||||
|
# pending i.e. is submitted.
|
||||||
|
def notify_proposal_submitted(sender, instance, **kwargs):
|
||||||
|
try:
|
||||||
|
original = sender.objects.get(pk=instance.pk)
|
||||||
|
except sender.DoesNotExist:
|
||||||
|
return False
|
||||||
|
|
||||||
|
target = settings.IRCBOT_CHANNELS['orga'] if 'orga' in settings.IRCBOT_CHANNELS else settings.IRCBOT_CHANNELS['default']
|
||||||
|
|
||||||
|
if original.proposal_status == 'draft' and instance.proposal_status == 'pending':
|
||||||
|
if isinstance(instance, EventProposal):
|
||||||
|
if not add_new_eventproposal_email(instance):
|
||||||
|
logger.error(
|
||||||
|
'Error adding event proposal email to outgoing queue for {}'.format(instance)
|
||||||
|
)
|
||||||
|
OutgoingIrcMessage.objects.create(
|
||||||
|
target=target,
|
||||||
|
message="New event proposal: {} - https://bornhack.dk/admin/program/eventproposal/{}/change/".format(
|
||||||
|
instance.title,
|
||||||
|
instance.uuid
|
||||||
|
),
|
||||||
|
timeout=timezone.now()+timedelta(minutes=10)
|
||||||
|
)
|
||||||
|
|
||||||
|
if isinstance(instance, SpeakerProposal):
|
||||||
|
if not add_new_speakerproposal_email(instance):
|
||||||
|
logger.error(
|
||||||
|
'Error adding speaker proposal email to outgoing queue for {}'.format(instance)
|
||||||
|
)
|
||||||
|
OutgoingIrcMessage.objects.create(
|
||||||
|
target=target,
|
||||||
|
message="New speaker proposal: {} - https://bornhack.dk/admin/program/speakerproposal/{}/change/".format(
|
||||||
|
instance.name,
|
||||||
|
instance.uuid
|
||||||
|
),
|
||||||
|
timeout=timezone.now()+timedelta(minutes=10)
|
||||||
|
)
|
||||||
|
|
Loading…
Reference in a new issue