Views Package

Submodules

Accounts

APIs

seed.views.api.get_api_schema(self, request, *args, **kwargs)

Returns a hash of all API endpoints and their descriptions.

Returns:

{
    '/example/url/here': {
        'name': endpoint name,
        'description': endpoint description
    }...
}

Todo

Format docstrings better.

Main

:copyright (c) 2014 - 2022, The Regents of the University of California, through Lawrence Berkeley National Laboratory (subject to receipt of any required approvals from the U.S. Department of Energy) and contributors. All rights reserved. :author

seed.views.main.angular_js_tests(request)

Jasmine JS unit test code covering AngularJS unit tests

seed.views.main.delete_file(self, request, *args, **kwargs)

Deletes an ImportFile from a dataset.

Payload:

{
    "file_id": "ImportFile id",
    "organization_id": "current user organization id as integer"
}

Returns:

{
    'status': 'success' or 'error',
    'message': 'error message, if any'
}
seed.views.main.delete_organization_inventory(self, request, *args, **kwargs)

Starts a background task to delete all properties & taxlots in an org.

DELETE

Expects ‘org_id’ for the organization.

Returns:

{
    'status': 'success' or 'error',
    'progress_key': ID of background job, for retrieving job progress
}
seed.views.main.error404(request, exception)
seed.views.main.error500(request)
seed.views.main.get_default_building_detail_columns(self, request, *args, **kwargs)

Get default columns for building detail view.

front end is expecting a JSON object with an array of field names

Returns:

{
    "columns": ["project_id", "name", "gross_floor_area"]
}
seed.views.main.home(request)

the main view for the app Sets in the context for the django template:

  • app_urls: a json object of all the URLs that is loaded in the JS global namespace

  • username: the request user’s username (first and last name)

seed.views.main.public_search(request)

The public API unauthenticated endpoint

seed.views.main.set_default_building_detail_columns(self, request, *args, **kwargs)
seed.views.main.set_default_columns(self, request, *args, **kwargs)
seed.views.main.version(self, request, *args, **kwargs)

Returns the SEED version and current git sha

Meters

class seed.views.meters.MeterViewSet(**kwargs)

Bases: rest_framework.viewsets.ViewSet

greenbutton_parsed_meters_confirmation(request)
parsed_meters_confirmation(request)
property_meter_usage(request)
property_meters(request)
valid_types_units(request)

Projects

:copyright (c) 2014 - 2022, The Regents of the University of California, through Lawrence Berkeley National Laboratory (subject to receipt of any required approvals from the U.S. Department of Energy) and contributors. All rights reserved. :author

class seed.views.projects.ProjectViewSet(**kwargs)

Bases: seed.decorators.DecoratorMixin.<locals>.Mixin, rest_framework.viewsets.ModelViewSet

ProjectViewModels = {'property': <class 'seed.models.projects.ProjectPropertyView'>, 'taxlot': <class 'seed.models.projects.ProjectTaxLotView'>}
ViewModels = {'property': <class 'seed.models.properties.PropertyView'>, 'taxlot': <class 'seed.models.tax_lots.TaxLotView'>}
add(request, pk)

Add inventory to project :PUT: Expects organization_id in query string. — parameters:

  • name: organization_id description: ID of organization to associate new project with type: integer required: true

  • name: inventory_type description: type of inventory to add: ‘property’ or ‘taxlot’ type: string required: true paramType: query

  • name: project slug or pk description: The project slug identifier or primary key for this project required: true paramType: path

  • name: selected description: ids of property or taxlot views to add type: array[int] required: true

Returns:
{

‘status’: ‘success’, ‘added’: [list of property/taxlot view ids added]

}

copy(request, pk)

Copy inventory from one project to another

PUT

Expects organization_id in query string.

— parameter_strategy: replace parameters:

  • name: organization_id description: The organization_id for this user’s organization required: true type: integer paramType: query

  • name: inventory_type description: type of inventory to add: ‘property’ or ‘taxlot’ required: true type: string paramType: query

  • name: target type: string or int description: target project slug/id to move/copy to. required: true

  • name: selected description: JSON array, list of property/taxlot views to be transferred paramType: array[int] required: true

count(request)

Returns the number of projects within the org tree to which a user belongs. Counts projects in parent orgs and sibling orgs.

GET

Expects organization_id in query string.

— parameters:

  • name: organization_id description: The organization_id for this user’s organization required: true paramType: query

type:
status:

type: string description: success, or error

count:

type: integer description: number of projects

create(request)

Creates a new project

POST

Expects organization_id in query string.

