def test_missing_fields(self): data = { 'date_range': 'range', 'start_date': '1992-01-30', } form = DashboardFeedFilterForm(DomainObject([], 'my-domain'), data=data) self.assertFalse(form.is_valid())
def test_good_data(self): data = { 'date_range': 'range', 'start_date': '1992-01-30', 'end_date': '2016-10-01', } form = DashboardFeedFilterForm(DomainObject([], 'my-domain'), data=data) self.assertTrue(form.is_valid())
def test_bad_dates(self): data = { 'date_range': 'range', 'start_date': '1992-01-30', 'end_date': 'banana', } form = DashboardFeedFilterForm(FakeDomainObject([], 'my-domain'), data=data) self.assertFalse(form.is_valid())
def commit_filters(request, domain): permissions = ExportsPermissionsManager(request.POST.get('model_type'), domain, request.couch_user) if not permissions.has_edit_permissions: raise Http404 export_id = request.POST.get('export_id') form_data = json.loads(request.POST.get('form_data')) export = get_properly_wrapped_export_instance(export_id) if export.is_daily_saved_export and not domain_has_privilege( domain, DAILY_SAVED_EXPORT): raise Http404 if export.export_format == "html" and not domain_has_privilege( domain, EXCEL_DASHBOARD): raise Http404 if export.is_odata_config and not domain_has_privilege(domain, ODATA_FEED): raise Http404 if not export.filters.is_location_safe_for_user(request): return location_restricted_response(request) domain_object = Domain.get_by_name(domain) filter_form = DashboardFeedFilterForm(domain_object, form_data, couch_user=request.couch_user) if filter_form.is_valid(): old_can_access_all_locations = export.filters.can_access_all_locations old_accessible_location_ids = export.filters.accessible_location_ids filters = filter_form.to_export_instance_filters( # using existing location restrictions prevents a less restricted user from modifying # restrictions on an export that a more restricted user created (which would mean the more # restricted user would lose access to the export) old_can_access_all_locations, old_accessible_location_ids, export.type) if export.filters != filters: export.filters = filters export.save() if export.is_daily_saved_export: rebuild_saved_export(export_id, manual=True) return json_response({ 'success': True, 'locationRestrictions': ExportListHelper.get_location_restriction_names( export.filters.accessible_location_ids), }) else: return json_response({ 'success': False, 'error': _("Problem saving dashboard feed filters: Invalid form"), })
def commit_filters(request, domain): permissions = ExportsPermissionsManager(request.POST.get('model_type'), domain, request.couch_user) if not permissions.has_edit_permissions: raise Http404 export_id = request.POST.get('export_id') form_data = json.loads(request.POST.get('form_data')) export = get_properly_wrapped_export_instance(export_id) if export.is_daily_saved_export and not domain_has_privilege(domain, DAILY_SAVED_EXPORT): raise Http404 if export.export_format == "html" and not domain_has_privilege(domain, EXCEL_DASHBOARD): raise Http404 if not export.filters.is_location_safe_for_user(request): return location_restricted_response(request) domain_object = Domain.get_by_name(domain) filter_form = DashboardFeedFilterForm(domain_object, form_data) if filter_form.is_valid(): old_can_access_all_locations = export.filters.can_access_all_locations old_accessible_location_ids = export.filters.accessible_location_ids filters = filter_form.to_export_instance_filters( # using existing location restrictions prevents a less restricted user from modifying # restrictions on an export that a more restricted user created (which would mean the more # restricted user would lose access to the export) old_can_access_all_locations, old_accessible_location_ids, export.type ) if export.filters != filters: export.filters = filters export.save() rebuild_saved_export(export_id, manual=True) return json_response({ 'success': True, }) else: return json_response({ 'success': False, 'error': _("Problem saving dashboard feed filters: Invalid form"), })
def page_context(self): context = super(DailySavedExportListView, self).page_context model_type = None if self.permissions.has_form_export_permissions and not self.permissions.has_case_export_permissions: model_type = "form" if not self.permissions.has_form_export_permissions and self.permissions.has_case_export_permissions: model_type = "case" context.update({ "is_daily_saved_export": True, "model_type": model_type, "static_model_type": False, "export_filter_form": DashboardFeedFilterForm( self.domain_object, ) }) return context
def _get_daily_saved_export_metadata(self, export): """ Return a dictionary containing details about an emailed export. This will eventually be passed to javascript. """ has_file = export.has_file() file_data = {} if has_file: download_url = self.request.build_absolute_uri( reverse('download_daily_saved_export', args=[self.domain, export._id])) file_data = self._fmt_emailed_export_fileData( export._id, export.file_size, export.last_updated, export.last_accessed, download_url) location_restrictions = [] locations = [] filters = export.filters if filters.accessible_location_ids: locations = SQLLocation.objects.filter( location_id__in=filters.accessible_location_ids) for location in locations: location_restrictions.append(location.display_name) return { 'groupId': None, # This can be removed when we're off legacy exports 'hasFile': has_file, 'index': None, # This can be removed when we're off legacy exports 'fileData': file_data, 'filters': DashboardFeedFilterForm.get_form_data_from_export_instance_filters( filters, self.domain, type(export)), 'isLocationSafeForUser': filters.is_location_safe_for_user(self.request), 'locationRestrictions': location_restrictions, 'taskStatus': _get_task_status_json(export._id), 'updatingData': False, }
def page_context(self): return { 'create_export_form': self.create_export_form if not self.is_deid else None, 'create_export_form_title': self.create_export_form_title if not self.is_deid else None, 'bulk_download_url': self.bulk_download_url, 'allow_bulk_export': self.allow_bulk_export, 'has_edit_permissions': self.permissions.has_edit_permissions, 'is_deid': self.is_deid, 'is_odata': self.is_odata, "export_type_caps": _("Export"), "export_type": _("export"), "export_type_caps_plural": _("Exports"), "export_type_plural": _("exports"), 'my_export_type': _('My Exports'), 'shared_export_type': _('Exports Shared with Me'), "model_type": self.form_or_case, "static_model_type": True, 'max_exportable_rows': MAX_EXPORTABLE_ROWS, 'lead_text': self.lead_text, "export_filter_form": (DashboardFeedFilterForm( self.domain_object, couch_user=self.request.couch_user, ) if self.include_saved_filters else None), 'create_url': '#createExportOptionsModal', }
def _get_daily_saved_export_metadata(self, export): """ Return a dictionary containing details about an emailed export. This will eventually be passed to javascript. """ has_file = export.has_file() file_data = {} if has_file: download_url = self.request.build_absolute_uri( reverse('download_daily_saved_export', args=[self.domain, export._id])) file_data = self._fmt_emailed_export_fileData( export._id, export.file_size, export.last_updated, export.last_accessed, download_url ) location_restrictions = [] locations = [] filters = export.filters if filters.accessible_location_ids: locations = SQLLocation.objects.filter(location_id__in=filters.accessible_location_ids) for location in locations: location_restrictions.append(location.display_name) return { 'groupId': None, # This can be removed when we're off legacy exports 'hasFile': has_file, 'index': None, # This can be removed when we're off legacy exports 'fileData': file_data, 'filters': DashboardFeedFilterForm.get_form_data_from_export_instance_filters( filters, self.domain, type(export) ), 'isLocationSafeForUser': filters.is_location_safe_for_user(self.request), 'locationRestrictions': location_restrictions, 'taskStatus': _get_task_status_json(export._id), 'updatingData': False, }
def _get_filters(self, export): if self.include_saved_filters: return DashboardFeedFilterForm.get_form_data_from_export_instance_filters( export.filters, self.domain, type(export))