Just a dump of a countries data, including standard codes & dial-codes, based on the following model:
- Country
-- name : CharField
-- code : CharField
-- dial_code : CharField
Note that countries aren't unique, as some may have several intl. dial codes.
You can parse it using script or load it using the loaddata command.
A Django form widget which displays help text for individual items in a set of radio buttons.
It overrides the RadioSelect widget, adding a small bit of HTML after each <input> element, with the help text for each item.
It was developed for a Django Dash project I'm working on (called transphorm.me), so isn't as feature-rich as it could be, but if you have any trouble installing it - or if I've miscopied any of my code in my rush - please let me know.
*JsonWebService.jsonresponse
JsonWebService provides the property jsonresponse which marks the method it is applied to, and also serializes to json the response of the method.
*JsonWebService.urls
Scans the marked methods and build a urlpattern ready to use in urls.py
Simple logging decorator. Logs the function name along with the message.
`Jul 14 16:10:42 mtzion test_func: 1 two`
Define SYSLOG_FACILITY in settings.py.
import syslog
SYSLOG_FACILITY = syslog.LOG_LOCAL1
Lets you include another template and pass in named variables. Use like:
{% partial field_template field=form.city %}
If no key is specified, it will use "item" instead. You may pass in multiple variables as comma-separated key=value pairs.
A simple decorator to register a template.Node object as a tag, without the need to write the usual "`token.split_contents()` yatta yatta blatta blatta" function.
The decorator should be called with the name of the tag, and an optional `required` named argument in case your tag requires a minimum number of arguments.
Please note that all the arguments in the templatetag call will be passed to the node (except the templatetag name and the `for` and `as` keywords) in the order given.
Suggestions etc are very welcome, of course =)
Based fully on [snippet 1929](http://www.djangosnippets.org/snippets/1929/)
**The update is:**
It checks to see the view returns an instance of HttpResponse and returns that rather than trying to render it.
This allows you to return something like `HttpResponseRedirect('/')`, or use a normal `render_to_response` to use a different template.
*Also updates cleandict as per comment on original snippet*
In this case the 'render_template' decorator assumes there is a myview.html template. this keeps things simple and you DRY. Hope it helps.
I wasn't sure if my setup supported sessions properly. This view helped me make sure.
Usage: fill the inputs with text and make sure that these values traverse a couple of requests. If it doesn't work then maybe the session backend you've set is broken?
A decorator that allows the programmer to restrict access to some views only to non logged-in users. For instance, if an user in logged in, it should be denied access to views like /accounts/register or /accounts/login.
It is often convenient to be able to specify form field defaults via GET parameters, such as /contact-us/?reason=Sales (where "reason" is the name of a form field for which we want a default value of "Sales"). This snippet shows how to set a form's initial field values from matching GET parameters while safely ignoring unexpected parameters.
Middleware to decorate views with user_passes_test in a centralized, url-matching manner. Makes it easy to apply permissions across large sections or all of a site.
This templatetag let's you output a form with select boxes instead of the ul's for filters.
Uses some hacks to get the param names out of query strings.
This would be a lot easier if filterspecs defined params instead of query strings
(if filter tag would handle the encoding)
This is simple validation weather a string is close enough to what we want. First param is keyword we are comparing to Second is user's input and third is tolerance level. Its very rudimentary. I have my mind fixed upon some imperfections. I am trying to make it good for human like(crazy keyboard) error.
You're looking at the top-rated snippets currently on the site; if you'd like to contribute, sign up for an account and you'll be able to rate any snippet you see.