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:
parent
544d6ba07b
commit
05946d065b
|
@ -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']
|
||||||
|
|
|
@ -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()
|
||||||
|
|
Loading…
Reference in a new issue