use hasattr() and clean up urls

This commit is contained in:
Thomas Steen Rasmussen 2018-07-24 19:02:58 +02:00
parent cf9e9ebd5a
commit 016ac8adac

View file

@ -376,10 +376,10 @@ class EventProposal(UserSubmittedModel):
eventmodel = apps.get_model('program', 'event') eventmodel = apps.get_model('program', 'event')
eventproposalmodel = apps.get_model('program', 'eventproposal') eventproposalmodel = apps.get_model('program', 'eventproposal')
# use existing event if we have one # use existing event if we have one
if self.event: if not hasattr(self, 'event'):
event = self.event
else:
event = eventmodel() event = eventmodel()
else:
event = self.event
event.track = self.track event.track = self.track
event.title = self.title event.title = self.title
event.abstract = self.abstract event.abstract = self.abstract
@ -392,6 +392,8 @@ class EventProposal(UserSubmittedModel):
try: try:
event.speakers.add(sp.speaker) event.speakers.add(sp.speaker)
except ObjectDoesNotExist: except ObjectDoesNotExist:
# clean up
event.urls.clear()
event.delete() event.delete()
raise ValidationError('Not all speakers are approved or created yet.') raise ValidationError('Not all speakers are approved or created yet.')