Created
April 19, 2017 14:35
-
-
Save pferreir/5ca4887ce83ea512aae6297892ae04b6 to your computer and use it in GitHub Desktop.
regform_fix.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from sqlalchemy.orm.attributes import flag_modified | |
import uuid | |
lst = [] | |
for reg_item in RegistrationFormItem.find(input_type='accommodation', is_deleted=False): | |
choice_id = unicode(uuid.uuid4()) | |
needs_caption = False | |
for rffd in RegistrationFormFieldData.find(field_id=reg_item.id): | |
if not any(('is_no_accommodation' in choice) for choice in rffd.versioned_data['choices']): | |
print reg_item.registration_form, reg_item, rffd, not reg_item.is_required | |
lst.append((reg_item.registration_form, reg_item, rffd, not reg_item.is_required)) | |
needs_caption = True | |
no_acc_choice = {"is_no_accommodation": True, | |
"is_enabled": not reg_item.is_required, | |
"price": 0, | |
"is_billable": False, | |
"places_limit": 0, | |
"placeholder": "Title of the \"None\" option", | |
"id": choice_id} | |
rffd.versioned_data['choices'].append(no_acc_choice) | |
flag_modified(rffd, 'versioned_data') | |
if needs_caption: | |
reg_item.data['captions'][choice_id] = 'No accommodation' | |
flag_modified(reg_item, 'data') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment