def commit(self): if not self.is_validated(): return False poll = self.poll or PollRepository().create() poll.title = self.title.value poll.question = self.question.value poll.multiple = self.multiple.value poll.end_date = self.end_date.value + ONE_DAY # insert/update choices polls_to_delete = [] for idx, choice_property in enumerate(self.choices): choice_label = choice_property.value if choice_label: choice = poll.choices[idx] if idx < len( poll.choices) else PollChoiceData(poll=poll) choice.label = choice_label else: if idx < len(poll.choices): polls_to_delete.append(poll.choices[idx].id) # delete choices for id in polls_to_delete: for choice in poll.choices: if choice.id == id: choice.delete() return True
def poll(self): return PollRepository().get_by_id(self.id)
def __init__(self): self.poll_repository = PollRepository() self.content = component.Component(None)