proso.django package

Submodules

proso.django.auth module

proso.django.auth.convert_lazy_user(user)[source]
proso.django.auth.get_unused_username(user)[source]
proso.django.auth.is_user_lazy(user)[source]
proso.django.auth.is_user_named(user)[source]
proso.django.auth.is_user_real(user)[source]
proso.django.auth.is_user_social(user)[source]
proso.django.auth.is_username_present(username)[source]
proso.django.auth.name_lazy_user(user, save=True)[source]

proso.django.cache module

class proso.django.cache.RequestCache[source]

Bases: django.core.cache.backends.locmem.LocMemCache

class proso.django.cache.RequestCacheMiddleware[source]

Bases: object

process_request(request)[source]
proso.django.cache.cache_page_conditional(condition, timeout=3600, cache=None)[source]
proso.django.cache.cache_pure(f, expiration=2592000)[source]

Cache decorator for functions taking one or more arguments.

proso.django.cache.get_from_request_permenent_cache(key)[source]
proso.django.cache.get_request_cache()[source]
proso.django.cache.is_cache_prepared()[source]
proso.django.cache.set_to_request_permanent_cache(key, value)[source]

proso.django.config module

class proso.django.config.ConfigMiddleware[source]

Bases: object

process_request(request)[source]
proso.django.config.get_config(app_name, key, config_name=None, required=False, default=None)[source]
proso.django.config.get_config_path()[source]
proso.django.config.get_default_config_name()[source]
proso.django.config.get_global_config(config_name=None)[source]
proso.django.config.instantiate_from_json(json, default_class=None, default_parameters=None, pass_parameters=None)[source]
proso.django.config.is_any_overridden()[source]
proso.django.config.is_overridden_from_url()[source]
proso.django.config.override(app_name_key, value)[source]
proso.django.config.override_value(app_name_key, value, override_key, override_value)[source]
proso.django.config.reset_overridden()[source]
proso.django.config.set_default_config_name(config_name)[source]

proso.django.db module

proso.django.db.dump_cursor(cursor, dest_file, append=False)[source]
proso.django.db.dump_table(table_name, pk_column, batch_size, dest_file)[source]
proso.django.db.is_on_postgresql()[source]

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.enrichment.register_object_type_enricher(object_types, enricher, dependencies=None, priority=0, pure=True)[source]

proso.django.log module

class proso.django.log.AdminJavascriptEmailHandler(include_html=False, email_backend=None)[source]

Bases: django.utils.log.AdminEmailHandler

format(record)[source]
class proso.django.log.RequestHandler[source]

Bases: logging.Handler

emit(record)[source]
class proso.django.log.RequestLogMiddleware[source]

Bases: object

process_request(request)[source]
proso.django.log.get_request_log()[source]
proso.django.log.is_active()[source]
proso.django.log.is_log_prepared()[source]

proso.django.request module

class proso.django.request.RequestMiddleware[source]

Bases: object

process_request(request)[source]
proso.django.request.get_current_request(force=True)[source]
proso.django.request.get_language(request)[source]
proso.django.request.get_time(request)[source]
proso.django.request.get_user_id(request=None)[source]
proso.django.request.is_time_overridden(request)[source]
proso.django.request.is_user_id_overridden(request)[source]
proso.django.request.json_body(body)[source]
proso.django.request.load_query_json(query_dict, key, default_json=None)[source]
proso.django.request.parse_common_body_to_json(body)[source]
proso.django.request.set_current_request(request)[source]

proso.django.response module

exception proso.django.response.BadRequestException(message)[source]

Bases: proso.django.response.HttpError

exception proso.django.response.HttpError(status, message)[source]

Bases: Exception

class proso.django.response.JsonResponse(content, status=None, content_type='application/json')[source]

Bases: django.http.response.HttpResponse

JSON response

proso.django.response.append_get_parameters(dest_url, get_parameters_string)[source]
proso.django.response.pass_get_parameters(request, dest_url, ignore=None)[source]
proso.django.response.pass_get_parameters_string(request, ignore=None)[source]
proso.django.response.redirect_pass_get(request, view, *args, **kwargs)[source]
proso.django.response.render(request, template, data, *args, **kwargs)[source]
proso.django.response.render_json(request, json, template=None, status=None, help_text=None, version='3.5.0.dev')[source]

Module contents