Created
July 20, 2017 18:42
-
-
Save frankjwu/e80f543c41d3da121594934b405cd300 to your computer and use it in GitHub Desktop.
Form/FormInstance versioning
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
class VisitSchema(): | |
... | |
forms = fields.Method('forms_data') | |
@staticmethod | |
def forms_data(visit): | |
forms = [] | |
for form in visit.forms_versioned: | |
# Full implementation would need another level for the form_fields | |
form_data = FormSummarySchema().dump(form).data | |
form_data['formSections'] = FormSectionSummarySchema().dump( | |
visit.form_sections_versioned(form.id), many=True).data | |
forms.append(form_data) | |
return forms | |
class FormSchema(): | |
# Would be very similar, except that the visit object would need to be passed down and retrieved via context |
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
class Visit(): | |
... | |
@hybrid_property | |
def forms_versioned(self): | |
from .forms import PilotForm | |
FormVersion = version_class(PilotForm) | |
return _versioned_query(FormVersion.query.filter_by(visit_def_id=self.visit_def_id), | |
FormVersion, | |
self._protocol_amendment).all() | |
def form_sections_versioned(self, form_id): | |
from .forms import PilotFormSection | |
FormSectionVersion = version_class(PilotFormSection) | |
return _versioned_query(FormSectionVersion.query.filter_by(form_id=form_id), | |
FormSectionVersion, | |
self._protocol_amendment).all() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment