def get_form_data_schema(request, domain, form_unique_id): """Get data schema One of `app_id` or `form_unique_id` is required. `app_id` is ignored if `form_unique_id` is provided. :returns: A list of data source schema definitions. A data source schema definition is a dictionary. For details on the content of the dictionary, see https://github.com/dimagi/Vellum/blob/master/src/datasources.js """ data = [] try: form, app = Form.get_form(form_unique_id, and_app=True) except ResourceConflict: raise Http404() if app.domain != domain: raise Http404() try: data.append(get_session_schema(form)) if form.requires_case() or is_usercase_in_use(domain): data.append(get_casedb_schema(form)) except Exception: logger.exception("schema error") return HttpResponseBadRequest("schema error, see log for details") data.extend( sorted(item_lists_by_domain(domain), key=lambda x: x['name'].lower()) ) kw = {} if "pretty" in request.GET: kw["indent"] = 2 return HttpResponse(json.dumps(data, **kw))
def get_form_data_schema(request, domain, app_id, form_unique_id): """Get data schema :returns: A list of data source schema definitions. A data source schema definition is a dictionary. For details on the content of the dictionary, see https://github.com/dimagi/Vellum/blob/master/src/datasources.js """ data = [] app = get_app(domain, app_id) form = app.get_form(form_unique_id) try: data.append(get_session_schema(form)) if form.requires_case() or is_usercase_in_use(domain): data.append(get_casedb_schema(form)) except AppManagerException as e: notify_exception(request, message=str(e)) return HttpResponseBadRequest( str(e) or _("There is an error in the case management of your application. " "Please fix the error to see case properties in this tree")) except Exception as e: notify_exception(request, message=str(e)) return HttpResponseBadRequest("schema error, see log for details") data.extend(item_lists_by_domain(domain)) kw = {} if "pretty" in request.GET: kw["indent"] = 2 return HttpResponse(json.dumps(data, **kw))
def get_form_data_schema(request, domain, form_unique_id): """Get data schema One of `app_id` or `form_unique_id` is required. `app_id` is ignored if `form_unique_id` is provided. :returns: A list of data source schema definitions. A data source schema definition is a dictionary. For details on the content of the dictionary, see https://github.com/dimagi/Vellum/blob/master/src/datasources.js """ data = [] try: form, app = Form.get_form(form_unique_id, and_app=True) except ResourceConflict: raise Http404() if app.domain != domain: raise Http404() try: data.append(get_session_schema(form)) if form.requires_case() or is_usercase_in_use(domain): data.append(get_casedb_schema(form)) except AppManagerException as e: notify_exception(request, message=str(e)) return HttpResponseBadRequest( str(e) or _("There is an error in the case management of your application. " "Please fix the error to see case properties in this tree") ) except Exception as e: notify_exception(request, message=six.text_type(e)) return HttpResponseBadRequest("schema error, see log for details") data.extend( sorted(item_lists_by_domain(domain), key=lambda x: x['name'].lower()) ) kw = {} if "pretty" in request.GET: kw["indent"] = 2 return HttpResponse(json.dumps(data, **kw))
def get_data_schema(request, domain, app_id=None, form_unique_id=None): """Get data schema One of `app_id` or `form_unique_id` is required. `app_id` is ignored if `form_unique_id` is provided. :returns: A list of data source schema definitions. A data source schema definition is a dictionary with the following format: ``` { "id": string (default instance id) "uri": string (instance src) "path": string (path of root nodeset, not including `instance(...)`) "name": string (human readable name) "structure": { element: { "name": string (optional human readable name) "structure": { nested-element: { ... } }, }, ref-element: { "reference": { "source": string (optional data source id, defaults to this data source) "subset": string (optional subset id) "key": string (referenced property) } }, @attribute: { }, ... }, "subsets": [ { "id": string (unique identifier for this subset) "key": string (unique identifier property name) "name": string (optional human readable name) "structure": { ... } "related": { string (relationship): string (related subset name), ... } }, ... ] } ``` A structure may contain nested structure elements. A nested element may contain one of "structure" (a concrete structure definition) or "reference" (a link to some other structure definition). Any structure item may have a human readable "name". """ data = [] if form_unique_id is None: app = get_app(domain, app_id) form = None else: try: form, app = Form.get_form(form_unique_id, and_app=True) except ResourceConflict: raise Http404() data.append(get_session_schema(form)) if app.domain != domain: raise Http404() data.append(get_casedb_schema(app)) # TODO use domain instead of app data.extend( sorted(item_lists_by_domain(domain), key=lambda x: x['name'].lower()) ) kw = {} if "pretty" in request.GET: kw["indent"] = 2 return HttpResponse(json.dumps(data, **kw))
def fixture_metadata(request, domain): """ Returns list of fixtures and metadata needed for itemsets in vellum """ return json_response(item_lists_by_domain(domain))
def fixture_metadata(request, domain): """ Returns list of fixtures and metadata needed for itemsets in vellum """ return json_response(item_lists_by_domain(domain))
def get_form_data_schema(request, domain, form_unique_id): """Get data schema One of `app_id` or `form_unique_id` is required. `app_id` is ignored if `form_unique_id` is provided. :returns: A list of data source schema definitions. A data source schema definition is a dictionary with the following format: ``` { "id": string (default instance id) "uri": string (instance src) "path": string (path of root nodeset, not including `instance(...)`) "name": string (human readable name) "structure": { element: { "name": string (optional human readable name) "structure": { nested-element: { ... } }, }, ref-element: { "reference": { "source": string (optional data source id, defaults to this data source) "subset": string (optional subset id) "key": string (referenced property) } }, @attribute: { }, ... }, "subsets": [ { "id": string (unique identifier for this subset) "key": string (unique identifier property name) "name": string (optional human readable name) "structure": { ... } "related": { string (relationship): string (related subset name), ... } }, ... ] } ``` A structure may contain nested structure elements. A nested element may contain one of "structure" (a concrete structure definition) or "reference" (a link to some other structure definition). Any structure item may have a human readable "name". """ data = [] try: form, app = Form.get_form(form_unique_id, and_app=True) except ResourceConflict: raise Http404() if app.domain != domain: raise Http404() try: data.append(get_session_schema(form)) if form and form.requires_case(): data.append(get_casedb_schema(form)) except Exception as e: return HttpResponseBadRequest(e) data.extend( sorted(item_lists_by_domain(domain), key=lambda x: x['name'].lower())) kw = {} if "pretty" in request.GET: kw["indent"] = 2 return HttpResponse(json.dumps(data, **kw))