Login

Tag "script"

Snippet List

Load dynamically loaded form javascript assets using dajax

I am used to load forms directly into modals using dajax but I found out I had to load the scripts using an ajax call from the browser. You can see here an example of a dynamically loaded form and the function used to load the scripts.

  • ajax
  • javascript
  • forms
  • script
  • dynamically-loaded-form
  • form-assets
  • dajax
Read More

Export Django data to datestamped tarball -- choose individual models for handy packaging and archiving

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.

  • django
  • python
  • json
  • export
  • data
  • script
  • command
  • archive
  • django1.1
  • backup
  • datestamp
  • tar
  • tarball
Read More

Middleware to move tags <script> to the bottom

This middleware makes the page load faster because it moves all tags <script> to the end of document. When a tag <script> loads, it blocks parallel loading, so, the best practice is load them after load CSS and images. To use it, just put in a file and add to your setting MIDDLEWARE_CLASSES.

  • performance
  • script
  • otimization
Read More

Script factory for monitoring django-sphinx with Nagios

This snippet is used to create a script for monitoring sphinx status with Nagios via [django-sphinx](http://code.google.com/p/django-sphinx/). It returns 0 (OK) or 2 (CRITICAL). Remember to change this strings `ModelToMonitor` and `app_name`. Usage : `./manage your-controls-command --log` > /your/script/name.py

  • sphinx
  • script
  • management
  • nagios
  • monitoring
  • django-sphinx
  • factory
Read More

Update All Apps to Latest Revision

This snippet is based on [#844](http://www.djangosnippets.org/snippets/844/ "#844") and [#892](http://www.djangosnippets.org/snippets/892/ "#892") and updates all apps in the current directory using hg, svn, git or bzr. Including subdirectories not under version control (subfolders to keep your stuff organized). For example: python/lib/ django-trunk/ django-0.96/ pydelicious/ (...) django-apps/ django-tagging/ django-pagination/ django-registration/ django-threadedcomments/ django-mptt/ (...) The script will iterate through all of your apps (in the current dir and also recursively in subdirs NOT under version control) and update them to the latest version. To run, simply execute: python update_apps.py in the desired parent folder. Just in case it could be useful: In my case I'm using MAC OS X. I have a folder full of miscellaneous scripts under my HOMEDIR, with this content: /Users/Dedaluz/bin/update_apps.py /Users/Dedaluz/bin/update_apps (this is a bash script) The update_apps script contains simply: #!/bin/bash python /Users/Dedaluz/bin/update_apps.py Then I put this folder in my path, so in my /HOMEDIR/.bash_profile I add this line export PATH=$PATH:$HOME/bin And I just can update from any parent folder just going there and typing: update_apps

  • script
  • update
  • svn
  • git
  • hg
  • bzr
Read More

Command Line Script Launcher

I often write short test or development scripts that are intended as one-offs. I typically want to execute these scripts from the command line but am always forgetting the necessary steps to set up the Django environment [as described here][bennett]. This snippet allows you execute arbitrary Python scripts from the command line with the context of a given project: python manage.py execfile /path/to/some/script.py Add the code to a file named `execfile.py` within the `management/commands` directory of one of your apps ([see here][ref] for details). [ref]: http://www.djangoproject.com/documentation/django-admin/#customized-actions "Customized Actions" [bennett]: http://www.b-list.org/weblog/2007/sep/22/standalone-django-scripts/ "Standalone Django Scripts"

  • script
  • management
  • execfile
Read More

Update All Apps to Latest Revision

A simple script that I have put in my Django applications directory to fetch the latest application code from git and svn. For example, your directory structure might look like so: django-apps/ django-tagging/ django-pagination/ django-registration/ django-threadedcomments/ django-mptt/ update_apps.py Where update_apps.py is the source of this snippet. To run, simply execute: # python update_apps.py And the script will iterate through all of your apps and update them to the latest version.

  • script
  • update
  • apps
  • project
  • svn
  • git
Read More

script for run a django task

when running a console script to access django or your models, you need to setup django environment properly and that is very annoying if you have quite a few scripts. this script can be used as a wrapper just like the manage.py. put it in your project root and type this: python run.py myproj.appname.filename.functionname [arguments] and define your function as def functionname(argv[]): ...

  • task
  • console
  • script
Read More

8 snippets posted so far.