This is a class I use instead of the default PayPalPaymentsForm in django-paypal.
I wanted to use the Paypal sandbox on my development site and the real Paypal site on my production site. Currently, if you want to output the Paypal form with the sandbox you have to call the sandbox() method on the form, rather than the render() method.
Using this class instead of the default PayPalPaymentsForm, you can just set PAYPAL_DEBUG to True in the settings file and the form will take you through to the sandbox instead. Don't forget to set the sandbox merchant account's business email address as PAYPAL_RECEIVER_EMAIL too.
Use this class to authenticate against Drupal 7 password strings. When importing passwords from Drupal, the database values should be prefixed with "drupal$".
In contrast to the two present solutions, this class also works with passwords which were imported to Drupal 7 (e.g. from Drupal 6 or phpBB) and with passwords with variable iteration numbers. It is possible to use this class for encoding passwords, but due to questionable design decisions in Drupal (like truncating the non-standard base64 encoded hash at 43 characters) I'd recommend to do this this only if you really need to be able to migrate back to Drupal.
It's haystack whoosh backend code which involves stemming for specific language in time of indexing.
2 lines was changed comparing to original whoosh backend (StemmingAnalyzer replaced with LanguageAnalyzer for russian language, list of supported languages: [here](https://bitbucket.org/mchaput/whoosh/raw/default/src/whoosh/lang/snowball/__init__.py) )
Sometimes you just don't want to display every permission django has, you just want a short list showing the permissions for some of your apps (or even django core apps).
GROUP_PERMISSIONS_MODELS must be a list of your app models. Dotted path (in lowercase) required, app name + model *class* name.
Template context processor for delegating other context processors to individual apps.
Useful if all views within an app require common context variables that aren't required by other apps.
Wanted a simple function to concatenate n dictionaries. Each dictionary passed in is deep copied to avoid any possible mutation of dictionaries being concatenated.
Dictionary m's key/values will be overwritten by dictionary m+1's key/values.
Tag to correctly uppercase Greek characters with accent, copy the code in your templatetags folder in a file of your choice, load it in your templates {% load yourfile %} and use it as {% string|gruppercase %} the code works also with other languages, it won't modify anything (eg {% ukwork|gruppercase %} as it transforms only Greek characters (unless your language contains Greek characters).
Custom template filter to retrieve a content type of a given model instance. Useful for ModelForms which want to set the content_type field (i.e: GenericForeignKey).
### A usage example:
{% load helpers %}
{% with instance|content_type as ctype %}
<input type="hidden" name="content_type" value="{{ ctype.pk }}">
{% endwith %}
Original idea from [this stackoverflow answer] [1]
[1]: http://stackoverflow.com/a/12807458/484127
This module extends the standard `url' template tag in Django and adds support for fully qualified domain name URLs. It also can be extended with simple URL load balancing techniques if desired.
See my blog for the background story:
<http://atodorov.org/blog/2013/12/22/django-template-tag-inheritance-howto/>
Validate form field that include email or emails separated by 'token' kwargs, by default ',' a comma. Return a list [] of email(s). Check validity of the email(s) from django EmailField regex (tested with 1.3, but normally will also work with 1.5)
Beware if using Amazon Simple Queue Service to execute Celery tasks which send email messages! Sometimes SQS messages are duplicated which results in multiple copies of the messages being sent. This is a simple decorator which uses a cache backend to prevent the task from executing twice in a specified period. For example:
@task
@execute_once_in(3600*24*7)
def cron_first_week_follow_up():
"""
Send a follow-up email to new users!
"""
pass
For more info see
<http://atodorov.org/blog/2013/12/06/duplicate-amazon-sqs-messages-cause-multiple-emails/>
<http://atodorov.org/blog/2013/12/11/idempotent-django-email-sender-with-amazon-sqs-and-memcache/>
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.