Views Package

Submodules

Accounts

APIs

seed.views.api.get_api_schema(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

seed.views.main.angular_js_tests(request)

Jasmine JS unit test code covering AngularJS unit tests

seed.views.main.delete_file(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(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)
seed.views.main.error500(request)
seed.views.main.get_default_building_detail_columns(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, *args, **kwargs)

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)
  • AWS_UPLOAD_BUCKET_NAME: S3 direct upload bucket
  • AWS_CLIENT_ACCESS_KEY: S3 direct upload client key
  • FILE_UPLOAD_DESTINATION: ‘S3’ or ‘filesystem’
seed.views.main.public_search(request, *args, **kwargs)

the public API unauthenticated endpoint

see search_buildings for the non-public version

seed.views.main.search_buildings(request, *args, **kwargs)

Retrieves a paginated list of CanonicalBuildings matching search params.

Payload:

{
    'q': a string to search on (optional),
    'show_shared_buildings': True to include buildings from other orgs in this user's org tree,
    'order_by': which field to order by (e.g. pm_property_id),
    'import_file_id': ID of an import to limit search to,
    'filter_params': {
        a hash of Django-like filter parameters to limit query.  See seed.search.filter_other_params.
        If 'project__slug' is included and set to a project's slug, buildings will include associated labels
        for that project.
    }
    'page': Which page of results to retrieve (default: 1),
    'number_per_page': Number of buildings to retrieve per page (default: 10),
}

Returns:

{
    'status': 'success',
    'buildings': [
        {
            all fields for buildings the request user has access to, e.g.:
                'canonical_building': the CanonicalBuilding ID of the building,
                'pm_property_id': ID of building (from Portfolio Manager),
                'address_line_1': First line of building's address,
                'property_name': Building's name, if any
            ...
        }...
    ]
    'number_matching_search': Total number of buildings matching search,
    'number_returned': Number of buildings returned for this page
}
seed.views.main.set_default_building_detail_columns(request, *args, **kwargs)
seed.views.main.set_default_columns(request, *args, **kwargs)
seed.views.main.version(request, *args, **kwargs)

Returns the SEED version and current git sha

Meters

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

Bases: rest_framework.viewsets.ViewSet

add_timeseries(request, *args, **kwargs)

Returns timeseries for meter — type:

status:
required: true type: string description: Either success or error
meter:
required: true type: dict description: meter information
timeseries:
required: true type: list description: timeseries information
parameters:
  • name: pk description: Meter primary key required: true paramType: path
create(request, *args, **kwargs)

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: property_view_id description: Property view id to which to add the meter required: true paramType: form
  • name: name description: name of the new meter type: string required: true paramType: form
  • name: energy_type description: type of metered energy type: integer required: true paramType: form
  • name: energy_units description: units of energy being metered type: integer required: true paramType: form
type:
status:
required: true type: string description: Either success or error
list(request, *args, **kwargs)

Returns all of the meters for a property view — type:

status:
required: true type: string description: Either success or error
property_view_id:
required: true type: integer description: property view id of the request
meters:
required: true type: array[meters] description: list of meters for property_view_id
parameters:
  • name: organization_id description: The organization_id for this user’s organization required: true paramType: query
  • name: property_view_id description: The property_view_id of the building holding the meter data required: true paramType: query
parser_classes = (<class 'rest_framework.parsers.JSONParser'>, <class 'rest_framework.parsers.FormParser'>)
raise_exception = True
retrieve(request, *args, **kwargs)

Returns a single meter based on its id — type:

status:
required: true type: string description: Either success or error
meters:
required: true type: dict description: meter object
parameters:
  • name: pk description: Meter primary key required: true paramType: path
timeseries(request, *args, **kwargs)

Returns timeseries for meter — type:

status:
required: true type: string description: Either success or error
meter:
required: true type: dict description: meter information
data:
required: true type: list description: timeseries information
parameters:
  • name: pk description: Meter primary key required: true paramType: path

Projects

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

Bases: seed.decorators.DecoratorMixindrf_api_endpoint, 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, *args, **kwargs)

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]

}

count(request, *args, **kwargs)

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, *args, **kwargs)

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, *args, **kwargs)

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_status(status)

Get status from string or int

list(request, *args, **kwargs)

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,
        }...
    ]
}
parser_classes = (<class 'rest_framework.parsers.JSONParser'>,)
partial_update(request, *args, **kwargs)

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, *args, **kwargs)

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, *args, **kwargs)

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, *args, **kwargs)

Move or 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: copy or move description: Whether to move or copy inventory required: true paramType: path required: true
-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
update(request, *args, **kwargs)

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, *args, **kwargs)

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