— parameters:

  • name: organization_id description: ID of organization to associate new project with type: integer required: true paramType: query

  • name: name description: name of the new project type: string required: true

  • name: is_compliance description: add compliance data if true type: bool required: true

  • name: compliance_type description: description of type of compliance type: string required: true if is_compliance else false

  • name: description description: description of new project type: string required: true if is_compliance else false

  • name: end_date description: Timestamp for when project ends type: string required: true if is_compliance else false

  • name: deadline_date description: Timestamp for compliance deadline type: string required: true if is_compliance else false

Returns::
{

‘status’: ‘success’, ‘project’: {

‘id’: project’s primary key, ‘name’: project’s name, ‘slug’: project’s identifier, ‘status’: ‘active’, ‘number_of_buildings’: Count of buildings associated with project ‘last_modified’: Timestamp when project last changed ‘last_modified_by’: {

‘first_name’: first name of user that made last change, ‘last_name’: last name, ‘email’: email address,

}, ‘is_compliance’: True if project is a compliance project, ‘compliance_type’: Description of compliance type, ‘deadline_date’: Timestamp of when compliance is due, ‘end_date’: Timestamp of end of project, ‘property_count’: 0, ‘taxlot_count’: 0,

}

}

destroy(request, pk)

Delete a project.

DELETE

Expects organization_id in query string.

— parameter_strategy: replace parameters:

  • name: organization_id description: The organization_id for this user’s organization required: true paramType: query

  • name: project slug or pk description: The project slug identifier or primary key for this project required: true paramType: path

Returns::
{

‘status’: ‘success’,

}

get_error(error, key=None, val=None)

Return error message and corresponding http status code.

get_key(pk)

Determine where to use slug or pk to identify project.

get_organization()

Get org id from query param or request.user.

get_params(keys)

Get required params from post etc body.

Returns dict of params and list of missing params.

get_project(key, pk)

Get project for view.

get_queryset()

Get the list of items for this view. This must be an iterable, and may be a queryset. Defaults to using self.queryset.

This method should always be used rather than accessing self.queryset directly, as self.queryset gets evaluated only once, and those results are cached for all subsequent requests.

You may want to override this if you need to provide different querysets depending on the incoming request.

(Eg. return a list of items that is specific to the user)

get_status(status)

Get status from string or int

list(request)

Retrieves all projects for a given organization.

GET

Expects organization_id in query string.

parameters:
  • name: organization_id description: The organization_id for this user’s organization required: true paramType: query

Returns:

{
    'status': 'success',
    'projects': [
        {
            'id': project's primary key,
            'name': project's name,
            'slug': project's identifier,
            'status': 'active',
            'number_of_buildings': Count of buildings associated with project
            'last_modified': Timestamp when project last changed
            'last_modified_by': {
                'first_name': first name of user that made last change,
                'last_name': last name,
                'email': email address,
            },
            'is_compliance': True if project is a compliance project,
            'compliance_type': Description of compliance type,
            'deadline_date': Timestamp of when compliance is due,
            'end_date': Timestamp of end of project,
            'property_count': number of property views associated with project,
            'taxlot_count':  number of taxlot views associated with project,
        }...
    ]
}
move(request, pk)

Move inventory from one project to another

PUT

Expects organization_id in query string.

— parameter_strategy: replace parameters:

  • name: organization_id description: The organization_id for this user’s organization required: true type: integer paramType: query

  • name: inventory_type description: type of inventory to add: ‘property’ or ‘taxlot’ required: true type: string paramType: query

  • name: target type: string or int description: target project slug/id to move/copy to. required: true

  • name: selected description: JSON array, list of property/taxlot views to be transferred paramType: array[int] required: true

parser_classes = (<class 'rest_framework.parsers.JSONParser'>,)
partial_update(request, pk)

Updates a project. Allows partial update, i.e. only updated param s need be supplied.

PUT

Expects organization_id in query string.

— parameters:

  • name: organization_id description: ID of organization to associate new project with type: integer required: true paramType: query

  • name: project slug or pk description: The project slug identifier or primary key for this project required: true paramType: path

  • name: name description: name of the new project type: string required: false

  • name: is_compliance description: add compliance data if true type: bool required: false

  • name: compliance_type description: description of type of compliance type: string required: true if is_compliance else false

  • name: description description: description of new project type: string required: true if is_compliance else false

  • name: end_date description: Timestamp for when project ends type: string required: true if is_compliance else false

  • name: deadline_date description: Timestamp for compliance deadline type: string required: true if is_compliance else false

Returns::
{

‘status’: ‘success’, ‘project’: {

‘id’: project’s primary key, ‘name’: project’s name, ‘slug’: project’s identifier, ‘status’: ‘active’, ‘number_of_buildings’: Count of buildings associated with project ‘last_modified’: Timestamp when project last changed ‘last_modified_by’: {

‘first_name’: first name of user that made last change, ‘last_name’: last name, ‘email’: email address,

}, ‘is_compliance’: True if project is a compliance project, ‘compliance_type’: Description of compliance type, ‘deadline_date’: Timestamp of when compliance is due, ‘end_date’: Timestamp of end of project, ‘property_count’: number of property views associated with project, ‘taxlot_count’: number of taxlot views associated with project,

}

}

