This is a very simple way of getting authenticated RSS feeds in django, by slightly changing the django.contrib.syndication.views
1) copy django/contrib/syndication/views.py into mysite/feeds/views.py
2) replace the contents of that file with the snippet
3) any feeds which you require login just add them to the auth_required list. In this case I require login for /feeds/mystuff/ so I make auth_required = ['mystuff']
My directory structure is like this:
mysite/feeds/
views.py
feedmodels.py
feedmodels.py is just where you make your feed models (see http://docs.djangoproject.com/en/dev/ref/contrib/syndication/ where they give an example of "LatestEntries")
[urls.py] - this is what I add in urls.py
from mysite.feeds.feedmodels import Latest,MyPersonalStuff
feeds = {
'latest':Latest,
'mystuff':MyPersonalStuff,
}
(r'^feeds/(?P<url>.*)/$', 'mysite.feeds.views.feed', {'feed_dict': feeds}),
###########################################################################
Ever wished you could have pretty SQL-like output for a python object (e.g., a list of dicts) while you're debugging your code? This function will do just that. Simply pass it an object that is an iterable of dictionaries and it returns it in an easy-to-read table, similar to the output of commandline SQL.
Example:
from tablelize import tableize
from django.contrib.auth.models import User
print(tableize(User.objects.values('email', 'first_name', 'last_name')))
+------------+-----------+-------------------+
| first_name | last_name | email |
+------------+-----------+-------------------+
| Test | User | [email protected] |
| Another | User | [email protected] |
+------------+-----------+-------------------+
Custom serialization, the poor try to make something like [django full serializers](http://code.google.com/p/wadofstuff/wiki/DjangoFullSerializers)
Usage:
you need two files, goodjson.py and goodpython.py, for example, in the root of application named "core". Then, add two lines into your settings.py:
SERIALIZATION_MODULES = {'goodjson' : 'core.goodjson',
'goodpython': 'core.goodpython'}
This thing does only serialization, not deserialization. You were warned.
DateTimeWidget using [JSCal2](http://www.dynarch.com/projects/calendar/)
Duplicate of [this snippet](http://www.djangosnippets.org/snippets/391/), but for latest 1.5 version of DHTML Calendar.
Also here is **fixed problem of previous widget** linked to *form.changed_data* and *EntryLog.message*. This is fixed by adding own, little modified *_has_changed()* method
This tag is designed to facilitate pagination in the case where both the page number and other parameters (eg. search criteria) are passed via GET.
It takes one argument - a dictionary of GET variables to be added to the current url
Example usage:
{% for page_num in results.paginator.page_range %}
<a href="{% append_to_get p=page_num %}">{{ page_num }}</a>
{% endfor %}
Note that the passed arguments are evaluated within the template context.
If you have a model with foreign key to User, you can use this manager to show (i.e. in admin interface) only objects, that are related to currently logged-in user. Superuser sees all objects, not only his.
Requires: [ThreadlocalsMiddleware](http://code.djangoproject.com/wiki/CookBookThreadlocalsAndUser)
This is another foreign key to User model. User is automatically associated before save.
Requires: [ThreadlocalsMiddleware](http://code.djangoproject.com/wiki/CookBookThreadlocalsAndUser)
Inspired by: [snippet 509](http://www.djangosnippets.org/snippets/509/)
Simple function that tests whether a given IP address is in a list of IP addresses or subnets.
Requires `ipaddr`. Comes with Python 2.7 or 3.1, [downloadable here](http://code.google.com/p/ipaddr-py/) for earlier versions.
More info on `ipaddr` [in Python 3.1 docs](http://docs.python.org/dev/py3k/library/ipaddr.html).
This is a small approach to have a middleware which automatically creates a ticket in an existing Trac environment.
**Note:** you must have the [XML-RPC-Plugin](http://trac-hacks.org/wiki/XmlRpcPlugin) installed.
Extend the attrs-dict to your needs. For example: in my case I have the SensitiveTicket-Plugin installed - automatically created tickets are marked as sensitive and are not visible to the public.
When using the django admin as a means of moderating reviews on a site, the obvious choice was to use admin actions and do everything from a single screen. The I stumbled across was that after the actions were peformed, the app redirected to the change list without any filters. This meant that filtering on un-moderated reviews was lost as soon as a change was made.
It turns out that the solution is pretty simple, you just put a redirect to request.get_full_path() at the end of the admin action. I think this should be the default behaviour, but the fix is simple nonetheless.
Example of using django localeurl with sitemaps. Create sitemap instance for each combination of the sitemap section and language.
In your sitemap class create method
`
def location(self, obj):
return chlocale(obj.get_absolute_url(), self.language)
`
or inherit it from LocaleurlSitemap class.
The django_admin_log only logs changes, not simple requests.
Sometimes it can be useful to log when a user of your admin interface is checking out important data, for instance if you are making a system with personal sensitive data, that needs to comply with government / company policies.
This will log such hits to the django_admin_log by overriding the change_view method in ModelAdmin.
So you must override this method in all classes you want to have logged.