Snippet List
This decorator allows edit or delete for the owner of the record. Snippet applies for every model that has ForeignKey to User. Works for User model too. Works with other decorators as permission_required or similar.
Decorator raise http 403 view if user is not owner.
**Usage**
@permission_required('blogs.change_entry')
@owner_required(Entry)
def manage_entry(request, object_id=None, object=None):
Decorator populates object kwargs if object_id present, otherwise just returns original view function.
@permission_required('blogs.delete_entry')
@owner_required()
def entry_delete(*args, **kwargs):
kwargs["post_delete_redirect"] = reverse('manage_blogs')
return delete_object(*args, **kwargs)
In generic delete wrapper view returns original view function.
This is just an example, **NOT any particular tag**. I was just tiered in examining every bits in list. I converted list to dictionary for easier manipulation of parameters. You can use this keeping in mind syntax:
{% tag_name 1_key 1_value 2_key 2_value %} and so on...
For use in templates:
{% if object|classname:"entry" %}
... class="{{ object|classname }}" ...
I couldn't find simpler solution for checking weather specific object belongs to specific class name, or just to output object's class name.
**Problem**:
You search by firing POST and paginate by firing GET, so search results disappear on GET. I want to preserve searching results, so user can paginate them.
First I try to use some static class to keep search results, but this solution has bug (thanks to svetlyak). In multiuser environment other user searching got results from previous one. No @cache_control(private=True) helps so I decided to change searching schema by using GET in the first place and to supply query string on each 'paging' request. Also added some memory cache that expires after 5 min
**In template**
Please append query to each paging link:
<a href="?page={{ page_number }}
&search_query={{ query|urlencode }}">
{{ page_number }}</a>
This snippet should keep search results on pagination in multiuser environment.
- search
- pagination
- static-class
polarbear has posted 4 snippets.