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 form_list(request): """ This is where ODK Collect gets its download list. """ interviewer = request.user #get_object_or_404(Interviewer, mobile_number=username, odk_token=token) #to do - Make fetching households more e allocation = get_survey_allocation(interviewer) if allocation and interviewer.ea.open_batches: audit_log(Actions.USER_FORMLIST_REQUESTED, request.user, interviewer, _("survey allocation %s" % allocation.survey), {}, request) survey = allocation.survey survey_listing = SurveyHouseholdListing.get_or_create_survey_listing(interviewer, survey) audit = {} audit_log(Actions.USER_FORMLIST_REQUESTED, request.user, interviewer, _("Requested forms list. for %s" % interviewer.name), audit, request) content = render_to_string("odk/xformsList.xml", { 'allocation' : allocation, 'survey' : survey, 'interviewer' : interviewer, 'request' : request, 'survey_listing': survey_listing, 'Const': SurveyAllocation }) response = BaseOpenRosaResponse(content) response.status_code = 200 return response else: return OpenRosaResponseNotFound('No survey allocated presently')
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