Login

Tag "django"

Snippet List

chdjango

This is a convenient script for those working with different branches of Django. Place all of your branches in `~/django` (e.g., `~/django/newforms-admin`, `~/django/trunk`) and you're ready to quickly change between them. For example: `chdjango.py trunk`.

  • django
  • path
  • change
  • chdjango
  • branches
  • pth
  • site-packages
Read More

Tagging System

This is my personal tagging system that I have created. It is intended to be used for multiple applications. This tagging system also has a build in tag cloud that will generate based on the most frequently used tags that you have used or based on the number of clicks users have clicked on a particular tag.

  • tag
  • django
  • python
  • tags
  • tagging
  • tagger
Read More

Foldable Admin Interface

Have you had a rather huge database, say 50-100+ tables? Why not compress the tables you don't want to see and expand the ones that you do want to see? This template should do the trick. It uses cookies to remember which tabs you have open and which ones you have closed. This should work on .91 to current. How to install - just CP code and save as index.html toss in your media folder under /path_to_media/template_folder/admin/index.html. next download mootools and toss this into /path_to_media/js_folder/mootools.js (alternatively you could be lazy and cp mootools into the script tag of this template) A quick and dirty fix but it sure saves time trying to find the tables you are looking for.

  • django
  • admin
  • templates
  • html
Read More

Alternate method of autoloading Django models in ipython

This is a little improvement to the [idea](http://www.djangosnippets.org/snippets/540/) from sheats a few days ago. I like it over the previous solutions because it doesn't involve doing anything other than running `./manage.py shell` inside your project directory. You don't have to create any files anywhere or remember to call anything, and `ipython` still works fine outside of a Django project. Throw this code in `~/.ipython/ipy_user_conf.py` (`ipythonrc` has apparently been deprecated).

  • django
  • model
  • manage.py
  • shell
  • ipython
Read More

Cache decorator

You can use this cache all your functions' output, except dynamic things like connection.cursor.

  • django
  • cache
  • decorator
Read More
Author: xyb
  • 0
  • 9

duplicate model object merging script

Use this function to merge model objects (i.e. Users, Organizations, Polls, Etc.) and migrate all of the related fields from the alias objects the primary object. Usage: from django.contrib.auth.models import User primary_user = User.objects.get(email='[email protected]') duplicate_user = User.objects.get(email='[email protected]') merge_model_objects(primary_user, duplicate_user)

  • django
  • fields
  • model
  • generic
  • related
  • merge
  • duplicates
  • genericforeignkey
Read More

cron/console bootstrap django

Call this function as the first thing in your cron, or console script; it will bootstrap Django, and allow you to access all of the Django modules from the console, with out using 'python manage.py shell' Examples: # A script within your django project. from django_bootstrap import bootstrap bootstrap(__file__) --- or --- # A cron script located outside of your django project from django_bootstrap import bootstrap bootstrap("/path/to/your/project/root/")

  • django
  • console
  • cron
  • bootstrap
Read More

Integrating Django with ToofPy

[ToofPy](http://pyds.muensterland.org/wiki/toolserver.html) is a python server that supports WSGI so you can integrate Django with it via the WSGI handler. There is already some default Django integration in the source, but it looked really hacked up with many `if hasdjango:` lines all over the place and hardcoded URLs. A really simple solution is to create a Tool for wrapping around Django. That is what the above file does. So I removed most of the hardcoded django lines and created the tool above. ToofPy dynamically loads tools based on paths on the filesystem, so you'll need to put the file above in the WSGI folder path. Or, if you want to pre-integrate, import the file in the _initops function of WSGIMainTool just after the code to scan the directory.

  • django
  • python
  • toofpy
  • toolserver-for-python
Read More

django image bundle template tag library

Django ImageBundle tag, an implementation of image bundle by google: http://code.google.com/p/google-web-toolkit/wiki/ImageBundleDesign. Here is how to use it: http://www.djangosnippets.org/snippets/278/

  • django
  • imagebundle
Read More

Roman Numeral Filter

Template filter to convert integer or long integer into roman numeral with support for upper and lower case numerals. Requires python-roman package on Debian which apparently comes from http://www.diveintopython.org/

  • django
  • python
  • roman-numerals
Read More

Django Using Stored Procedure

Here is an clean example of using stored procedure using django. It sounds pretty weird "stored procedures in django" but for legacy database system we still need a clean approach to implement stored procedures using django. In this example, I've implemented logic inside models.py by creating a dummy class, i.e a django table (which is comparable to package in your database) and inside this package/class i added stored procedure wrappers. I tested it with boulder-oracle-sprint branch, there is minor issues with LazyDate in db/backend/oracle/base.py but it still working after minor edits in base.py. It worked absolutely fine with MySQL and MSSQL. View is pretty straight forward. Dont forget to create form.html as template and in body just put {{ form }}

  • django
  • stored
  • procedures
  • oracle
  • mysql
Read More

Convert LaTeX templates to various output formats

**The code is a bit messy and may include bugs ;-) Anyway, I want to clean it up and add features (see below).** The `process_latex()` function will read the given template, render it with a custom context and convert it into the desired output format by running it through pdflatex. Depending on the `outfile` parameter, the output will either be returned (for a response object) or written to the path specified in `outfile` (useful for `save()` in models which generate static, unique files). **TODO** * Error handling in case pdflatex breaks (non-zero return value) * Optionally returning a HttpResponse with the correct mimetype and Content-Disposition set to attachement and an appropriate filename * RequestContext instead of Context (passing the Context object instead of a dict) **CREDITS** Credits also go to ronny for the names dict :-P

  • template
  • django
  • pdf
  • dvi
  • png
  • latex
  • pdflatex
Read More

Upload a file using newforms

Django's transition from oldforms to newforms is nearing. If you're using recent trunk source code from Django's subversion repository, you should start using newforms. But there are still some rough edges as of today. File uploading seems to be one of them. (Adrian and other Django folks are well aware of this. Please don't bother them by asking "Are we there yet?") The Django mailing lists and Google searching didn't turn up any best practices for this area of newforms, so I muddled through it and here's the result. I omit the urls.py code necessary to hook up the zip_upload method to a URL, but otherwise this should be complete. And if I haven't loaded this with enough caveats...please be aware this code may be obsoleted soon.

  • django
  • newforms
  • files
  • forms
Read More

213 snippets posted so far.