Routes and route mixins¶
Contents
A route is an implementation of the django_crucrudile.entities.Entity abstract class that yields URL patterns made from its attributes. In the code, this is represented by subclassing django_crucrudile.entities.Entity and providing a generator in patterns(), yielding URL patterns made from the route attributes. When route classes provide django_crucrudile.entities.Entity.patterns(), it makes them become concrete implementations of the Entity abstract class. Route classes themselves are abstract by nature and need a definition of the abstract function base.BaseRoute.get_callback().
- CallbackRoute : Implements base.BaseRoute using mixins.callback.CallbackMixin that provides an implementation of base.BaseRoute.get_callback() that returns the callback set on the route (either in CallbackRoute.__init__() or as class attribute)
- ViewRoute : Implements base.BaseRoute using mixins.view.ViewMixin that provides an implementation of base.BaseRoute.get_callback() that returns the a callback obtaining from the view class set on the route (either in mixins.view.ViewMixin.__init__() or as class attribute).
- ModelViewRoute : Implements base.BaseRoute using mixins.view.ViewMixin and mixins.model.ModelMixin, passes the model in the view keyword arguments, and can be used with Django generic views.
Note
ModelViewRoute Can also be used in a django_crucrudile.routers.model.ModelRouter store register mapping, as it correctly uses the model given in django_crucrudile.routers.mixins.model.ModelMixin.get_register_map_kwargs and django_crucrudile.routers.mixins.model.ModelMixin.get_base_store_kwargs, and the view class that can then be registered in the resulting router.
Base route¶
This module contains the “main” abstract route class, that provides BaseRoute.patterns(), yielding patterns made from the route metadata and using the callback returned by implementations of the abstract function BaseRoute.get_callback().
Note
This route class is one the two (along with django_crucrudile.routers.Router) standard implementations of the django_crucrudile.entities.Entity abstract class.
- class django_crucrudile.routes.base.BaseRoute(name=None, url_part=None, **kwargs)[source]¶
Bases: django_crucrudile.entities.Entity
Abstract class for a django_crucrudile.entities.Entity that URL patterns that point to its implementation of get_callback(). Implements django_crucrudile.entities.Entity.patterns() using patterns().
Warning
Abstract class ! Subclasses should define the get_callback() function. See warning in __init__().
The URL part and URL name must be either set on class, or given at __init__().
- __init__(name=None, url_part=None, **kwargs)[source]¶
Initialize Route, check that needed attributes/arguments are defined.
Also sets self.redirect to the URL name (using get_url_name()).
Parameters: Raises: - ValueError – If name is None, and not given in args
- ValueError – If url_part is None, and not given in args, and auto_url_part is None or name is None
- TypeError – If get_callback() not implemented (see warning below)
Warning
This method cannot be called on BaseRoute, as it is an abstract class missing an implementation of get_callback() :
>>> try: ... BaseRoute() ... except Exception as catched: ... type(catched).__name__ ... str(catched) == ( ... "Can't instantiate abstract class BaseRoute " ... "with abstract methods get_callback" ... ) 'TypeError' True
- name = None¶
Attribute name: URL name to use for this pattern (will be used for the Django URL pattern name)
- url_part = None¶
Attribute url_part: URL regex to use for the pattern (will be used in the URL regexp)
- patterns(parents=None, add_redirect=None, add_redirect_silent=None)[source]¶
Yield patterns for URL regexs in get_url_regexs(), using callback in get_callback() and URL name from get_url_name().
Parameters: - parents (list of django_crucrudile.routers.Router) – Not used in BaseRoute‘s implementation of patterns.
- add_redirect (bool) – Not used in BaseRoute‘s implementation of patterns.
- add_redirect_silent (bool) – Not used in BaseRoute‘s implementation of patterns.
Returns: Django URL patterns
Return type: iterable of RegexURLPattern
>>> class Route(BaseRoute): ... def get_callback(self): ... pass >>> >>> route = Route('name', 'url_part') >>> list(route.patterns()) [<RegexURLPattern name ^url_part$>]
- get_callback()[source]¶
Return callback to use in the URL pattern
Warning
Abstract method ! Should be implemented in subclasses, otherwise class instantiation will fail. See warning in __init__().
Returns: Callable to use in the URL patter Return type: callable
- get_url_name()[source]¶
Get the main URL name, defined at class level (name) or passed to __init__().
Returns: main URL name Return type: str >>> class Route(BaseRoute): ... def get_callback(self): ... pass >>> >>> route = Route('name', 'url_part') >>> route.get_url_name() 'name'
- get_url_names()[source]¶
Get a list of URL names to generate patterns for. An least one URL pattern will be returned for each URL name returned by this function.
The default implementation returns a singleton (get_url_name()).
Returns: URL names (list of URL name) Return type: iterable of str >>> class Route(BaseRoute): ... def get_callback(self): ... pass >>> >>> route = Route('name', 'url_part') >>> print(list(route.get_url_names())) ['name']
- get_url_part()[source]¶
Get the main URL part, defined at class level (url_part) or passed to __init__().
Returns: main URL part Return type: str >>> class Route(BaseRoute): ... def get_callback(self): ... pass >>> >>> route = Route('name', 'url_part') >>> route.get_url_part() 'url_part'
- get_url_parts()[source]¶
Get a list of URL parts to generate patterns for. At least one URL pattern will be returned for each URL part returned by this function.
The default implementation returns a singleton (get_url_part()).
Returns: URL parts (list of URL part) Return type: iterable of str >>> class Route(BaseRoute): ... def get_callback(self): ... pass >>> >>> route = Route('name', 'url_part') >>> list(route.get_url_parts()) ['url_part']
- get_url_specs()[source]¶
Yield URL specifications. An URL specification is a 3-tuple, containing 3 django_crucrudile.urlutils.URLBuilder instances : prefix, name and suffix. These objects are used to join together different part of the URLs. Using them in a 3-tuple allows building an URL part with a “central” name, (whose parts are joined using -), a prefix (joined using /), and a suffix (joined using /, /?). This schema allows different subclasses to register different parts in the URLs (without interfering with each other, using super()), and provides automatic optional/required separator handling.
The base implementation yields a specification for each URL part returned by get_url_parts().
Note
The prefix, name and suffix names for the URL specification contents are purely indicative, and never used as identifiers. They are used in this package’s code for consistency.
Returns: URL specifications Return type: iterable of 3-tuple >>> class Route(BaseRoute): ... def get_callback(self): ... pass >>> >>> route = Route('name', 'url_part') >>> list(route.get_url_specs()) [([], ['url_part'], [])]
- get_url_regexs()[source]¶
Yield URL regexs to generate patterns for.
For each URL specification in get_url_specs() :
- Run each django_crucrudile.urlutils.URLBuilder instance in the URL specification 3-tuple (prefix, name and suffix)
- Pass builder outputs in another URL builder
- Run this builder, and yield output, prefixed with ‘^’ and suffixed with ‘$’
URL specifications are structured as follow :
- iterable (list of
- iterable (3-tuple) of
- iterable (URLBuilder) of
- URL part
We use django_crucrudile.urlutils.URLBuilder twice, first to join the URL parts in each URL builder of the specification (prefix, name and suffix), and then to join together the 3 resulting URL parts.
It’s not possible to flatten this list directly, because prefix, name and suffix may use different separators.
Returns: URL regexs Return type: iterable of string >>> class Route(BaseRoute): ... def get_callback(self): ... pass >>> >>> route = Route('name', 'url_part') >>> list(route.get_url_regexs()) ['^url_part$']
Route mixins¶
This module contains route mixins, that implement specific functionality for abstract class django_crucrudile.routes.base.BaseRoute() subclasses. Some of these mixins make the class “concrete” (as the abstract function django_crucrudile.routes.base.BaseRoute.get_callback() is implemented, the class can be instantiated).
Abstract¶
Arguments¶
This module contains the ArgumentsMixin route mixin, that uses parser.ArgumentsParser to create a list of argument combinations from the given argument list.
- class django_crucrudile.routes.mixins.arguments.ArgumentsMixin(*args, arguments_spec=None, **kwargs)[source]¶
Bases: builtins.object
Route mixin, that builds the argument combination list when instantiating, and that yields (in get_url_specs()) another URL specification for each argument in resulting list.
Should be a list that, if needed, contains argument specifications. An argument specification is a 2-tuple, contaning a boolean indicating if the argument is required or not,
Warning
This mixin does not make django_crucrudile.routes.base.BaseRoute a concrete class !
- arguments_parser¶
Attribute arguments_parser: Argument parser to use to build the argument combinations from the argument specifications. Should be a django_crucrudile.urlutils.Parsable subclass, or any class whose instances can be called to return its parsed output. alias of ArgumentsParser
- __init__(*args, arguments_spec=None, **kwargs)[source]¶
Initialize route, set arguments specification if given, and run arguments parser.
Parameters: arguments_spec – See arguments_spec Example with the default test parser (parser.ArgumentsParser) used with base.BaseRoute :
>>> from django_crucrudile.routes.base import BaseRoute >>> >>> class ArgumentsRoute(ArgumentsMixin, BaseRoute): ... def get_callback(self): ... pass >>> >>> route = ArgumentsRoute( ... 'name', 'url_part', ... arguments_spec=[ ... ['<arg1.1>', '<arg1.2>'], ... '<arg2>' ... ] ... ) >>> >>> list(route.get_url_regexs()) ... ['^url_part/<arg1.1>/<arg2>$', '^url_part/<arg1.2>/<arg2>$']
- arguments_spec = None¶
Attribute arguments_spec: Argument list that will be passed to arguments_parser. Should be structured as the arguments parser expects it.
- get_arguments_spec()[source]¶
Yield argument specifications. By default, return specifications from arguments_spec. Subclasses or mixins may override this method to add their own argument specifications.
Returns: Argument specifications Return type: iterable >>> list(ArgumentsMixin().get_arguments_spec()) []
- get_url_specs()[source]¶
Yield another URL specification for each argument in the argument combination list (arguments parser output).
Returns: URL specifications Return type: iterable of 3-tuple Example using the default test parser (parser.ArgumentsParser) :
>>> from django_crucrudile.routes.base import BaseRoute >>> >>> class ArgumentsRoute(ArgumentsMixin, BaseRoute): ... def get_callback(self): ... pass ... arguments_spec=[ ... ['<arg1.1>', '<arg1.2>'], ... '<arg2>' ... ] >>> >>> route = ArgumentsRoute( ... 'name', 'url_part', ... ) >>> >>> list(route.get_url_specs()) ... [([], ['url_part'], [(True, '<arg1.1>/<arg2>')]), ([], ['url_part'], [(True, '<arg1.2>/<arg2>')])]
Parser¶
This module contains the default arguments parser (ArgumentsParser), used in django_crucrudile.routes.mixins.arguments.ArgumentsMixin.
The combine() function is used by the cartesian product in ArgumentsParser.cartesian_product(), it joins an iterable (filtering out its items that evaluate to None) using a given separator.
- django_crucrudile.routes.mixins.arguments.parser.combine(iterable, separator)[source]¶
Join iterable (filtering out its items that evaluate to Ǹone) using separator
Parameters: - iterable (iterable) – Iterable to filter and join
- separator (str) – Separator to join with
Returns: Joined string
Return type: str
>>> combine(['Foo', '', 'Bar', None, 'Xyz', 0], '/') 'Foo/Bar/Xyz'
- class django_crucrudile.routes.mixins.arguments.parser.ArgumentsParser(iterable=None, separator=None, opt_separator=None, required_default=None)[source]¶
Bases: django_crucrudile.urlutils.OptionalPartList
This parser reads a list of argument specification, and builds an argument combination list (using a cartesian product). It subclasses django_crucrudile.urlutils.OptionalPartList (as an arguments list is an URL part list), and add its building parsers in ArgumentsParser.get_parsers().
The input of the parser should be a list of argument specifications. Argument specifications can be written as :
- (bool, string) : converted to (bool, list([string]))
- string : converted to (True, list([string]))
- list : converted to (True, list)
If bool is not defined, a default value will be used (see django_crucrudile.urlutils.Separated.required_default).
In (bool, list) :
- bool is a boolean flag indicating whether an argument list is required
- list is a list of argument, as “choices” : a combination will be generated for each item in the list
The output of the parser is a list of 2-tuple containing a boolean value and a string. The boolean value is a flag indicating whether the first argument of the string is required, and the string is the joined URL parts of the argument combination.
To set the separators, see django_crucrudile.urlutils.Separated.separator and django_crucrudile.urlutils.Separated.opt_separator.
With empty specifition (o
>>> parser = ArgumentsParser([]) >>> >>> parser() == ArgumentsParser()() True >>> >>> parser() ... []
With single item :
>>> parser = ArgumentsParser(["<my>/<arg>/<spec>"]) >>> list(parser()) ... [(True, '<my>/<arg>/<spec>')]
With first argument required :
>>> parser = ArgumentsParser([ ... ["<arg1.1>", "<arg2.2>"], ... "<arg3>", ... (False, ["<arg4.1>", "<arg4.2>"]), ... (True, ["<args5>"]) ... ]) >>> >>> parser() ... [(True, '<arg1.1>/<arg3>/?<arg4.1>/<args5>'), (True, '<arg1.1>/<arg3>/?<arg4.2>/<args5>'), (True, '<arg2.2>/<arg3>/?<arg4.1>/<args5>'), (True, '<arg2.2>/<arg3>/?<arg4.2>/<args5>')]
- get_parsers()[source]¶
Add transform_args_to_list(), cartesian_product() and consume_cartesian_product() to the parsers from django_crucrudile.urlutils.OptionalPartList.get_parsers().
Returns: Argument parsers list Return type: list of callable
- static transform_args_to_list(items)[source]¶
Transform second part of each item in items in a list if it’s not one.
Parameters: items (iterable of 2-tuple) – List of items to transform Returns: Transformed list Return type: iterable of 2-tuple : [(bool, list)] >>> list(ArgumentsParser.transform_args_to_list([ ... (None, '<arg1>'), ... (None, ['<arg2>', '<arg3>']) ... ])) ... [(None, ['<arg1>']), (None, ['<arg2>', '<arg3>'])]
- static cartesian_product(items, get_separator)[source]¶
Process cartesian product to get all possible combinations with argument lists in items.
Parameters: items (iterable of 2-tuple) – List of tuple to transform (2-tuple with a flag indicating if the argument specification is required, and the argument choice list) Returns: List of 2-tuple, with a flag indicating if the first item is required, and the joined list. Return type: iterable of 2-tuple : [(bool, str)] >>> get_separator = lambda x: '/' if x else '/?'
With first spec required :
>>> list(ArgumentsParser.cartesian_product( ... [ ... (True, ['<arg1>']), ... (True, ['<arg2>', '<arg3>']), ... (False, ['<arg4>', '<arg5>']) ... ], ... get_separator=get_separator ... )) ... [(True, '<arg1>/<arg2>/?<arg4>'), (True, '<arg1>/<arg2>/?<arg5>'), (True, '<arg1>/<arg3>/?<arg4>'), (True, '<arg1>/<arg3>/?<arg5>')]
With first spec not required :
>>> list(ArgumentsParser.cartesian_product( ... [ ... (False, ['<arg1>']), ... (True, ['<arg2>', '<arg3>']), ... (False, ['<arg4>', '<arg5>']) ... ], ... get_separator=get_separator ... )) ... [(False, '<arg1>/<arg2>/?<arg4>'), (False, '<arg1>/<arg2>/?<arg5>'), (False, '<arg1>/<arg3>/?<arg4>'), (False, '<arg1>/<arg3>/?<arg5>')]
Model¶
This module contains ModelMixin, a route mixin that can be used to bind a model to a route, and use it when computing route metadata.
- class django_crucrudile.routes.mixins.model.ModelMixin(*args, model=None, prefix_url_part=None, **kwargs)[source]¶
Bases: builtins.object
Route mixin that requires a model to be set either on the class (model attribute), or to be passed in __init__(), and provides the URL name and URL part using the model metadata.
Warning
This mixin does not make django_crucrudile.routes.base.BaseRoute a concrete class !
- __init__(*args, model=None, prefix_url_part=None, **kwargs)[source]¶
Initialize ModelRoute, check that model is defined at class-level or passed as argument.
Parameters: - model – See model
- prefix_url_part – See prefix_url_part
Raises ValueError: model argument is None, and no model defined in model
- model = None¶
Attribute model: Model to use on the Route
- prefix_url_part = False¶
Attribute prefix_url_part: Prefix the URL part with the model (ex: /model/<url_part>)
- model_url_name[source]¶
Return the model name to be used when building the URL name
Returns: URL name from model name, using Django internals Return type: str >>> from django_crucrudile.routes.base import BaseRoute >>> from mock import Mock >>> >>> class ModelRoute(ModelMixin, BaseRoute): ... def get_callback(self): ... pass >>> >>> model = Mock() >>> model._meta.model_name = 'testmodel' >>> route = ModelRoute(model=model, name='routename') >>> >>> route.model_url_name 'testmodel'
- model_url_part[source]¶
Return the model name to be used when building the URL part
Returns: URL part from the URL name (model_url_name()) Return type: str >>> from django_crucrudile.routes.base import BaseRoute >>> from mock import Mock >>> >>> model = Mock() >>> model._meta.model_name = 'testmodel' >>> route = ModelMixin(model=model) >>> >>> route.model_url_part 'testmodel'
- get_url_specs()[source]¶
Return URL specs where the model URL name is appended to the prefix part list if needed
Returns: URL specifications Return type: iterable of 3-tuple >>> from django_crucrudile.routes.base import BaseRoute >>> from mock import Mock >>> >>> class ModelRoute(ModelMixin, BaseRoute): ... def get_callback(self): ... pass >>> >>> model = Mock() >>> model._meta.model_name = 'testmodel' >>> route = ModelRoute(model=model, name='routename') >>> >>> list(route.get_url_specs()) [([], ['routename'], [])]
With prefix_url_part set to True :
>>> from django_crucrudile.routes.base import BaseRoute >>> from mock import Mock >>> >>> class PrefixModelRoute(ModelMixin, BaseRoute): ... def get_callback(self): ... pass ... prefix_url_part = True >>> >>> model = Mock() >>> model._meta.model_name = 'testmodel' >>> route = PrefixModelRoute( ... model=model, name='routename', ... ) >>> >>> list(route.get_url_specs()) ... [(['testmodel'], ['routename'], [])]
- get_url_name()[source]¶
Return the URL name built model_url_name() and Route.name.
Returns: compiled URL name Return type: str >>> from django_crucrudile.routes.base import BaseRoute >>> from mock import Mock >>> >>> class ModelRoute(ModelMixin, BaseRoute): ... def get_callback(self): ... pass >>> >>> model = Mock() >>> model._meta.model_name = 'testmodel' >>> route = ModelRoute( ... model=model, name='routename', ... ) >>> >>> route.get_url_name() 'testmodel-routename'
- class django_crucrudile.routes.mixins.model.GenericViewArgsMixin¶
Bases: builtins.object
This route mixin, that should be used with django_crucrudile.routes.mixins.arguments.ArgumentsMixin and django_crucrudile.routes.mixins.view.ViewMixin, enables automatic URL arguments for Django generic views.
- get_arguments_spec()¶
Add view arguments (returned by get_view_arguments()) to the arguments specification returned by the super implementation (django_crucrudile.routes.mixins.arguments.ArgumentsMixin.get_arguments_spec()).
Returns: Arguments specification Return type: iterable
- get_view_arguments()¶
Return URL arguments if the view class is a Django generic view that requires an URL argument for the object.
Returns: View argument specification Return type: iterable
Generic view arguments¶
This module contains GenericViewArgsMixin, a route mixin that can be used to automatically get the needed URL arguments for a Django generic view.
- class django_crucrudile.routes.mixins.model.generic.GenericViewArgsMixin[source]¶
Bases: builtins.object
This route mixin, that should be used with django_crucrudile.routes.mixins.arguments.ArgumentsMixin and django_crucrudile.routes.mixins.view.ViewMixin, enables automatic URL arguments for Django generic views.
- get_view_arguments()[source]¶
Return URL arguments if the view class is a Django generic view that requires an URL argument for the object.
Returns: View argument specification Return type: iterable
- get_arguments_spec()[source]¶
Add view arguments (returned by get_view_arguments()) to the arguments specification returned by the super implementation (django_crucrudile.routes.mixins.arguments.ArgumentsMixin.get_arguments_spec()).
Returns: Arguments specification Return type: iterable
Concrete¶
Callback¶
This module contains a route mixin, CallbackMixin, that implements django_crucrudile.routes.base.BaseRoute.
- class django_crucrudile.routes.mixins.callback.CallbackMixin(*args, callback=None, **kwargs)[source]¶
Bases: builtins.object
Route mixin, implements django_crucrudile.routes.base.BaseRoute, requires a callback to be set either on the class (callback attribute), or to be passed in __init__().
Note
This mixin makes the class concrete, as it implements the django_crucrudile.routes.base.BaseRoute.get_callback() abstract function.
- __init__(*args, callback=None, **kwargs)[source]¶
Initialize CallbackRoute, check that callback is defined at class-level or passed as argument
Parameters: callback – See callback Raises ValueError: If callback and callback are both None
- callback = None¶
Attribute callback: Callback that will be used by the URL pattern
- get_callback()[source]¶
Return callback
Returns: The callback set on class (callback) or passed to __init__(). Return type: callable
View¶
This module contains a route mixin, ViewMixin, that implements django_crucrudile.routes.base.BaseRoute.
- class django_crucrudile.routes.mixins.view.ViewMixin(view_class=None, name=None, auto_url_name_from_view=None, *args, **kwargs)[source]¶
Bases: builtins.object
Route mixin, implements django_crucrudile.routes.base.BaseRoute, requires a view class to be set either on the class (callback attribute), or to be passed in __init__().
The view class will be used to get the callback to give to the URL pattern.
Note
This mixin makes the class concrete, as it implements the django_crucrudile.routes.base.BaseRoute.get_callback() abstract function.
>>> class TestView: ... pass >>> >>> route = ViewMixin(TestView) >>> >>> route.view_class.__name__ 'TestView' >>> route.name 'test'
With auto_url_name_from_view set to False :
>>> class TestView: ... pass >>> >>> route = ViewMixin(TestView, auto_url_name_from_view=False) >>> >>> route.view_class.__name__ 'TestView' >>> >>> # Because :class:`ViewMixin` does not even set >>> # :attr:`django_crucrudile.routes.base.BaseRoute.name` if >>> # :attr:`auto_url_name_from_view` is ``False``, this will >>> # raise an attribute error : >>> route.name Traceback (most recent call last): ... AttributeError: 'ViewMixin' object has no attribute 'name'
- __init__(view_class=None, name=None, auto_url_name_from_view=None, *args, **kwargs)[source]¶
Initialize ViewRoute, check that view_class is defined at class-level or passed as argument.
Parameters: - view_class – See view_class
- auto_url_name_from_view – See auto_url_name_from_view
See also
For doctests that use this member, see ViewMixin
Raises ValueError: if both view_class and view_class are None
- view_class = None¶
Attribute view_class: View class that will be used to get the callback to pass to the URL pattern
- auto_url_name_from_view = True¶
Attribute auto_url_name_from_view: Automatically set route name using view class name (lower casing it, and stripping it of View)
- get_callback()[source]¶
Return callback using django.generic.views.View.as_view(), getting arguments from get_view_kwargs().
Calls View.as_view() on view class, with kwargs from get_view_kwargs(), to get callback to use in URL pattern.
Returns: Callback to use in URL pattern Return type: callable >>> from mock import Mock >>> callback = Mock() >>> mock_view = Mock() >>> mock_view.__name__ = 'MockView' >>> mock_view.as_view = lambda: callback >>> >>> route = ViewMixin(view_class=mock_view) >>> route.get_callback() is callback True
- get_view_kwargs()[source]¶
Return arguments to use when calling the callback builder.
Returns: Keyword arguments Return type: dict
- classmethod make_for_view(view_class, **kwargs)[source]¶
Return a subclass of this class, setting the view_class argument at class-level.
Also sets the django_crucrudile.routes.base.BaseRoute.name attribute using the view class name.
This is useful when combined with django_crucrudile.entities.store.EntityStore.register_class(), as it only accepts classes (in opposition to django_crucrudile.entities.store.EntityStore.register()).
Parameters: view_class (subclass of django.views.generic.view) – View class to set on the resulting class Returns: New class, with view_class attribute set to view_class argument. >>> class TestView: ... pass >>> >>> route_class = ViewMixin.make_for_view(TestView) >>> >>> route_class.__name__ 'TestRoute' >>> route_class.view_class.__name__ 'TestView'
Callback route¶
- class django_crucrudile.routes.CallbackRoute(*args, **kwargs)[source]¶
Bases: django_crucrudile.routes.mixins.arguments.ArgumentsMixin, django_crucrudile.routes.mixins.callback.CallbackMixin, django_crucrudile.routes.base.BaseRoute
Implement base.BaseRoute using a callback function.
Also use mixins.arguments.ArgumentsMixin to allow URL arguments to be specified.
View route¶
- class django_crucrudile.routes.ViewRoute(*args, **kwargs)[source]¶
Bases: django_crucrudile.routes.mixins.arguments.ArgumentsMixin, django_crucrudile.routes.mixins.view.ViewMixin, django_crucrudile.routes.base.BaseRoute
Implement base.BaseRoute using a view class function.
Also use mixins.arguments.ArgumentsMixin to allow URL arguments to be specified.
Model view route¶
- class django_crucrudile.routes.ModelViewRoute(*args, **kwargs)[source]¶
Bases: django_crucrudile.routes.mixins.arguments.ArgumentsMixin, django_crucrudile.routes.mixins.model.ModelMixin, django_crucrudile.routes.mixins.view.ViewMixin, django_crucrudile.routes.base.BaseRoute
Combine mixins.view.ViewMixin and django_crucrudile.routes.mixins.model.ModelMixin to make a route that can easily be used with a model and a generic view.
Also use mixins.arguments.ArgumentsMixin to allow URL arguments to be specified.
- get_view_kwargs()[source]¶
Make the view use mixins.model.ModelMixin.model.
This is the effective combination of mixins.model.ModelMixin and ViewRoute.
>>> from mock import Mock >>> >>> model = Mock() >>> route = ModelViewRoute(model=model, view_class=Mock(),name='name') >>> >>> route.get_view_kwargs()['model'] is model True
Generic model view route¶
- class django_crucrudile.routes.GenericModelViewRoute(*args, **kwargs)[source]¶
Bases: django_crucrudile.routes.mixins.model.generic.GenericViewArgsMixin, django_crucrudile.routes.ModelViewRoute
Combine ModelViewRoute with django_crucrudile.routes.mixins.model.generic.GenericViewArgsMixin to automatically get the needed URL arguments for route instances.