SEED Package¶
Subpackages¶
Inheritance¶
Submodules¶
Decorators¶
-
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 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¶
-
class
seed.factory.
SEEDFactory
¶ Bases:
seed.test_helpers.factory.helpers.DjangoFunctionalFactory
model factory for SEED
-
classmethod
building_snapshot
(canonical_building=None, *args, **kwargs)¶ creates an BuildingSnapshot inst.
if canonical_building (CanonicalBuilding inst.) is None, then a CanonicalBuilding inst. is created and a BuildingSnapshot inst. is created and linked to the CanonicalBuilding inst.
-
classmethod
Models¶
Search¶
Search methods pertaining to buildings.
-
seed.search.
build_json_params
(order_by, sort_reverse)¶ returns db_columns, extra_data_sort, and updated order_by
Parameters: order_by (str) – field to order_by Returns: tuple: db_columns: dict of known DB columns i.e. non-JSONField, extra_data_sort bool if order_by is in extra_data
JSONField, order_by str if sort_reverse and DB column prepend a ‘-‘ for the django order_by
returns a list of sibling and parent orgs
-
seed.search.
create_building_queryset
(orgs, exclude, order_by, other_orgs=None, extra_data_sort=False)¶ creates a queryset of buildings within orgs. If
other_orgs
, buildings in both orgs and other_orgs will be represented in the queryset.Parameters: - 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.
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.
filter_other_params
(queryset, other_params, db_columns)¶ applies a dictionary filter to the query set. Does some domain specific parsing, mostly to remove extra query params and deal with ranges. Ranges should be passed in as ‘<field name>__lte’ or ‘<field name>__gte’ e.g. other_params = {‘gross_floor_area__lte’: 50000}
Parameters: - Queryset queryset (Django) – queryset to be filtered
- other_params (dict) – dictionary to be parsed and applied to filter.
- db_columns (dict) – list of column names, extra_data blob outside these
Returns: Django Queryset:
-
seed.search.
generate_paginated_results
(queryset, number_per_page=25, page=1, whitelist_orgs=None, below_threshold=False, matching=True)¶ Return a page of results as a list from the queryset for the given fields
Parameters: - queryset – optional queryset to filter from
- number_per_page (int) – optional number of results per page
- page (int) – optional page of results to get
- whitelist_orgs – a queryset returning the organizations in which all building fields can be returned, otherwise only the parent organization’s
exportable_fields
should be returned. Thewhitelist_orgs
are the orgs the request user belongs. - below_threshold – True if less than the parent org’s query threshold is greater than the number of queryset results. If True, only return buildings within whitelist_orgs.
- matching – Toggle expanded parent and children data, including coparent and confidence
Usage:
generate_paginated_results(q, 1)
Returns:
[ { 'gross_floor_area': 1710, 'site_eui': 123, 'tax_lot_id': 'a-tax-lot-id', 'year_built': 2001 } ]
-
seed.search.
get_building_fieldnames
()¶ returns a list of field names for the BuildingSnapshot class/model that will be searched against
-
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.
is_not_whitelist_building
(parent_org, building, whitelist_orgs)¶ returns false if a building is part of the whitelist_orgs
Parameters: - parent_org – the umbrella parent Organization instance.
- building – the BuildingSnapshot inst.
- whitelist_orgs – queryset of Organization instances.
Returns: bool
-
seed.search.
mask_results
(search_results)¶ masks (deletes dict keys) for non-shared public fields
-
seed.search.
orchestrate_search_filter_sort
(params, user, skip_sort=False)¶ Given a parsed set of params, perform the search, filter, and sort for BuildingSnapshot’s
-
seed.search.
paginate_results
(request, search_results)¶ returns a paginated list of dict results
-
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.
remove_results_below_q_threshold
(search_results)¶ removes buildings if total count of buildings grouped by org is less than their org’s public query threshold
Parameters: search_results (list/queryset) – search results Returns: list or queryset
-
seed.search.
search_buildings
(q, fieldnames=None, queryset=None)¶ returns a queryset for matching buildings :param str or unicode q: search string :param list fieldnames: list of BuildingSnapshot model fieldnames
(defaults to those generated by get_building_field_names())Parameters: queryset – optional queryset to filter from, defaults to BuildingSnapshot.objects.none() Returns: queryset: queryset of matching buildings
-
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, defaults to
BuildingSnapshot.objects.none()Returns: queryset: queryset of matching buildings
-
seed.search.
search_properties
(q, fieldnames=None, queryset=None)¶
-
seed.search.
search_public_buildings
(request, orgs)¶ returns a queryset or list of buildings matching the search params and count
Parameters: - request – wsgi request (Django) for parsing params
- orgs – list of Organization instances to search within
Returns: tuple (search_results_list, result count)
-
seed.search.
search_taxlots
(q, fieldnames=None, queryset=None)¶
Token Generator¶
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.
-