Login

Most bookmarked snippets

Snippet List

Safing HTML Text Input

Personally I hate using markdown for text input just so it can be converted into HTML. Markdown languages almost always don't support some thing I want to do; thus, why not just use HTML in the first place. Well because you don't want anybody posting any kind of HTML on your site. Solution, instead of making your users learn markdown, let them enter HTML and filter out bad tags. This is a filter I use to filter HTML for only certain allowed tags. The allowed tags can be configured with the **allowedhtml** list. To make your text input even more user friendly use a Javascript HTML editor like [FCK Editor](http://www.fckeditor.net/) so your users will have a nice GUI editor.

  • template
  • filter
  • markup
  • markdown
  • html
Read More

Add extra form elements in your contib admin

Add extra form elements in your contib admin Install add this in header of base.html <script type="text/javascript" src="/static/jquery-1.2.6.min.js"></script> http://code.google.com/p/jqueryjs/downloads/detail?name=jquery-1.2.6.min.js

  • form
  • extra
  • elements
Read More

FlatPageOverrideMiddleware

This snippet is a piece of middleware that can be used to allow an administrator to create a flatpage that will override an existing URL. Why would you want such a thing? Maybe an admin needs to be able to override individual detail pages of an item list at will and doesn't want to be bothered mucking around with urlconf and restarting apache2. Obviously, it's not the ideal situation for permanent overrides (in that case, you'd be better off writing an exception in the urlconf), but it's good for the temporary, one-off, situations that may arise for whatever reasons.

  • flatpage
  • override
Read More

Permission Required Middleware

Wraps specified URL patterns with permission_required decorator. Allows you to quickly require a specific permission for an area of your site based only on a URL pattern. Assumes a passing knowledge of how Django permissions work and how to use them. See [User authentication in Django](http://docs.djangoproject.com/en/dev/topics/auth/#permissions) for more information.

  • middleware
  • permissions
Read More

Example usage of SimpleCouchPaginator

Example Usage of [Very basic CouchDB Paginator](http://www.djangosnippets.org/snippets/1208/) An Example setup of CouchDB with django can be found at: [Eric Florenzanos post about django+couchdb](http://www.eflorenzano.com/blog/post/using-couchdb-django/)

  • pagination
  • paginator
  • couchdb
  • example
Read More

A small script to rearranging the models generated from inspectdb command

`python manage.py inspectdb` allows you to generate the models from a legacy database. The generated model classes are not arranged by dependencies. When the number of tables is big, it becomes really painful to rearrange by hand. This small script should rearrange the models for you. It doesn't solve every problem with generated models, but it makes our the process easier

  • admin
  • inspectdb
  • arrangement
Read More

iPernity thumbnail helper

A simple template filter that detects [iPernity](http://www.ipernity.com) static URLs and creates clickable thumbnail for them. Use it with [Lightbox](http://www.huddletogether.com/projects/lightbox2/) or any other funky image overlay script. Your HTML code may contain this: <p>A short example <img src="http://...ipernity..." title="The Description" />.</p> After applying this filter it will become: <p>A short example <a href="http://...large version..." title="The Title"><img alt="The Title" src="http://...thumb version..."/> </a>.</p> Thats all! You may have a look at this: [iPernity and static URLs](http://www.ipernity.com/group/api-users/discuss/20098)

  • template
  • image
  • thumbnail
  • resize
  • ipernity
Read More

Cheap direct_to_tempalte patterns

Django cheap-pages Methods to use when you just want to use the Django dispatcher and there will be no extra business logic in your pages. In some cases flatpages is too flat, and store templates in DB is too much hassle >>> url(^name/$, ... direct_to_template, ... {'template': 'name.html'}, ... name='name') can be expressed as: >>> page('name') urlpatterns = patterns('', ...) urlpatterns += build('Regexp', ['page1', 'page2', ...])

  • generic
  • urlpatterns
  • direct_to_template
Read More

Test Integration for mako templates

This is a small addition to the mako template processing plugin for django that allows you to use the unit test framework with mako templates. To install, put the code into a file on your python path, and add the python path to your settings.py file. For example, if you install the code at /usr/lib/python2.5/site-packages/mako_django/test_integration.py you would add the following line to settings.py: TEST_RUNNER="mako_django.test_integration.run_mako_tests" This code will still call all of the normal test code, it just adds the mako template handler onto the list of things that are monitored.

  • mako
  • testing
  • test
  • mako-django
Read More

Rails Style Controller

Just a quick hack for a Controller style pattern. Similar to the approach taken in django.contrib.admin views things this breaks: 1. {% url %} and reverse() 2. validation provided by regex urlpatterns

  • python
  • controller
  • rubyonrails
Read More

django-pyodbc MoneyField

This is a very small, simple piece of code, but essential for using fields of type 'money' on MS SQL Server, through FreeTDS. This took me quite some time to hunt down, as get_placeholder() is in fact an undocumented feature. **Example:** class MyModel(models.Model): price = MoneyField()

  • money
  • convert
  • pyodbc
  • django-pyodbc
Read More

Allow editing of the selected object of the filter_vertical/filter_horizontal widget with jquery

This patch allows to open a popup to edit the selected object of either the left or right select input of a filter_horizontal or filter_vertical field, when pressing the "Insert" key. Being a noob with general client-side issue, it's served as a patch that suits my needs. Maybe it's possible to do it cleaner by overloading the javascript methods, or get rid of the jquery dependency in order to integrate it into django trunk ... Any contribution is welcome! It's licensed under WTFPL license. Requires jquery.

  • admin
  • jquery
  • widget
  • filter_horizontal
  • filter_vertical
Read More

Get stories by category and some date range

Removed for now... Not sure where to share new Ellington snippets due to the gray-area of it being proprietary. It's an awesome package but it's hard to find any good help with Django 91 code. Good luck ellingtoners!

  • date
  • stories
  • category
Read More

3110 snippets posted so far.