SEED Package

Subpackages

Inheritance

Submodules

Decorators

: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.decorators.DecoratorMixin(decorator)

Converts a decorator written for a function view into a mixin for a class-based view.

Example:

LoginRequiredMixin = DecoratorMixin(login_required)
class MyView(LoginRequiredMixin):
    pass

class SomeView(DecoratorMixin(some_decorator), DecoratorMixin(something_else)):
    pass
seed.decorators.ajax_request(func)

Copied from django-annoying, with a small modification. Now we also check for ‘status’ or ‘success’ keys and slash return correct status codes

If view returned serializable dict, returns response in a format requested by HTTP_ACCEPT header. Defaults to JSON if none requested or match.

Currently supports JSON or YAML (if installed), but can easily be extended.

Example:

@ajax_request
def my_view(request):
    news = News.objects.all()
    news_titles = [entry.title for entry in news]
    return { 'news_titles': news_titles }
seed.decorators.ajax_request_class(func)
  • Copied from django-annoying, with a small modification. Now we also check for ‘status’ or

‘success’ keys and return correct status codes

If view returned serializable dict, returns response in a format requested by HTTP_ACCEPT header. Defaults to JSON if none requested or match.

Currently supports JSON or YAML (if installed), but can easily be extended.

Example:

@ajax_request
def my_view(self, request):
    news = News.objects.all()
    news_titles = [entry.title for entry in news]
    return { 'news_titles': news_titles }
seed.decorators.get_prog_key(func_name, import_file_pk)

Return the progress key for the cache

seed.decorators.lock_and_track(fn, *args, **kwargs)

Decorator to lock tasks to single executor and provide progress url.

seed.decorators.require_organization_id(func)

Validate that organization_id is in the GET params and it’s an int.

seed.decorators.require_organization_id_class(fn)

Validate that organization_id is in the GET params and it’s an int.

seed.decorators.require_organization_membership(fn)

Validate that the organization_id passed in GET is valid for request user.

Factory

Models

: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

Search

: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

Search methods pertaining to buildings.

exception seed.search.FilterException

Bases: Exception

class seed.search.QueryFilter(field_name: str, operator: Union[QueryFilterOperator, None], is_negated: bool)

Bases: object

field_name: str
is_negated: bool
operator: Optional[seed.search.QueryFilterOperator]
classmethod parse(filter: str)seed.search.QueryFilter

Parse a filter string into a QueryFilter

Parameters

filter – string in the format <field_name>, or <field_name>__<lookup_expression>

to_q(value: Any)django.db.models.query_utils.Q
class seed.search.QueryFilterOperator(value)

Bases: enum.Enum

An enumeration.

CONTAINS = 'icontains'
EQUAL = 'exact'
GT = 'gt'
GTE = 'gte'
LT = 'lt'
LTE = 'lte'
seed.search.build_shared_buildings_orgs(orgs)

returns a list of sibling and parent orgs

seed.search.build_view_filters_and_sorts(filters: django.http.request.QueryDict, columns: list)tuple

Build a query object usable for *View.filter(…) as well as a list of column names for usable for *View.order_by(…).

Filters are specified in a similar format as Django queries, as column_name or column_name__lookup, where column_name is a valid Column.column_name, and __lookup (which is optional) is any valid Django field lookup:

One special lookup which is not provided by Django is __ne which negates the filter expression.

Query string examples: - ?city=Denver - inventory where City is Denver - ?city__ne=Denver - inventory where City is NOT Denver - ?site_eui__gte=100 - inventory where Site EUI >= 100 - ?city=Denver&site_eui__gte=100 - inventory where City is Denver AND Site EUI >= 100 - ?my_custom_column__lt=1000 - inventory where the extra data field my_custom_column < 1000

Sorts are specified with the order_by parameter, with any valid Column.column_name as the value. By default the column is sorted in ascending order, columns prefixed with - will be sorted in descending order.

