Add this to your admin change_list.html template to replace the actions drop-down with buttons.
This is a rewritten version of snippet [1931](http://djangosnippets.org/snippets/1931/) with Django 1.3 compatibility and cleaner code. Thanks to [andybak](http://djangosnippets.org/users/andybak/) for the idea.
Add login_required (or any other combination of decorators) to any view references by the urls created by patterns(...).
My personal little itch as an example...
urlpatterns += required(
login_required,
patterns('',
(r'^api/',
include(api.urls)),
)
)
I used the code from http://djangosnippets.org/snippets/901/ and expanded the code to have the possibility to map AD groups to the superuser attribute of Django's users.
The code updates the Django users database every time a user connects, so every change in the AD is replicated to the Django database.
Sometimes I don't want to reveal a staff-only view so I created this decorator, using ``django.contrib.admin.views.decorators.staff_member_required`` as my boilerplate. Non staff members are kicked to the 404 curb.
Suggestion: Create a file, ``decorators.py`` in your project (or single app) and import like so: ``from myproject.app_name.decorators import staff_or_404``.
This mimicks the keys used internally by the @cache_page decorators and site-wide CacheMiddleware.
Now you can poke them, prod them, delete them, do what you like with them (eg, delete after you update some content and you want a specific URL refreshed).
Dehydrates objects that can be dictionaries, lists or tuples containing django
model objects or django querysets. For each of those, it creates a
smaller/dehydrated version of it for saving in cache or pickling. The reverse
operation is also provided so dehydrated objects can also be re-hydrated.
*Example:*
>>> import pickle
>>> users = list(User.objects.all()[:20])
>>> print users
[<User: Indiana Jones>, <User: Bilbo Baggins>, ...]
>>> pickled_users = pickle.dumps(users)
>>> print len(pickled_users)
17546
>>> dehydrated_users = dehydrate(users)
>>> pickled_dehydrated_users = pickle.dumps(dehydrated_users)
>>> rehydrated_users = hydrate(pickle.loads(pickled_dehydrated_users))
>>> print rehydrated_users
[<User: Indiana Jones>, <User: Bilbo Baggins>, ...]
>>> print len(pickled_dehydrated_users)
1471
It was based in:
http://djangosnippets.org/snippets/1586/
Instead of doing this:
'attribute_name = forms.CharField(widget=forms.TextInput(attrs={'class':'special'}))`
You can do this in your template:
{{ form|cssclass:"attribute_name:special_class"|cssclass:"other_attribute:special_class" }}
**Your model:**
class TicketItem(models.Model):
hours = models.DecimalField(decimal_places=2, max_digits=6)
day = models.DateField()
order = models.ForeignKey(Order)
tickets = models.ManyToManyField(Ticket)
Now you want to auto save m2m fields in your forms.TicketItemCreateForm:
1. inherit from m2mForm-Class
2. define m2m_field(s)
**Example:**
class TicketItemCreateForm(m2mForm):
m2m_field = 'tickets'
class Meta:
model = models.TicketItem
Use this to send emails to your users, takes one template and renders it as html or text as needed.
Credits to
"""
Jutda Helpdesk - A Django powered ticket tracker for small enterprise.
(c) Copyright 2008 Jutda. All Rights Reserved. See LICENSE for details.
lib.py - Common functions (eg multipart e-mail)
"""
MIT licence
I only removed the specific project parts and made it general to use.
The original project repository https://github.com/rossp/django-helpdesk/
This code allows you to upload a mp3 to the Admin Frontend. The ID3 tags are automatically read out and filled in to the according fields.
This should work for other filetypes as well. As long as they have an id3 tag.
Simple password validation for user registration - requires that password be 7 or more characters and contain both letters and numbers. Original validation with regex approach developed by kurtis. Optimized no-regex version based on code from watchedman ran as fast or significantly faster on all systems on which we tested it.
A collection of utilities for admin log entries management.
This module provides functions to add log entries for instance addition,
change and deletion, as seen in *django.contrib.admin.options*.
It also provides a class based view mixin to add logging capabilities,
and other tools as a log collector.
See docstrings for a better description.
You're looking at the most-bookmarked snippets on the site; if you'd like to help useful snippets show up here, sign up for an account and you'll get your own bookmarks list.