Views Package

Submodules

Accounts

APIs

Main

class seed.views.main.DataFileViewSet(**kwargs)

Bases: rest_framework.viewsets.ViewSet

authentication_classes = (<class 'rest_framework.authentication.SessionAuthentication'>, <class 'seed.authentication.SEEDAuthentication'>)
mapping_suggestions(request, *args, **kwargs)

Returns suggested mappings from an uploaded file’s headers to known data fields. — type:

status:
required: true type: string description: Either success or error
suggested_column_mappings:

required: true type: dictionary description: Dictionary where (key, value) = (the column header from the file,

array of tuples (destination column, score))
building_columns:
required: true type: array description: A list of all possible columns
building_column_types:
required: true type: array description: A list of column types corresponding to the building_columns array

parameter_strategy: replace parameters:

  • name: pk description: import_file_id required: true paramType: path
  • name: organization_id description: The organization_id for this user’s organization required: true paramType: query
raise_exception = True
suffix = None
seed.views.main.angular_js_tests(request)

Jasmine JS unit test code covering AngularJS unit tests and ran by ./manage.py harvest

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

Deletes all BuildingSnapshots the user has selected.

Does not delete selected_buildings where the user is not a member or owner of the organization the selected building belongs. Since search shows buildings across all the orgs a user belongs, it’s possible for a building to belong to an org outside of org_id.

DELETE:Expects ‘org_id’ for the organization, and the search payload similar to add_buildings/create_project

Payload:

{
    'organization_id': 2,
    'search_payload': {
        'selected_buildings': [2, 3, 4],
        'select_all_checkbox': False,
        'filter_params': ... // see search_buildings
    }
}

Returns:

{
    'status': 'success' or 'error'
}
seed.views.main.delete_duplicates_from_import_file(request, *args, **kwargs)

Retrieves the number of matched and unmatched BuildingSnapshots for a given ImportFile record.

GET:Expects import_file_id corresponding to the ImportFile in question.

Returns:

{
    "status": "success",
    "deleted": "Number of duplicates deleted"
}
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_buildings(request, *args, **kwargs)

Starts a background task to delete all BuildingSnapshots in an org.

GET:Expects ‘org_id’ for the organization.

Returns:

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

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

GET:Expects ‘org_id’ for the organization.

Returns:

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

Begins a building export process.

Payload:

{
    "export_name": "My Export",
    "export_type": "csv",
    "selected_buildings": [1234,], (optional list of building ids)
    "selected_fields": optional list of fields to export
    "select_all_checkbox": True // optional, defaults to False
}

Returns:

{
    "success": True,
    "status": "success",
    "export_id": export_id; see export_buildings_download,
    "total_buildings": count of buildings,
}
seed.views.main.export_buildings_download(request, *args, **kwargs)

Provides the url to a building export file.

Payload:

{
    "export_id": export_id from export_buildings
}

Returns:

{
    'success': True or False,
    'status': 'success or error',
    'message': 'error message, if any',
    'url': The url to the exported file.
}
seed.views.main.export_buildings_progress(request, *args, **kwargs)

Returns current progress on building export process.

Payload:

{
    "export_id": export_id from export_buildings
}

Returns:

{
    'success': True,
    'status': 'success or error',
    'message': 'error message, if any',
    'buildings_processed': number of buildings exported
}
seed.views.main.get_building(request)

Retrieves a building. If user doesn’t belong to the building’s org, fields will be masked to only those shared within the parent org’s structure.

GET:Expects building_id and organization_id in query string. building_id should be the canonical_building ID for the building, not the BuildingSnapshot id.

Returns:

{
     'status': 'success or error',
     'message': 'error message, if any',
     'building': {'id': the building's id,
                  'canonical_building': the canonical building ID,
                  other fields this user has access to...
     },
     'imported_buildings': [ A list of buildings imported to create
                             this building's record, in the same
                             format as 'building'
                           ],
     'projects': [
        // A list of the building's projects
        {
            "building": {
                "approved_date":07/30/2014,
                "compliant": null,
                "approver": "demo@seed.lbl.gov"
                "approved_date": "07/30/2014"
                "compliant": null
                "label": {
                    "color": "red",
                    "name": "non compliant",
                    id: 1
                }
            }
            "description": null
            "id": 3
            "is_compliance": false
            "last_modified_by_id": 1
            "name": "project 1"
            "owner_id": 1
            "slug": "project-1"
            "status": 1
            "super_organization_id": 1
        },
        . . .
    ],
     'user_role': role of user in this org,
     'user_org_id': the org id this user belongs to
}
seed.views.main.get_columns(request, *args, **kwargs)

returns a JSON list of columns a user can select as his/her default

GET:Expects organization_id in the query string.
seed.views.main.get_coparents(request, *args, **kwargs)

Returns the nodes in the BuildingSnapshot tree that can be unmatched.

GET:Expects organization_id and building_id in the query string

Returns:

{
    'status': 'success',
    'coparents': [
        {
            "id": 333,
            "coparent": 223,
            "child": 443,
            "parents": [],
            "canonical_building_id": 1123
        },
        {
            "id": 223,
            "coparent": 333,
            "child": 443,
            "parents": [],
            "canonical_building_id": 1124
        },
        ...
    ]
}
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.get_default_columns(request, *args, **kwargs)

Get default columns for building list 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.get_total_number_of_buildings_for_user(request, *args, **kwargs)

gets a count of all buildings in the user’s organizations

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.remap_buildings(request, *args, **kwargs)

Re-run the background task to remap buildings as if it hadn’t happened at all. Deletes mapped buildings for a given ImportRecord, resets status.

NB: will not work if buildings have been merged into CanonicalBuilings.

Payload:

{
    'file_id': The ID of the ImportFile to be remapped
}

Returns:

{
    'status': 'success' or 'error',
    'progress_key': ID of background job, for retrieving job progress
}
seed.views.main.save_match(request)
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)

Meters

seed.views.meters.add_meter_to_building(request, *args, **kwargs)

Will add a building to an existing meter.

Payload:

{
    'organization_id': 435,
    'building_id': 342,
    'meter_name': 'Unit 34.',
    'energy_type': 'Electricity',
    'energy_units': 'kWh'
}
seed.views.meters.add_timeseries(request, *args, **kwargs)

Add time series data for a meter.

Payload:

{
    'organization_id': 435,
    'meter_id': 34,
    'timeseries': [
        {
            'begin_time': 2342342232,
            'end_time': 23423433433,
            'cost': 232.23,
        }...
    ]
}
seed.views.meters.get_meters(request, *args, **kwargs)

Returns all of the meters for a building.

Expected GET params:

building_id: int, unique identifier for a (canonical) building.

seed.views.meters.get_timeseries(request, *args, **kwargs)

Return all time series data for a building, grouped by meter.

Expected GET params:

meter_id: int, unique identifier for the meter. offset: int, the offset from the most recent meter data to begin showing. num: int, the number of results to show.

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]

}

authentication_classes = (<class 'rest_framework.authentication.SessionAuthentication'>, <class 'seed.authentication.SEEDAuthentication'>)
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 = []
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 ProjectSerializer

suffix = None
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