Query string examples: - ?order_by=site_eui - sort by Site EUI in ascending order - ?order_by=-site_eui - sort by Site EUI in descending order - ?order_by=city&order_by=site_eui - sort by City, then Site EUI

This function basically does the following: - Ignore any filter/sort that doesn’t have a corresponding column - Handle cases for extra data - Convert filtering values into their proper types (e.g., str -> int)

Parameters
  • filters – QueryDict from a request

  • columns – list of all valid Columns in dict format

Returns

filters, annotations and sorts

seed.search.create_inventory_queryset(inventory_type, orgs, exclude, order_by, other_orgs=None)

creates a queryset of properties or taxlots within orgs. If other_orgs, properties/taxlots in both orgs and other_orgs will be represented in the queryset.

Parameters
  • inventory_type – property or taxlot.

  • orgs – queryset of Organization inst.

  • exclude – django query exclude dict.

  • order_by – django query order_by str.

  • other_orgs – list of other orgs to or the query

seed.search.get_inventory_fieldnames(inventory_type)

returns a list of field names that will be searched against

seed.search.get_orgs_w_public_fields()

returns a list of orgs that have publicly shared fields

seed.search.inventory_search_filter_sort(inventory_type, params, user)

Given a parsed set of params, perform the search, filter, and sort for Properties or Taxlots

seed.search.parse_body(request)

parses the request body for search params, q, etc

Parameters

request – django wsgi request object

Returns

dict

Example:

{
    'exclude': dict, exclude dict for django queryset
    'order_by': str, query order_by, defaults to 'tax_lot_id'
    'sort_reverse': bool, True if ASC, False if DSC
    'page': int, pagination page
    'number_per_page': int, number per pagination page
    'show_shared_buildings': bool, whether to search across all user's orgs
    'q': str, global search param
    'other_search_params': dict, filter params
    'project_id': str, project id if exists in body
}
seed.search.process_search_params(params, user, is_api_request=False)

Given a python representation of a search query, process it into the internal format that is used for searching, filtering, sorting, and pagination.

Parameters
  • params – a python object representing the search query

  • user – the user this search is for

  • is_api_request – bool, boolean whether this search is being done as an api request.

Returns

dict

Example:

{
    'exclude': dict, exclude dict for django queryset
    'order_by': str, query order_by, defaults to 'tax_lot_id'
    'sort_reverse': bool, True if ASC, False if DSC
    'page': int, pagination page
    'number_per_page': int, number per pagination page
    'show_shared_buildings': bool, whether to search across all user's orgs
    'q': str, global search param
    'other_search_params': dict, filter params
    'project_id': str, project id if exists in body
}
seed.search.search_inventory(inventory_type, q, fieldnames=None, queryset=None)

returns a queryset for matching Taxlot(View)/Property(View) :param str or unicode q: search string :param list fieldnames: list of model fieldnames :param queryset: optional queryset to filter from :returns: :queryset: queryset of matching buildings

seed.search.search_properties(q, fieldnames=None, queryset=None)
seed.search.search_taxlots(q, fieldnames=None, queryset=None)

Tasks

: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.tasks.delete_organization(org_pk)

delete_organization_buildings

seed.tasks.invite_new_user_to_seed(domain, email_address, token, user_pk, first_name)

Send invitation email to newly created user from the landing page. NOTE: this function is only used on the landing page because the user has not been assigned an organization domain – The domain name of the running seed instance email_address – The address to send the invitation to token – generated by Django’s default_token_generator user_pk – primary key for this user record first_name – First name of the new user new_user

Returns: nothing

Token Generator

: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: Aleck Landgraf

token_generator.py - taken from django core master branch

needed a token check that would not expire after three days for sending a signup email

class seed.token_generators.SignupTokenGenerator

Bases: object

Strategy object used to generate and check tokens for the password reset mechanism.

check_token(user, token, token_expires=True)

Check that a password reset token is correct for a given user.

make_token(user)

Returns a token that can be used once to do a password reset for the given user.

URLs

: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

Utils

: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

Views

: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

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