def _set_document(self, document): DataObject._set_document(self, document) # make form_model level fields for any json fields in to for json_field in document.json_fields: f = field.create_question_from(json_field, self._dbm) self._form_fields.append(f)
def __init__(self, dbm, reminder=None, sent_status=None, number_of_sms=None, date=None, project_id=None, to_number=""): DataObject.__init__(self, dbm) if reminder is not None: if reminder.reminder_mode == ReminderMode.ON_DEADLINE: reminder_mode = self._format_string_before_saving( reminder.reminder_mode) else: reminder_mode = str( reminder.day ) + ' days ' + self._format_string_before_saving( reminder.reminder_mode) doc = ReminderLogDocument( reminder_id=reminder.id, project_id=project_id, sent_status=sent_status, number_of_sms=number_of_sms, date=date, message=reminder.message, remind_to=self._format_string_before_saving(to_number), reminder_mode=reminder_mode) DataObject._set_document(self, doc)
def __init__(self, dbm, name=None, slug=None, primitive_type=None, description=None, constraints=None, tags=None, id=None, **kwargs): """Create a new DataDictType. This represents a type of data that can be used to coordinate data collection and interoperability. """ assert isinstance(dbm, DatabaseManager) assert name is None or is_string(name) assert slug is None or is_string(slug) assert primitive_type is None or is_string(primitive_type) assert description is None or is_string(description) assert constraints is None or isinstance(constraints, dict) # how to assert any kwargs? DataObject.__init__(self, dbm) # Are we being constructed from an existing doc? if name is None: return # Not made from existing doc, so create a new one doc = DataDictDocument(id, primitive_type, constraints, slug, name, description, tags, **kwargs) self._set_document(doc)
def __init__(self, dbm, name=None, label=None, form_code=None, fields=None, entity_type=None, type=None, language="eng", state=attributes.ACTIVE_STATE): assert isinstance(dbm, DatabaseManager) assert name is None or is_not_empty(name) assert fields is None or is_sequence(fields) assert form_code is None or (is_string(form_code) and is_not_empty(form_code)) assert type is None or is_not_empty(type) assert entity_type is None or is_sequence(entity_type) DataObject.__init__(self, dbm) self._form_fields = [] self.errors = [] # Are we being constructed from scratch or existing doc? if name is None: return # Not made from existing doc, so build ourselves up self._form_fields = fields self.validate_fields() doc = FormModelDocument() doc.name = name doc.add_label(language, label) doc.form_code = form_code doc.entity_type = entity_type doc.type = type doc.state = state doc.active_languages = language DataObject._set_document(self, doc)
def _set_doc(self, form_code, is_registration_model, label, language, name): doc = EntityFormModelDocument() doc.name = name doc.set_label(label) doc.form_code = form_code doc.active_languages = [language] doc.is_registration_model = is_registration_model DataObject._set_document(self, doc)
def __init__(self, dbm, attachment_name=None, attachment_size=None, questionnaire_id=None, is_preview=False): DataObject.__init__(self, dbm) doc = MediaDocument(attachment_name=attachment_name, attachment_size=attachment_size, questionnaire_id=questionnaire_id, is_preview=is_preview) DataObject._set_document(self, doc)
def __init__(self, dbm, transport_info=None, form_model_id=None, form_model_revision=None, values=None, owner_uid=None, admin_id=None, response=None): DataObject.__init__(self, dbm) self.response = response if transport_info is not None: doc = SurveyResponseDocument(channel=transport_info.transport, destination=transport_info.destination, form_model_id=form_model_id, form_model_revision=form_model_revision, values=values, status=False, error_message="", owner_uid=owner_uid, modified_by_id=admin_id) DataObject._set_document(self, doc)
def __init__(self, dbm, org_id=None, entity_type=None, share_token=None, fallback_location=None, **kwargs): super(EntityPreference, self).__init__(dbm) doc = EntityPreferenceDocument() doc.org_id = org_id doc.entity_type = entity_type doc.share_token = share_token doc.fallback_location = fallback_location DataObject._set_document(self, doc)
def _set_document(self, document): DataObject._set_document(self, document) # make form_model level fields for any json fields in to for json_field in document.json_fields: f = field.create_question_from(json_field, self._dbm) self._form_fields.append(f) for validator_json in document.validators: validator = validator_factory(validator_json) if validator not in self.validators: self.validators.append(validator) if hasattr(document, 'snapshots'): for key, value in document.snapshots.items(): self._snapshots[key] = [] for each in value: f = field.create_question_from(each, self._dbm) self._snapshots[key].append(f)
def __init__(self, dbm, name=None, label=None, form_code=None, fields=None, language="en", is_registration_model=False, validators=None, enforce_unique_labels=True): if not validators: validators = [MandatoryValidator()] assert isinstance(dbm, DatabaseManager) assert name is None or is_not_empty(name) assert fields is None or is_sequence(fields) assert form_code is None or (is_string(form_code) and is_not_empty(form_code)) # assert type is None or is_not_empty(type) DataObject.__init__(self, dbm) self.xform_model = None self._old_doc = None self._snapshots = {} self._form_fields = [] self.errors = [] self.validators = validators self._enforce_unique_labels = enforce_unique_labels self._validation_exception = [] # Are we being constructed from scratch or existing doc? if name is None: return # Not made from existing doc, so build ourselves up self._validate_fields(fields) self._form_fields = fields self._set_doc(form_code, is_registration_model, label, language, name)
def __init__(self, dbm, **kwargs): super(EntityReportConfig, self).__init__(dbm) DataObject._set_document(self, EntityReportConfigDocument())
def save(self): # convert fields to json fields before save if self._doc.rev is None: self._check_if_form_code_is_unique(self.form_code) self._doc.json_fields = [f._to_json() for f in self._form_fields] return DataObject.save(self)
def __init__(self, dbm, user_id=None, project_ids=[]): super(UserPermission, self).__init__(dbm) doc = UserPermissionDocument() doc.user_id = user_id doc.project_ids = project_ids DataObject._set_document(self, doc)
def __init__(self, dbm, user_id=None, project_id=None, **kwargs): super(UserQuestionnairePreference, self).__init__(dbm) doc = UserQuestionnairePreferenceDocument() doc.user_id = user_id doc.project_id = project_id DataObject._set_document(self, doc)
def __init__(self, dbm, name=None, questionnaires=None, **kwargs): super(ReportConfig, self).__init__(dbm) DataObject._set_document(self, ReportConfigDocument()) self._create_new_report_config_doc(name, questionnaires)