def submit_app_data_drilldown_form(request, domain): if json.loads(request.POST.get('is_deid')): raise Http404() model_type = request.POST.get('model_type') permissions = ExportsPermissionsManager(model_type, domain, request.couch_user) permissions.access_list_exports_or_404(is_deid=False) form_data = json.loads(request.POST.get('form_data')) is_daily_saved_export = json.loads( request.POST.get('is_daily_saved_export')) is_feed = json.loads(request.POST.get('is_feed')) create_form = CreateExportTagForm(permissions.has_form_export_permissions, permissions.has_case_export_permissions, form_data) if not create_form.is_valid(): return json_response({ 'success': False, 'error': _("The form did not validate."), }) from corehq.apps.export.views.new import ( CreateNewCaseFeedView, CreateNewCustomCaseExportView, CreateNewCustomFormExportView, CreateNewDailySavedCaseExport, CreateNewDailySavedFormExport, CreateNewFormFeedView, ) if is_daily_saved_export: if create_form.cleaned_data['model_type'] == "case": export_tag = create_form.cleaned_data['case_type'] cls = CreateNewCaseFeedView if is_feed else CreateNewDailySavedCaseExport else: export_tag = create_form.cleaned_data['form'] cls = CreateNewFormFeedView if is_feed else CreateNewDailySavedFormExport elif model_type == 'form': export_tag = create_form.cleaned_data['form'] cls = CreateNewCustomFormExportView elif model_type == 'case': export_tag = create_form.cleaned_data['case_type'] cls = CreateNewCustomCaseExportView url_params = '?export_tag="{}"'.format(export_tag) app_id = create_form.cleaned_data['application'] if app_id != ApplicationDataRMIHelper.UNKNOWN_SOURCE: url_params += '&app_id={}'.format(app_id) return json_response({ 'success': True, 'url': reverse(cls.urlname, args=[domain]) + url_params, })
def test_required_fields(self): # Confirm that form cannot be submitted without case_type when model_type is case data = { 'model_type': 'case', 'app_type': "application", 'application': "fdksajhfjkqwf", } form = CreateExportTagForm(True, True, data) # Missing case_type self.assertFalse(form.is_valid())
def test_required_fields(self): # Confirm that form cannot be submitted without case_type when model_type is case data = { 'model_type': 'case', 'app_type': "application", 'application': "fdksajhfjkqwf", } form = CreateExportTagForm(True, True, data) # Missing case_type self.assertFalse(form.is_valid())
def submit_app_data_drilldown_form(request, domain): if json.loads(request.POST.get('is_deid')): raise Http404() model_type = request.POST.get('model_type') permissions = ExportsPermissionsManager(model_type, domain, request.couch_user) permissions.access_list_exports_or_404(is_deid=False) form_data = json.loads(request.POST.get('form_data')) is_daily_saved_export = json.loads(request.POST.get('is_daily_saved_export')) is_feed = json.loads(request.POST.get('is_feed')) create_form = CreateExportTagForm( permissions.has_form_export_permissions, permissions.has_case_export_permissions, form_data ) if not create_form.is_valid(): return json_response({ 'success': False, 'error': _("The form did not validate."), }) from corehq.apps.export.views.new import ( CreateNewCaseFeedView, CreateNewCustomCaseExportView, CreateNewCustomFormExportView, CreateNewDailySavedCaseExport, CreateNewDailySavedFormExport, CreateNewFormFeedView, ) if is_daily_saved_export: if create_form.cleaned_data['model_type'] == "case": export_tag = create_form.cleaned_data['case_type'] cls = CreateNewCaseFeedView if is_feed else CreateNewDailySavedCaseExport else: export_tag = create_form.cleaned_data['form'] cls = CreateNewFormFeedView if is_feed else CreateNewDailySavedFormExport elif model_type == 'form': export_tag = create_form.cleaned_data['form'] cls = CreateNewCustomFormExportView elif model_type == 'case': export_tag = create_form.cleaned_data['case_type'] cls = CreateNewCustomCaseExportView url_params = '?export_tag="{}"'.format(export_tag) app_id = create_form.cleaned_data['application'] if app_id != ApplicationDataRMIHelper.UNKNOWN_SOURCE: url_params += '&app_id={}'.format(app_id) return json_response({ 'success': True, 'url': reverse(cls.urlname, args=[domain]) + url_params, })
def test_static_model_type(self): # Confirm that model_type is cleaned according to export permissions data = { 'model_type': 'form', # This should be switch to case in the cleaned_data 'app_type': 'application', 'application': 'asdfjwkeghrk', "case_type": "my_case_type" } form = CreateExportTagForm(has_form_export_permissions=False, has_case_export_permissions=True, data=data) self.assertTrue(form.is_valid()) self.assertEqual(form.cleaned_data['model_type'], 'case')
def test_static_model_type(self): # Confirm that model_type is cleaned according to export permissions data = { 'model_type': 'form', # This should be switch to case in the cleaned_data 'app_type': 'application', 'application': 'asdfjwkeghrk', "case_type": "my_case_type" } form = CreateExportTagForm( has_form_export_permissions=False, has_case_export_permissions=True, data=data ) self.assertTrue(form.is_valid()) self.assertEqual(form.cleaned_data['model_type'], 'case')