def save(self): cf = self.obj or CustomField() self.populate_obj(cf) cf.meeting = g.meeting is_choice_field_disabled = self.custom_field_choices.flags.disabled if (cf.field_type in (CustomField.MULTI_CHECKBOX, CustomField.RADIO) and not is_choice_field_disabled): CustomFieldChoice.query.filter_by(custom_field_id=cf.id).delete() for choice in self.custom_field_choices.data: cf_choice = CustomFieldChoice(custom_field=cf) cf_choice.value = Translation(english=choice) db.session.add(cf_choice) if not cf.id: last_sort = (CustomField.query.filter_by( meeting=g.meeting).with_entities(CustomField.sort).order_by( desc(CustomField.sort)).first()) if last_sort: cf.sort = last_sort[0] + 1 db.session.add(cf) db.session.commit()
def save(self): cf = self.obj or CustomField() self.populate_obj(cf) cf.meeting = g.meeting is_choice_field_disabled = self.custom_field_choices.flags.disabled if (cf.field_type in (CustomField.MULTI_CHECKBOX, CustomField.RADIO) and not is_choice_field_disabled): CustomFieldChoice.query.filter_by(custom_field_id=cf.id).delete() for choice in self.custom_field_choices.data: cf_choice = CustomFieldChoice(custom_field=cf) cf_choice.value = Translation(english=choice) db.session.add(cf_choice) if not cf.id: last_sort = ( CustomField.query.filter_by(meeting=g.meeting) .with_entities(CustomField.sort) .order_by(desc(CustomField.sort)) .first()) if last_sort: cf.sort = last_sort[0] + 1 db.session.add(cf) db.session.commit()
def _add_choice_values_for_custom_field(custom_field, choices): """Adds CustomFieldChoices for CustomField.""" for value, label in (choices or []): custom_field_choice = CustomFieldChoice(custom_field=custom_field) custom_field_choice.value = Translation(english=value) db.session.add(custom_field_choice)