project_view_factory(inventory_type, project_id, view_id)

ProjectPropertyView/ProjectTaxLotView factory.

query_set = <QuerySet []>
remove(request, pk)

Remove inventory from project :PUT: Expects organization_id in query string. — parameters:

  • name: organization_id description: ID of organization to associate new project with type: integer required: true

  • name: inventory_type description: type of inventory to add: ‘property’ or ‘taxlot’ type: string required: true paramType: query

  • name: project slug or pk description: The project slug identifier or primary key for this project required: true paramType: path

  • name: selected description: ids of property or taxlot views to add type: array[int] required: true

Returns:
{

‘status’: ‘success’, ‘removed’: [list of property/taxlot view ids removed]

}

renderer_classes = (<class 'rest_framework.renderers.JSONRenderer'>,)
retrieve(request, pk)

Retrieves details about a project.

GET

Expects organization_id in query string.

— parameter_strategy: replace parameters:

  • name: organization_id description: The organization_id for this user’s organization required: true paramType: query

  • name: project slug or pk description: The project slug identifier or primary key for this project required: true paramType: path

Returns:

{
 'id': project's primary key,
 'name': project's name,
 'slug': project's identifier,
 'status': 'active',
 'number_of_buildings': Count of buildings associated with project
 'last_modified': Timestamp when project last changed
 'last_modified_by': {
    'first_name': first name of user that made last change,
    'last_name': last name,
    'email': email address,
    },
 'is_compliance': True if project is a compliance project,
 'compliance_type': Description of compliance type,
 'deadline_date': Timestamp of when compliance is due,
 'end_date': Timestamp of end of project
 'property_count': number of property views associated with project,
 'taxlot_count':  number of taxlot views associated with project,
 'property_views': [list of serialized property views associated with the project...],
 'taxlot_views': [list of serialized taxlot views associated with the project...],
}
serializer_class

alias of seed.serializers.projects.ProjectSerializer

transfer(request, pk, transfer_action)

Move or copy inventory from one project to another

update(request, pk)

Updates a project

PUT

Expects organization_id in query string.

— parameters:

  • name: organization_id description: ID of organization to associate new project with type: integer required: true paramType: query

  • name: project slug or pk description: The project slug identifier or primary key for this project required: true paramType: path

  • name: name description: name of the new project type: string required: true

  • name: is_compliance description: add compliance data if true type: bool required: true

  • name: compliance_type description: description of type of compliance type: string required: true if is_compliance else false

  • name: description description: description of new project type: string required: true if is_compliance else false

  • name: end_date description: Timestamp for when project ends type: string required: true if is_compliance else false

  • name: deadline_date description: Timestamp for compliance deadline type: string required: true if is_compliance else false

Returns::
{

‘status’: ‘success’, ‘project’: {

‘id’: project’s primary key, ‘name’: project’s name, ‘slug’: project’s identifier, ‘status’: ‘active’, ‘number_of_buildings’: Count of buildings associated with project ‘last_modified’: Timestamp when project last changed ‘last_modified_by’: {

‘first_name’: first name of user that made last change, ‘last_name’: last name, ‘email’: email address,

}, ‘is_compliance’: True if project is a compliance project, ‘compliance_type’: Description of compliance type, ‘deadline_date’: Timestamp of when compliance is due, ‘end_date’: Timestamp of end of project, ‘property_count’: number of property views associated with project, ‘taxlot_count’: number of taxlot views associated with project,

}

}

update_details(request, pk)

Updates extra information about the inventory/project relationship. In particular, whether the property/taxlot is compliant and who approved it.

PUT

Expects organization_id in query string.

— parameter_strategy: replace parameters:

  • name: organization_id description: The organization_id for this user’s organization required: true type: integer paramType: query

  • name: inventory_type description: type of inventory to add: ‘property’ or ‘taxlot’ required: true type: string paramType: query

  • name: id description: id of property/taxlot view to update required: true type: integer paramType: string

  • name: compliant description: is compliant required: true type: bool paramType: string

Returns::
{

‘status’: ‘success’, ‘approved_date’: Timestamp of change (now), ‘approver’: Email address of user making change

}

seed.views.projects.convert_dates(data, keys)
seed.views.projects.update_model(model, data)

Module contents

:copyright (c) 2014 - 2022, The Regents of the University of California, through Lawrence Berkeley National Laboratory (subject to receipt of any required approvals from the U.S. Department of Energy) and contributors. All rights reserved. :author