Login

All snippets written in Python

Snippet List

Get email and push on couchdb - Model

view/admin.py ` def reactor(request): context = { 'email': read_mailbox() } return render_to_response(_lookup_template('dashboard'), context, context_instance=RequestContext(request)) ` **_Design all.js** ` function (doc) { if (doc.doc_type == 'MailArchive') { emit(doc._id, doc); } } ` **reduce.js** `_count`

  • email
  • couchdb
  • couchdbkit
Read More

Generate a dineromail form in python

This is the code we use on bandtastic.me to build a html that sends users to dineromail to pay with. This code builds a form thats ready to send multiple items.

  • django
  • python
  • dineromail
  • express checkout
Read More

get and image object

I use this snippet to save images to my imagefields on django models. This uses the very awesome requests library, so install it first pip install requests You probably want to have this be done on a celery queu, if the image is big enough.

  • imagefield
  • save file
  • save url
Read More

Easier and Faster than flatpages. Rendering templates by simpling calling by his path on the URL

This is in my opinion a better way to have flat pages in a project. In the example with the url patterns settings: / will render -> /pages/welcome.html /contact will render -> /pages/contact.html /products/ will render -> /pages/products/index.html /products/pricing will render -> /pages/products/pricing.html

  • views
  • flatpages
  • class-based-views
  • 1.4
  • class-based-views_1
Read More

Encrypted paypal buttons

Function and usage in views and template with django-paypal to have encrypted paypal buttons with a cart(adding multiple elements). All credits go to Jon Atkinson, http://jonatkinson.co.uk/paypal-encrypted-buttons-django/ I just added it here with a complete implementation using a cart(his example didnt include it). I know there is some redundancy in the data passed to the dict and the submit form, i'm just not sure what can i take out, the paypal docs are not clear about it, if you test this code without some of the data and it works, please tell me. The key parts are the cmd _s-xclick and again the cmd '_cart' both are needed.

  • paypal
  • encrypted button
  • cart
Read More

Horizontal RadioSelect widget

The problem with Django's default Radio button widget is that it puts the buttons in a vertical format and the documentation is somewhat silent on how to make them horizontal. If you are dealing with a long list of buttons then veritical is probably the way to go but if you are dealing with "YES/NO" situation or any other boolean choice then you will probably want them horizontal. Basically I just took the code and even the explanation from here: https://wikis.utexas.edu/display/~bm6432/Django-Modifying+RadioSelect+Widget+to+have+horizontal+buttons

  • widget
  • radioselect
  • horizontal
  • radio
  • renderer
Read More

Handles Inline Formsets and also "in-standard-way" normal forms

If you read the docstring and the example you should get a clue what this Code does. I didn't want a big function everytime that handles every specific form, formset combinations so this how i can add/edit Models with specific Forms given to the magic_handle_inlineformsets function. It also works for Forms without innline_formsets.

  • forms
  • formset
  • inline
  • inlineformset
  • inline_formset
Read More

Test Suite URL Coverage

This custom test suite runner will record all of the URLs accessed during your test suite. It will compare it to the list of all URLs you have configured for your site and produce a report of any URLs missed. It requires that all URLs are named (using the ``name=`` parameter). To use is, set the ``TEST_RUNNER`` variable in your configuration to this class. You can also define ignored URLs. For example, to filter out the admin URLs, you can use: IGNORED_COVERAGE_URLS = ['^admin/', '^admin/doc/']

  • urlconf
  • testing
  • testrunner
Read More

One register on admin

This code is for set one register on admin if exist more than 1 register you can not delete it or add more. Only set mymodel

  • admin
  • no-add
  • no-delete
  • one-line
  • one-row
  • one-register
Read More

Admin Download as CSV File

This function downloads selected rows to CSV file. The snippet is based on snippet 1697 and 2020. This function downloads all columns given in the list_display, including callable items.

  • admin
  • csv
  • export csv
Read More

"Open file in Textmate"-support in werkzeug debugger browser view

1) Install django-extensions (requires werkzeug) 2) Paste snippet into settings.py 3) manage.py runserver_plus Now you should be able to open files in textmate by clicking the file links in the werkzeug error pages. It will also take you to the correct line number and highlight files that are in your project directory in a different color.

  • debug
  • error
  • debugging
  • textmate
Read More

2955 snippets posted so far.