def get(self, request, *args, **kwargs): # just copying what was in the old django view here. don't want to mess too much with exports just yet. try: export_tag = [self.domain, json.loads(request.GET.get("export_tag", "null") or "null")] except ValueError: return HttpResponseBadRequest() schema = build_latest_schema(export_tag) if not schema and self.export_helper.export_type == "form": schema = create_basic_form_checkpoint(export_tag) if schema: app_id = request.GET.get('app_id') self.export_helper.custom_export = self.export_helper.ExportSchemaClass.default( schema=schema, name="%s: %s" % ( xmlns_to_name(self.domain, export_tag[1], app_id=app_id) if self.export_helper.export_type == "form" else export_tag[1], datetime.utcnow().strftime("%Y-%m-%d") ), type=self.export_helper.export_type ) if self.export_helper.export_type in ['form', 'case']: self.export_helper.custom_export.app_id = app_id return super(BaseCreateCustomExportView, self).get(request, *args, **kwargs) messages.warning(request, _("<strong>No data found for that form " "(%s).</strong> Submit some data before creating an export!") % xmlns_to_name(self.domain, export_tag[1], app_id=None), extra_tags="html") return HttpResponseRedirect(ExcelExportReport.get_url(domain=self.domain))
def update_schema(self): """ Update the schema for this object to include the latest columns from any relevant docs. Does NOT save the doc, just updates the in-memory object. """ from couchexport.schema import build_latest_schema self.set_schema(build_latest_schema(self.index))
def get(self, request, *args, **kwargs): # just copying what was in the old django view here. don't want to mess too much with exports just yet. try: export_tag = [self.domain, json.loads(request.GET.get("export_tag", "null") or "null")] except ValueError: return HttpResponseBadRequest() if self.export_helper.export_type == "form" and not export_tag[1]: return HttpResponseRedirect(reverse(FormExportListView.urlname, args=(self.domain,))) schema = build_latest_schema(export_tag) if not schema and self.export_helper.export_type == "form": schema = create_basic_form_checkpoint(export_tag) if request.GET.get("minimal", False): # minimal mode is a HACK so that some large domains can # load this page. halp. messages.warning(request, _("Warning you are using minimal mode, some things may not be functional")) if schema: app_id = request.GET.get("app_id") self.export_helper.custom_export = self.export_helper.ExportSchemaClass.default( schema=schema, name="%s: %s" % ( xmlns_to_name(self.domain, export_tag[1], app_id=app_id) if self.export_helper.export_type == "form" else export_tag[1], json_format_date(datetime.utcnow()), ), type=self.export_helper.export_type, ) if self.export_helper.export_type in ["form", "case"]: self.export_helper.custom_export.app_id = app_id if self.export_helper.export_type == "form": self.export_helper.custom_export.update_question_schema() return super(BaseCreateCustomExportView, self).get(request, *args, **kwargs) messages.warning( request, _('<strong>No data found to export "%s".</strong> ' "Please submit data before creating this export.") % xmlns_to_name(self.domain, export_tag[1], app_id=None), extra_tags="html", ) return HttpResponseRedirect(self.export_home_url)
def custom_export(req, domain): """ Customize an export """ try: export_tag = [ domain, json.loads(req.GET.get("export_tag", "null") or "null") ] except ValueError: return HttpResponseBadRequest() helper = CustomExportHelper.make(req, domain) if req.method == "POST": helper.update_custom_export() messages.success( req, "Custom export created! You can continue editing here.") return _redirect_to_export_home(helper.export_type, domain, ajax=True) schema = build_latest_schema(export_tag) if schema: app_id = req.GET.get('app_id') helper.custom_export = helper.ExportSchemaClass.default( schema=schema, name="%s: %s" % (xmlns_to_name(domain, export_tag[1], app_id=app_id) if helper.export_type == "form" else export_tag[1], datetime.utcnow().strftime("%Y-%m-%d")), type=helper.export_type) if helper.export_type == 'form': helper.custom_export.app_id = app_id return helper.get_response() else: messages.warning(req, "<strong>No data found for that form " "(%s).</strong> Submit some data before creating an export!" % \ xmlns_to_name(domain, export_tag[1], app_id=None), extra_tags="html") return HttpResponseRedirect( export.ExcelExportReport.get_url(domain=domain))
def get(self, request, *args, **kwargs): # just copying what was in the old django view here. don't want to mess too much with exports just yet. try: export_tag = [self.domain, json.loads(request.GET.get("export_tag", "null") or "null")] except ValueError: return HttpResponseBadRequest() if self.export_helper.export_type == "form" and not export_tag[1]: return HttpResponseRedirect(ExcelExportReport.get_url(domain=self.domain)) schema = build_latest_schema(export_tag) if not schema and self.export_helper.export_type == "form": schema = create_basic_form_checkpoint(export_tag) if request.GET.get('minimal', False): messages.warning(request, _("Warning you are using minimal mode, some things may not be functional")) if schema: app_id = request.GET.get('app_id') self.export_helper.custom_export = self.export_helper.ExportSchemaClass.default( schema=schema, name="%s: %s" % ( xmlns_to_name(self.domain, export_tag[1], app_id=app_id) if self.export_helper.export_type == "form" else export_tag[1], json_format_date(datetime.utcnow()) ), type=self.export_helper.export_type ) if self.export_helper.export_type in ['form', 'case']: self.export_helper.custom_export.app_id = app_id if self.export_helper.export_type == 'form': self.export_helper.custom_export.update_question_schema() return super(BaseCreateCustomExportView, self).get(request, *args, **kwargs) messages.warning(request, _("<strong>No data found for that form " "(%s).</strong> Submit some data before creating an export!") % xmlns_to_name(self.domain, export_tag[1], app_id=None), extra_tags="html") return HttpResponseRedirect(ExcelExportReport.get_url(domain=self.domain))
def custom_export(req, domain): """ Customize an export """ try: export_tag = [domain, json.loads(req.GET.get("export_tag", "null") or "null")] except ValueError: return HttpResponseBadRequest() helper = CustomExportHelper(req, domain) if req.method == "POST": helper.update_custom_export() helper.custom_export.save() messages.success(req, "Custom export created! You can continue editing here.") return HttpResponseRedirect("%s?type=%s" % (reverse("edit_custom_export", args=[domain, helper.custom_export.get_id]), helper.export_type)) schema = build_latest_schema(export_tag) if schema: app_id = req.GET.get('app_id') helper.custom_export = helper.ExportSchemaClass.default( schema=schema, name="%s: %s" % ( xmlns_to_name(domain, export_tag[1], app_id=app_id) if helper.export_type == "form" else export_tag[1], datetime.utcnow().strftime("%Y-%m-%d") ), type=helper.export_type ) if helper.export_type == 'form': helper.custom_export.app_id = app_id return helper.get_response() else: messages.warning(req, "<strong>No data found for that form " "(%s).</strong> Submit some data before creating an export!" % \ xmlns_to_name(domain, export_tag[1], app_id=None), extra_tags="html") return HttpResponseRedirect(export.ExcelExportReport.get_url(domain))