This assumes that you have a method called **decode_signed_request** which will validate the signed_request parameter and return None if the validation check fails.
A similar method can be found here - https://github.com/iplatform/pyFaceGraph/blob/70e456c79f1ac1c7eddece03af323346a00481ef/src/facegraph/canvas.py
Just like it says -- set it up and run. Use it for server migrations, for project handoffs, in cron jobs, you name it.
I have never had problems exporting models to individual fixtures in this way, and only one bout of trouble re-importing them (and that was, like, an impossible-triangle of OneToOneField dependencies anyway, and they were going from a sqlite file to a postgres schema that totally had inappropriate nullable columns in it). I find that the json files named for what they contain is helpful when and if manage.py does freak out during an import, as the output from `loaddata` command is so opaque it's autistic, basically.
A trivial refactoring effort could make it into a management command -- it already makes use of the builtin `dumpdata` command class internally. However I did not feel like overthinking it enough to set it up in a repository (doubtlessly padded with unrelated 'utilities' and explanatory .rst files) and then writing a blog post to sell it to you. That is why you are reading this code here, instead of on GitHub.
Don't get me wrong, GitHub is awesome, and like a consummate host... but not the way I love me some quick and dirty snippet code, these days. Whatever, you say lazy, I say productively relaxed, potato/potahto.
Erm. In any case please do enjoy this model fixture-exporter. Yes.
Ok, I just took [wolever](http://djangosnippets.org/users/wolever/)'s snippet at [http://djangosnippets.org/snippets/1926/](http://djangosnippets.org/snippets/1926/) and added template variable/filter support for range values.
For instance, you could write something like this:
`{% mkrange 1 tool_page.paginator.num_pages|add:"1" as page_range %}`
I'm just learning python and django, so any advice would be appreciated.
Requires [PyISBN](http://pypi.python.org/pypi/pyisbn/0.5.2). Use like so:
class Book(models.Model):
title = models.TextField()
isbn = ISBNField()
... the link in the widget can be changed to amazon, borders, you name it.
If the DB version is a 13-digit ISBN, the display box contains the 10-digit,
labeled; and vice-versa.
This is what I use to send simple status emails from my sites. Instead of a django.core.mail.send_mail call, which can take an irrritatingly, nondeterministically long time to return (regardless of error state), you can stow the emails in the database and rely on a separate interpreter process send them off (using a per-minute cron job or what have you). You then also have a record of everything you've sent via email from your code without having to configure your outbound SMTP server to store them or anything like that.
Usage notes are in the docstring; share and enjoy.
I never found a good snippet or tutorial to get the app_list (in django.admin) on other pages except the index page. So i started asking on irc j00bar has given me a very nice answer, but first i didn't know what to do with it till now.
Anyways this snippet is very handy for the people who wants this but don't know how to get it.
This is special made for the django version 1.1
Installation is quite easy, it is a context processor, so download this file put anywhere in your project, i got it in a app called cms_theme (theme and template related stuff.) and put the location in your settings.py file, example:
`TEMPLATE_CONTEXT_PROCESSORS = (
'django.core.context_processors.auth',
'django.core.context_processors.debug',
'django.core.context_processors.i18n',
'django.core.context_processors.media',
'django.core.context_processors.request',
'****cms.cms_themes.context_processors.theme',
'****cms.cms_themes.context_processors.applist',
)`
The '****' stuff is nothing, i replaced my company name with it.
Of course you may put the context processor anywhere else, that is your choice.
Good luck!
Alexander
This Snippet allows a view to controle the printed forms on the templates, in a similar way to the fieldsets used by the django admin.
How to Use:
In the view in question, put:
def some_view(request):
...
fieldsets = (
(u'Title 1',
{'hidden' : ('field_1', 'field_2',),
'fields' : ('field_3',)}),
(u'Title 2',
{'hidden' : ('field_5', 'field_6',),
'fields' : ('field_4',)}),)
)
return render_to_response('some.html', {'fieldsets': fieldsets})
fieldsets = (
(None,
{'hidden' : ('evento', 'colaborador',),
'fields' : ('acompanhantes',)}),
)
Next, in the html just add:
<form enctype="multipart/form-data" id="edit" method="post" ...>
...
{% include "inc/form_snippet.html" %}
...
<input type="submit" value="Submit">
</form>
This Snippet allows for your project's apps names to be displayed as you want in the Admin, including translations.
The lists of apps and languages are created from your settings.py file.
**How to use**
1st part:
- Create a application called 'apps_verbose' in you project with the models.py and admin.py showed here
- Create a folder inside it with named 'templatetags' with the verbose_tags.py file inside it.
- Add this app to installed apps in your settings.py
- If you change this app name, dont forget to correct the imports.
2nd part:
- Create a folder named 'admin' in your templates folder and copy the following files form your /django/contrib/admin/templates/admin/ folder.
- /app_index.html
- /base.html
- /change_form.html
- /change_list.html
- /delete_confirmation.html
- /delete_selected_confirmation.html
- /index.html
- /object_history.html
- Make the necessary changes in each file, like shown here.
3rd part:
- Create translations in the Admin and enjoy.
I was using flup to run django in fcgi mode and encountered the dreaded "Unhandled Exception" page quite frequently. So apart from all the precautions about handling this except, I wrote the above code snippet, which checks the import across your ENTIRE project. Ofcourse this can be used on any python project, but I have written it for my favorite framework django. It is now written as a Django command extension, an can be run as:
**python manage.py imports_checker**
This is a generic command, it does not check the settings.INSTALLED_APPS setting for cleaning. But can be improved to do the same.
Public Clone Url: [git://gist.github.com/242451.git](git://gist.github.com/242451.git)
Update: Now it supports checking imports, just only at the app level also
usage: python manage.py imports_checker <appname>
This is "pyText2Pdf" - Python script to convert plain text into PDF file.
Originally written by Anand B Pillai.
It is taken from http://code.activestate.com/recipes/189858/
Modified to work with streams.
Example: produce PDF document from text and output it as HTTPResponse object.
import StringIO
input_stream = StringIO.StringIO(text)
result = StringIO.StringIO()
pdfclass = pyText2Pdf(input_stream, result, "PDF title")
pdfclass.Convert()
response = HttpResponse(result.getvalue(), mimetype="application/pdf")
response['Content-Disposition'] = 'attachment; filename=pdf_report.pdf'
return response
This is another partial tag, taken from a previous partial tag.
The previous one assumed template locations by hardcoding in "partials/%s", etc. I took all that out, and made it work. And I took out the not needed third parameter for passing in your own data
So now you call like this:
{% partial "partials/mypartial.html" %}
It passes the template context var into the partial, so anything you do in the main template, will work in the partial
Just make sure you've got all the right imports.
Is an updated way of splitting contents for a token, it does the split, but fixes the list..
EX:
From a tag call like this: {% partial "partials/template.html" %}
usually you get: ['partial','"partials/template.html"']
notice the " double quotes
fixes it with: ['partial','partials/template.html']
takes out the " quotes