def get_shared_fields(request): """ Retrieves all fields marked as shared for this org tree. :GET: Expects organization_id in the query string. Returns:: { 'status': 'success', 'shared_fields': [ { "title": Display name of field, "sort_column": database/search name of field, "class": css used for field, "title_class": css used for title, "type": data type of field, (One of: 'date', 'floor_area', 'link', 'string', 'number') "field_type": classification of field. One of: 'contact_information', 'building_information', 'assessor', 'pm', "sortable": True if buildings can be sorted on this field, } ... ], 'public_fields': [ { "title": Display name of field, "sort_column": database/search name of field, "class": css used for field, "title_class": css used for title, "type": data type of field, (One of: 'date', 'floor_area', 'link', 'string', 'number') "field_type": classification of field. One of: 'contact_information', 'building_information', 'assessor', 'pm', "sortable": True if buildings can be sorted on this field, } ... ] } """ org_id = request.GET.get("organization_id") org = Organization.objects.get(pk=org_id) result = {"status": "success", "shared_fields": [], "public_fields": []} columns = utils_get_columns(False, org_id, True)["fields"] columns = {field["sort_column"]: field for field in columns} for exportable_field in SharedBuildingField.objects.filter(org=org, field_type=INTERNAL).select_related("field"): field_name = exportable_field.field.name shared_field = columns[field_name] result["shared_fields"].append(shared_field) for exportable_field in SharedBuildingField.objects.filter(org=org, field_type=PUBLIC).select_related("field"): field_name = exportable_field.field.name shared_field = columns[field_name] result["public_fields"].append(shared_field) return result
def get_columns(request): """returns a JSON list of columns a user can select as his/her default""" is_project = request.GET.get('is_project', '') if is_project == 'true': project = Project.objects.get(slug=request.GET.get('project_slug')) is_project = project.has_compliance else: is_project = False return utils_get_columns(is_project)
def list(self, request): """ Returns a JSON list of columns a user can select as his/her default Requires the organization_id as a query parameter. This was formally /get_columns """ all_fields = request.query_params.get('all_fields', '') all_fields = True if all_fields.lower() == 'true' else False return JsonResponse( utils_get_columns(request.query_params['organization_id'], all_fields))
def shared_fields(self, request, pk=None): """ Retrieves all fields marked as shared for this org tree. DANGER! Currently broken due to class attribute name in the body, do not use! --- parameter_strategy: replace parameters: - name: pk description: Organization ID (Primary key) type: integer required: true paramType: path response_serializer: SharedFieldsActualReturnSerializer """ org_id = pk org = Organization.objects.get(pk=org_id) result = {'status': 'success', 'shared_fields': [], 'public_fields': []} columns = utils_get_columns(org_id, True)['fields'] columns = { field['sort_column']: field for field in columns } for exportable_field in SharedBuildingField.objects.filter( org=org, field_type=INTERNAL ).select_related('field'): field_name = exportable_field.field.name shared_field = columns[field_name] result['shared_fields'].append(shared_field) for exportable_field in SharedBuildingField.objects.filter( org=org, field_type=PUBLIC ).select_related('field'): field_name = exportable_field.field.name shared_field = columns[field_name] result['public_fields'].append(shared_field) return JsonResponse(result)
def get_shared_fields(request): """ Retrieves all fields marked as shared for this org tree. :GET: Expects organization_id in the query string. Returns:: { 'status': 'success', 'shared_fields': [ { "title": Display name of field, "sort_column": database/search name of field, "class": css used for field, "title_class": css used for title, "type": data type of field, (One of: 'date', 'floor_area', 'link', 'string', 'number') "field_type": classification of field. One of: 'contact_information', 'building_information', 'assessor', 'pm', "sortable": True if buildings can be sorted on this field, } ... ], 'public_fields': [ { "title": Display name of field, "sort_column": database/search name of field, "class": css used for field, "title_class": css used for title, "type": data type of field, (One of: 'date', 'floor_area', 'link', 'string', 'number') "field_type": classification of field. One of: 'contact_information', 'building_information', 'assessor', 'pm', "sortable": True if buildings can be sorted on this field, } ... ] } """ org_id = request.GET.get('organization_id') org = Organization.objects.get(pk=org_id) result = {'status': 'success', 'shared_fields': [], 'public_fields': []} columns = utils_get_columns(False, org_id, True)['fields'] columns = {field['sort_column']: field for field in columns} for exportable_field in SharedBuildingField.objects.filter( org=org, field_type=INTERNAL).select_related('field'): field_name = exportable_field.field.name shared_field = columns[field_name] result['shared_fields'].append(shared_field) for exportable_field in SharedBuildingField.objects.filter( org=org, field_type=PUBLIC).select_related('field'): field_name = exportable_field.field.name shared_field = columns[field_name] result['public_fields'].append(shared_field) return result