fix issue with approving eventproposal with unapproved speakers

This commit fixes some issues around approving eventproposals with no
speakers attached or unapproved speakers attached.
This commit is contained in:
Stephan Telling 2017-07-15 16:48:30 +02:00
parent 544d6ba07b
commit 05946d065b
No known key found for this signature in database
GPG key ID: D4892289F36ADA9B
2 changed files with 32 additions and 4 deletions

View file

@ -1,6 +1,20 @@
from django.contrib import admin from django.contrib import (
admin,
messages
)
from django.core.exceptions import ValidationError
from .models import Event, Speaker, EventType, EventInstance, EventLocation, SpeakerProposal, EventProposal, Favorite
from .models import (
Event,
Speaker,
EventType,
EventInstance,
EventLocation,
SpeakerProposal,
EventProposal,
Favorite
)
@admin.register(SpeakerProposal) @admin.register(SpeakerProposal)
@ -18,7 +32,18 @@ class SpeakerProposalAdmin(admin.ModelAdmin):
class EventProposalAdmin(admin.ModelAdmin): class EventProposalAdmin(admin.ModelAdmin):
def mark_eventproposal_as_approved(self, request, queryset): def mark_eventproposal_as_approved(self, request, queryset):
for ep in queryset: for ep in queryset:
if not ep.speakers.all():
messages.error(
request,
'Event cant be approved as it has no speaker(s).'
)
return False
else:
try:
ep.mark_as_approved() ep.mark_as_approved()
except ValidationError as e:
messages.error(request, e)
return False
mark_eventproposal_as_approved.description = 'Approve and create Event object(s)' mark_eventproposal_as_approved.description = 'Approve and create Event object(s)'
actions = ['mark_eventproposal_as_approved'] actions = ['mark_eventproposal_as_approved']

View file

@ -9,6 +9,7 @@ from datetime import timedelta
from django.contrib.postgres.fields import DateTimeRangeField from django.contrib.postgres.fields import DateTimeRangeField
from django.contrib import messages from django.contrib import messages
from django.db import models from django.db import models
from django.core.exceptions import ObjectDoesNotExist
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.utils import timezone
@ -278,8 +279,10 @@ class EventProposal(UserSubmittedModel):
event.save() event.save()
# loop through the speakerproposals linked to this eventproposal and associate any related speaker objects with this event # loop through the speakerproposals linked to this eventproposal and associate any related speaker objects with this event
for sp in self.speakers.all(): for sp in self.speakers.all():
if sp.speaker: try:
event.speakers.add(sp.speaker) event.speakers.add(sp.speaker)
except ObjectDoesNotExist:
raise ValidationError('Not all speakers are approved or created yet.')
self.proposal_status = eventproposalmodel.PROPOSAL_APPROVED self.proposal_status = eventproposalmodel.PROPOSAL_APPROVED
self.save() self.save()