proso.django package¶
Submodules¶
proso.django.auth module¶
proso.django.cache module¶
proso.django.config module¶
-
proso.django.config.
get_config
(app_name, key, config_name=None, required=False, default=None)[source]¶
proso.django.db module¶
proso.django.enrichment module¶
This module provides enrichment for JSON objects.
from pprint import pprint from proso.django.enrichment import register_object_type_enricher, enrich_json_objects_by_object_type # Firstly, we create a few enrichers. def global_enricher(request, json_list, nested): for json in json_list: json['globally_enriched'] = 1 def local_enricher(request, json_list, nested): for json in json_list: json['locally_enriched'] = json.get('globally_enriched', 0) + 1 register_object_type_enricher(['parent', 'dog', 'child'], global_enricher) register_object_type_enricher(['parent'], local_enricher, [global_enricher]) # Imagine we have the following data. We can enrich them. data = [ {'object_type': 'parent', 'children': [{'object_type': 'child'}, {'object_type': 'child'}]}, {'object_type': 'parent', 'children': [{'object_type': 'child'}]}, {'object_type': 'dog'}, ] enrich_json_objects_by_object_type(request, data) # Now, we have enriched data. pprint(data)[{'children': [{'globally_enriched': 1, 'object_type': 'child'}, {'globally_enriched': 1, 'object_type': 'child'}], 'globally_enriched': 1, 'locally_enriched': 2, 'object_type': 'parent'}, {'children': [{'globally_enriched': 1, 'object_type': 'child'}], 'globally_enriched': 1, 'locally_enriched': 2, 'object_type': 'parent'}, {'globally_enriched': 1, 'object_type': 'dog'}]
-
proso.django.enrichment.
enrich_by_object_type
(request, json, fun, object_type, skip_nested=False, **kwargs)[source]¶ Take the JSON, find its subparts having the given object part and transform them by the given function. Other key-word arguments are passed to the function.
def enricher(request, json_list, nested): for json_object in json_list: json_object['enriched'] = True enriched = enrich_by_object_type( request, [{'object_type': 'example_1'}, {'object_type': 'example_2'}], enricher, ['example_1'] ) pprint(enriched)
[{'enriched': True, 'object_type': 'example_1'}, {'object_type': 'example_2'}]
Parameters: - request (django.http.request.HttpRequest) – request which is currently processed
- json (list|dict) – in-memory representation of JSON
- fun – function which is be applied on found objects
- object_type (str|list) – object type or list of object types
- skip_nested – ignore nested objects
Returns: transformed JSON
Return type: list|dict
-
proso.django.enrichment.
enrich_by_predicate
(request, json, fun, predicate, skip_nested=False, **kwargs)[source]¶ Take the JSON, find all its subparts satisfying the given condition and them by the given function. Other key-word arguments are passed to the function.
def enricher(request, json_list, nested): for json_object in json_list: json_object['enriched'] = True enriched = enrich_by_predicate( request, [{'object_type': 'example_1'}, {'object_type': 'example_2'}], enricher, lambda x: True ) pprint(enriched)
[{'enriched': True, 'object_type': 'example_1'}, {'enriched': True, 'object_type': 'example_2'}]
Parameters: - request (django.http.request.HttpRequest) – request which is currently processed
- json (list|dict) – in-memory representation of JSON
- fun – function which is be applied on found objects
- predicate – function which is applied on all objects to determine which objects should be processed further
- skip_nested – ignore nested objects
Returns: transformed JSON
Return type: list|dict
-
proso.django.enrichment.
enrich_json_objects_by_object_type
(request, value)[source]¶ Take the given value and start enrichment by object_type. The va
Parameters: - request (django.http.request.HttpRequest) – request which is currently processed
- value (dict|list|django.db.models.Model) – in case of django.db.models.Model object (or list of these objects), to_json method is invoked
Returns: dict|list
proso.django.log module¶
-
class
proso.django.log.
AdminJavascriptEmailHandler
(include_html=False, email_backend=None)[source]¶ Bases:
django.utils.log.AdminEmailHandler