Logging and statistic middleware
Reviewing some statistic-middleware-classes I think you might need one wich is working correct and high-performant. Please comment it and have fun with it!
- middleware
- stats
- logging
- statistic
- user-activities
Reviewing some statistic-middleware-classes I think you might need one wich is working correct and high-performant. Please comment it and have fun with it!
When given a model this utility method will export all data in that model to a CSV file. I use this method to place an "Export" button on a particular model's change list page in the Django administrator.
This is a simple FCK editor widget that can be used in newforms in place of Textarea. Obviously it requires [FCKeditor](http://www.fckeditor.net/) and you will need to set the proper import path for that.
A widget for selecting from a list of `Model` instances using `MultipleChoiceField` which renders a table row for each choice, consisting of a column for a checkbox followed by a column for each item specified in `item_attrs`, which must specify attributes of the objects passed as choices.
Use `{% urchin "UA-1234567-1" %}` to insert the Javascript snippet for a Google Analytics site.
This script will reload apache when any modifications are detected in a folder - useful only if the development server or mod_python's reload does not suit your needs for testing. It requires Linux 2.6.13+, Python 2.5, and the [development version of pyinotify](http://seb.dbzteam.com/pages/pyinotify-dev.html).
If you ever have a need to display something like: "last update 5 days ago" "user logged in 2 mins ago" you can use this script to determine how long ago a timestamp is versus now().
Call this function as the first thing in your cron, or console script; it will bootstrap Django, and allow you to access all of the Django modules from the console, with out using 'python manage.py shell' Examples: # A script within your django project. from django_bootstrap import bootstrap bootstrap(__file__) --- or --- # A cron script located outside of your django project from django_bootstrap import bootstrap bootstrap("/path/to/your/project/root/")
This tag makes it easy to include menu or navigation bars in an application's pages, even in a 'tabbed' fashion. (The actual appearance is styled in CSS; this example uses UL tags that are then supposed to be styled by a "display: inline" attribute to be rendered as horizontal bars.)
If you have many models that all share the same fields, this might be an option. Please note that order matters: Your model need to inherit from TimestampedModelBase first, and models.Model second. The fields are added directly to each model, e.g. while they will be duplicated on the database level, you only have to define them once in your python code. Not sure if there is a way to automate the call to TimestampedModelInit(). Tested with trunk rev. 5699. There is probably a slight chance that future revisions might break this.
This function looks up items similar to a specific string. Requires the [Levenshtein module](http://trific.ath.cx/resources/python/levenshtein/).
Form fields use the dateutil module [http://labix.org/python-dateutil](http://labix.org/python-dateutil) to parse natural-language input for date and datetime fields. The callback function will replace all date and datetime fields automatically for form_for_model and form_for_instance. **Note**: by replacing the 'form_class' keyword argument instead of just returning the field itself you preserve the 'required' status of the field.
A very basic app centered around a template tag that takes an e-mail address and optional label and returns a link to an e-mail form. This way, you can easily throw e-mail addresses into your template that will automatically link to an e-mail form instead of displaying the e-mail address itself. The model for this app is extremely simple, with only one field to store the e-mail address. When an e-mail is passed to the email_link template tag, the e-mail address is added to the database if it is not already there. This is stored in the database in order to keep the full e-mail address hidden from the viewer. To use, simply create an app called 'email_links' (or you can change the name if you also change line 4 of email_extras.py to reflect the change). Then use the models.py and views.py provided. Add a templatetags directory under your app, and add email_extras.py and a blank __init__.py In your urls.py, add the following to your urlpatterns (subsitute project_name for your own): `(r'^email/(?P<email_id>[0-9]+)/$', 'project_name.email_links.views.email_form'),` Create two templates: email_links/email_form.html and email_links/thanks.html (the examples here are extremely basic - make them however you want). Finally, in a template where you want to provide a link to e-mail someone, first load email_extras: `{% load email_extras %}` Then do one of the following: `{% email_link "[email protected]" %}` `{% email_link "[email protected]" "E-mail someone" %}` Both will create a link to the e-mail form. The first will use mask_email (from the snippet by jkocherhans) to create the link. The second will display the second argument "E-mail someone" in the link. Also note that I've used the Sites add-on to generate the links, but you can easily change this to suit your needs. I hope all of this makes sense. I'm a bit tired, but wanted to get this up before bed.
This middleware allows developers to "fake" browser support for HTTP methods. Even though most modern browsers only support GET and POST, the HTTP standard defines others. In the context of REST, PUT and DELETE are used for client interaction with the server. For forms with a PUT or DELETE method, this middleware will change them to go through POST, and will include an invisible field called "method_middleware_transform" that carries the originally intended method. So, `<form method="PUT" ...>...</form>` More or less becomes `<form method="POST" ...><input type=hidden name="method_middleware_transform" value="PUT"></form>` (with a few other minor HTML modifications) The process is completely transparent to the developer... you never have to deal with the fact that browsers don't support the standard methods. **One caveat** is that server interaction via `XMLHttpRequest` (AJAX) requires special attention... this middleware won't properly setup your XMLHttpRequest to take advantage of this functionality. This is a combination of the work of Jesse Lovelace and the Django CSRF middleware.
This tag makes it easy to have a random rotation of images on a page. Don't forget to set your MEDIA_URL.
3110 snippets posted so far.