UtilsΒΆ
-
towel.utils.
app_model_label
(model) Stop those deprecation warnings
-
towel.utils.
changed_regions
(regions, fields) Returns a subset of regions which have to be updated when fields have been edited. To be used together with the
{% regions %}
template tag.Usage:
regions = {} render(request, 'detail.html', { 'object': instance, 'regions': regions, }) return HttpResponse( json.dumps(changed_regions(regions, ['emails', 'phones'])), content_type='application/json')
-
towel.utils.
parse_args_and_kwargs
(parser, bits) Parses template tag arguments and keyword arguments
Returns a tuple
args, kwargs
.Usage:
@register.tag def custom(parser, token): return CustomNode(*parse_args_and_kwargs(parser, token.split_contents()[1:])) class CustomNode(template.Node): def __init__(self, args, kwargs): self.args = args self.kwargs = kwargs def render(self, context): args, kwargs = resolve_args_and_kwargs(context, self.args, self.kwargs) return self._render(context, *args, **kwargs): def _render(self, context, ...): # The real workhorse
-
towel.utils.
related_classes
(instance) Return all classes which would be deleted if the passed instance were deleted too by employing the cascade machinery of Django itself. Does not return instances, only classes.
Note! When using Django 1.5, autogenerated models (many to many through models) are returned too.
-
towel.utils.
resolve_args_and_kwargs
(context, args, kwargs) Resolves arguments and keyword arguments parsed by
parse_args_and_kwargs
using the passed context instanceSee
parse_args_and_kwargs
for usage instructions.
-
towel.utils.
safe_queryset_and
(head, *tail) Safe AND-ing of querysets. If one of both queries has its DISTINCT flag set, sets distinct on both querysets. Also takes extra care to preserve the result of the following queryset methods:
reverse()
transform()
select_related()
prefetch_related()
-
towel.utils.
substitute_with
(to_delete, instance) Substitute the first argument with the second in all relations, and delete the first argument afterwards.
-
towel.utils.
tryreverse
(*args, **kwargs) Calls
django.core.urlresolvers.reverse
, and returnsNone
on failure instead of raising an exception.