Route class¶
CRUDLFA+ introduces an MVC-ish pattern, as the Router class is meant to sit between a Model class and its set of View. Your views will have to inherit from Route to work in Router.views. This structural decision made for you by CRUDLFA+ was not exactly designed: it’s an open source rewrite of a module that was ordered in a proprietary project.
- class crudlfap.route.Route[source]¶
The mixin for Views that will make it compatible with Router.
- authenticate¶
False by default, it makes the default has_perm() implementation require Django permission.
- urlargs¶
Args that should be passed to reverse() along with Route.urlfullname.
- url¶
Absolute url to the view, relying on Route.urlfullname and Route.urlargs.
You will be able to check if a user has access to a view with a given object for example as such:
crudlfap.site[YourModel]['detail'].clone( request=request, object=obj, ).has_perm()
If you want to open a View to all, set authenticate=False, examples:
class YourDetailView(DetailView): authenticate = False class YourRouter(Router): views = [ YourDetailView, ListView.clone(authenticate=False), # example with clone ]
Without authenticate=False, the default has_perm() implementation requires the request user to have the permission corresponding to the permission_fullcode attribute.
To create the permission with permission_fullcode, you can browse in your CRUDLFA+ site and navigate to URL list view, for each URL you have link in the menu called “authorized” that lets you select which groups have this permission: it will auto-create the permission in the database if necessary.
- get_permission_fullcode()[source]¶
Return a string with the app name, permission_shortcode and model name.
- get_permission_shortcode()[source]¶
Return the middle part for the view permission.
Returns the urlname by default.
- get_url()[source]¶
Return the URL for this view given its current state. Given that the
reverse()method is a class method, this should allow things like:url = YourView(object=your_object).url
- get_urlargs()[source]¶
Return args for reversing this view url from self. See
self.reverse()for detail.
- has_perm()[source]¶
Called to decide if user has the permission to execute this view.
This is what you should override to code view level permission logic, unless you want to use a Django permission backend.
If unsure, you probably need to just define Router.has_perm.
Default behaviour:
return True if the view
authenticateattribute has been overridden to Falsereturn self.router.has_perm(self) if the view has a router
return self.has_perm_backend otherwise, to let a Django permission backend decide
- has_perm_backend()[source]¶
Django Authentication backend has_perm() call.
This is called by Route.has_perm by default, from Router.has_perm is the view has a router object, and useful only if you implement your own permission backend, or add crudlfap_auth.backends.ViewBackend to settings.AUTHENTICATION_BACKENDS, or implement your own View permission backend.
If unsure, you probably need to just define Router.has_perm.
- class crudlfap.route.RouteMetaclass[source]¶
Base autocalculations for views.
- app_name¶
The view’s app name.
- model¶
The view’s model if any.
- urlpath¶
The path for the url path definition.
- label¶
The view label, serves as key in a Router.views.
- urlpattern¶
The Django URL path() instance, for inclusion in url lists.
- urlfullname¶
The full name to reverse the URL, with namespaces if any.
- urlfield¶
The default model field that will be use to match in the URL. It can be pk, or name, slug …