def download_xform(request, survey_id): interviewer = request.user survey = get_object_or_404(Survey, pk=survey_id) allocation = get_survey_allocation(interviewer) if allocation: try: if survey.has_sampling and allocation.stage in [None, SurveyAllocation.LISTING]: if allocation.stage is None: allocation.stage = SurveyAllocation.LISTING allocation.save() survey_listing = SurveyHouseholdListing.get_or_create_survey_listing(interviewer, survey) survey_xform = get_household_list_xform(interviewer, survey, survey_listing.listing) else: survey_xform = get_survey_xform(interviewer, survey) form_id = '%s'% survey_id audit = { "xform": form_id } audit_log( Actions.FORM_XML_DOWNLOADED, request.user, interviewer, _("'%(interviewer)s' Downloaded XML for form '%(id_string)s'.") % { "interviewer": interviewer.name, "id_string": form_id }, audit, request) response = response_with_mimetype_and_name('xml', 'survey-%s' %survey_id, show_date=False, full_mime='text/xml') response.content = survey_xform return response except: raise print 'an error occurred' pass return OpenRosaResponseNotFound()
def download_houselist_xform(request): interviewer = request.user allocation = get_survey_allocation(interviewer) response = OpenRosaResponseNotFound() if allocation: survey = allocation.survey survey_listing = SurveyHouseholdListing.get_or_create_survey_listing(interviewer, survey) householdlist_xform = get_household_list_xform(interviewer, survey, survey_listing.listing) form_id = 'allocation-%s'% allocation.id audit = { "xform": form_id } audit_log( Actions.FORM_XML_DOWNLOADED, request.user, interviewer, _("'%(interviewer)s' Downloaded XML for form '%(id_string)s'.") % { "interviewer": interviewer.name, "id_string": form_id }, audit, request) response = response_with_mimetype_and_name('xml', 'household_listing-%s' % survey.pk, show_date=False, full_mime='text/xml') response.content = householdlist_xform return response