Metadata-Version: 2.0
Name: django-tools
Version: 0.29.3
Summary: miscellaneous tools for django
Home-page: http://code.google.com/p/django-tools/
Author: Jens Diemer
Author-email: django-tools@jensdiemer.de
License: UNKNOWN
Platform: UNKNOWN
Classifier: Development Status :: 5 - Production/Stable
Classifier: Environment :: Web Environment
Classifier: Intended Audience :: Developers
Classifier: License :: OSI Approved :: GNU General Public License (GPL)
Classifier: Programming Language :: Python
Classifier: Framework :: Django
Classifier: Topic :: Database :: Front-Ends
Classifier: Topic :: Documentation
Classifier: Topic :: Internet :: WWW/HTTP :: Dynamic Content
Classifier: Topic :: Internet :: WWW/HTTP :: Site Management
Classifier: Topic :: Internet :: WWW/HTTP :: WSGI :: Application
Classifier: Operating System :: OS Independent
Requires-Dist: Django (>=1.7,<1.9)

============
django-tools
============

Miscellaneous tools for django.

+-----------------------------------+--------------------------------------------------+
| |Build Status on travis-ci.org|   | `travis-ci.org/jedie/django-tools`_              |
+-----------------------------------+--------------------------------------------------+
| |Coverage Status on coveralls.io| | `coveralls.io/r/jedie/django-tools`_             |
+-----------------------------------+--------------------------------------------------+
| |Status on landscape.io|          | `landscape.io/github/jedie/django-tools/master`_ |
+-----------------------------------+--------------------------------------------------+

.. |Build Status on travis-ci.org| image:: https://travis-ci.org/jedie/django-tools.svg
.. _travis-ci.org/jedie/django-tools: https://travis-ci.org/jedie/django-tools/
.. |Coverage Status on coveralls.io| image:: https://coveralls.io/repos/jedie/django-tools/badge.svg
.. _coveralls.io/r/jedie/django-tools: https://coveralls.io/r/jedie/django-tools
.. |Status on landscape.io| image:: https://landscape.io/github/jedie/django-tools/master/landscape.svg
.. _landscape.io/github/jedie/django-tools/master: https://landscape.io/github/jedie/django-tools/master

--------------
existing stuff
--------------

Filemanager library
===================

Library for building django application like filemanager, gallery etc.

more info, read `./filemanager/README.creole <https://github.com/jedie/django-tools/blob/master/django_tools/filemanager/README.creole>`_

per-site cache middleware
=========================

Similar to `django UpdateCacheMiddleware and FetchFromCacheMiddleware <https://docs.djangoproject.com/en/1.4/topics/cache/#the-per-site-cache>`_,
but has some enhancements: `'per site cache' in ./cache/README.creole <https://github.com/jedie/django-tools/blob/master/django_tools/cache/README.creole#per-site-cache-middleware>`_

smooth cache backends
=====================

Same as django cache backends, but adds ``cache.smooth_update()`` to clears the cache smoothly depend on the current system load.
more info in: `'smooth cache backends' in ./cache/README.creole <https://github.com/jedie/django-tools/blob/master/django_tools/cache/README.creole#smooth-cache-backends>`_ 

local sync cache
================

Keep a local dict in a multi-threaded environment up-to-date. Usefull for cache dicts.
More info, read DocString in `./local_sync_cache/local_sync_cache.py <https://github.com/jedie/django-tools/blob/master/django_tools/local_sync_cache/local_sync_cache.py>`_.

threadlocals middleware
=======================

For getting request object anywhere, use `./middlewares/ThreadLocal.py <https://github.com/jedie/django-tools/blob/master/django_tools/middlewares/ThreadLocal.py>`_

Dynamic SITE_ID middleware
==========================

Set settings.SITE_ID dynamically with a middleware base on the current request domain name.
Domain name alias can be specify as a simple string or as a regular expression.

more info, read `./dynamic_site/README.creole <https://github.com/jedie/django-tools/blob/master/django_tools/dynamic_site/README.creole>`_.

StackInfoStorage
================

Message storage like LegacyFallbackStorage, except, every message would have a stack info, witch is helpful, for debugging.
Stack info would only be added, if settings DEBUG or MESSAGE_DEBUG is on.
To use it, put this into your settings:

::

    MESSAGE_STORAGE = "django_tools.utils.messages.StackInfoStorage"

More info, read DocString in `./utils/messages.py <https://github.com/jedie/django-tools/blob/master/django_tools/utils/messages.py>`_.

limit to usergroups
===================

Limit something with only one field, by selecting:

* anonymous users

* staff users

* superusers

* ..all existing user groups..

More info, read DocString in `./limit_to_usergroups.py <https://github.com/jedie/django-tools/blob/master/django_tools/limit_to_usergroups.py>`_

-----------------
unittests helpers
-----------------

BaseUnittestCase
================

**django_tools.unittest_utils.unittest_base.BaseUnittestCase** contains some low-level assert methods:

* assertEqual_dedent()

* assert_is_dir(), assert_not_is_dir()

* assert_is_file(), assert_not_is_File()

*django_tools.unittest_utils.tempdir* contains **TempDir**, a Context Manager Class:

::

    with TempDir(prefix="foo_") as tempfolder:
        # create a file:
        open(os.path.join(tempfolder, "bar"), "w").close()

    # the created temp folder was deleted with shutil.rmtree()

usage/tests:

* `/tests/test_unittest_utils.py <https://github.com/jedie/django-tools/blob/master/tests/test_unittest_utils.py>`_

DOM compare in unittests
========================

The Problem:
You can’t easy check if e.g. some form input fields are in the response,
because the form rendering use a dict for storing all html attributes.
So, the ordering of form field attributes are not sorted and varied.

The Solution:
You need to parse the response content into a DOM tree and compare nodes.

We add the great work of Gregor Müllegger at his GSoC 2011 form-rendering branch.
You will have the following assert methods inherit from: django_tools.unittest_utils.unittest_base.BaseTestCase

* self.assertHTMLEqual() – for compare two HTML DOM trees

* self.assertDOM() – for check if nodes in response or not.

* self.assertContains() – Check if ond node occurs 'count’ times in response

More info and examples in `./tests/test_dom_asserts.py <https://github.com/jedie/django-tools/blob/master/django_tools/tests/test_dom_asserts.py>`_

small tools
===========

debug_csrf_failure()
--------------------

Display the normal debug page and not the minimal csrf debug page.
More info in DocString here: `django_tools/views/csrf.py <https://github.com/jedie/django-tools/blob/master/django_tools/views/csrf.py>`_

import lib helper
-----------------

additional helper to the existing ``django.utils.importlib``
more info in the sourcecode: `./utils/importlib.py <https://github.com/jedie/django-tools/blob/master/django_tools/utils/importlib.py>`_

http utils
----------

Pimped HttpRequest to get some more information about a request.
More info in DocString here: `django_tools/utils/http.py <https://github.com/jedie/django-tools/blob/master/django_tools/utils/http.py>`_

upgrade virtualenv
==================

A simple commandline script that calls ``pip install —-upgrade XY`` for every package thats installed in a virtualenv.
Simply copy/symlink it into the root directory of your virtualenv and start it.

**Note:** `Seems that this solution can't observe editables right. <https://github.com/pypa/pip/issues/319>`_

To use it, without installing django-tools:

::

    ~/$ cd goto/your_env
    .../your_env/$ wget https://github.com/jedie/django-tools/raw/master/django_tools/upgrade_virtualenv.py
    .../your_env/$ chmod +x upgrade_virtualenv.py
    .../your_env/$ ./upgrade_virtualenv.py

This script will be obsolete, if `pip has a own upgrade command <https://github.com/pypa/pip/issues/59>`_.

SignedCookieStorage
-------------------

Store information in signed Cookies, use **django.core.signing**.
So the cookie data can't be manipulated from the client.
Sources/examples:

* `/django_tools/utils/client_storage.py <https://github.com/jedie/django-tools/blob/master/django_tools/utils/client_storage.py>`_

* `/tests/test_signed_cookie.py <https://github.com/jedie/django-tools/blob/master/tests/test_signed_cookie.py>`_

Print SQL Queries
=================

Print the used SQL queries via context manager.

usage e.g.:

::

    from django_tools.unittest_utils.print_sql import PrintQueries

    # e.g. use in unittests:
    class MyTests(TestCase):
        def test_foobar(self):
            with PrintQueries("Create object"):
                FooBar.objects.create("name"=foo)

    # e.g. use in views:
    def my_view(request):
        with PrintQueries("Create object"):
            FooBar.objects.create("name"=foo)

the output is like:

::

    _______________________________________________________________________________
     *** Create object ***
    1 - INSERT INTO "foobar" ("name")
        VALUES (foo)
    -------------------------------------------------------------------------------

SetRequestDebugMiddleware
=========================

middleware to add debug bool attribute to request object.
More info: `./debug/README.creole <https://github.com/jedie/django-tools/blob/master/django_tools/debug/README.creole>`_

InternalIps() - Unix shell-style wildcards in INTERNAL_IPS
==========================================================

settings.py e.g.:

::

    from django_tools.settings_utils import InternalIps

    INTERNAL_IPS = InternalIps(["127.0.0.1", "::1", "192.168.*.*", "10.0.*.*"])

StdoutStderrBuffer()
====================

redirect stdout + stderr to a string buffer. e.g.:

::

    from django_tools.unittest_utils.stdout_redirect import StdoutStderrBuffer

    with StdoutStderrBuffer() as buffer:
        print("foo")
    output = buffer.get_output() # contains "foo\n"

..all others…
=============

There exist many miscellaneous stuff. Look in the source, luke!

------------------------------
Backwards-incompatible changes
------------------------------

-----
v0.29
-----

**ClientCookieStorage** was renamed to **SignedCookieStorage**
import e.g.:

::

    from django_tools.utils.client_storage import SignedCookieStorage

-------
v0.25.0
-------

SmoothCacheBackends API changed:
The **cache.clear()** method will really clear the cache, as the origin backend API.
You must call ``cache.smooth_update()`` to set the "last change" timestamp.

v0.24.10
========

AutoUpdateFileBasedCache is deprecated, use new SmoothCacheBackends.

v0.9
====

Language code field and SelectMediaPath are renamed.

change:
**from django_tools.fields import LanguageCodeFormField**
to:
**from django_tools.fields.language_code import LanguageCodeFormField**

change and rename:
**from django_tools.fields import LanguageCodeField**
to:
**from django_tools.fields.language_code import LanguageCodeModelField**

change and rename:
**from django_tools.widgets import SelectMediaPath**
to:
**from django_tools.fields.media_path import MediaPathWidget**

--------------------
Django compatibility
--------------------

+--------------+----------------+----------+
| django-tools | django version | python   |
+==============+================+==========+
| v0.29        | 1.7, 1.8       | 2.7, 3,4 |
+--------------+----------------+----------+
| v0.26        | <=1.6          |          |
+--------------+----------------+----------+
| v0.25        | <=1.4          |          |
+--------------+----------------+----------+

(since v0.29 the given version combination will be tested via travis-ci)

-------
history
-------

* v0.29.3 - 10.08.2015 - `compare v0.29.2...v0.29.3 <https://github.com/jedie/django-tools/compare/v0.29.2...v0.29.3>`_ 

    * Clear ThreadLocal request atttribute after response is processed (contributed by Lucas Wiman)

* v0.29.2 - 19.06.2015 - `compare v0.29.1...v0.29.2 <https://github.com/jedie/django-tools/compare/v0.29.1...v0.29.2>`_ 

    * Bugfix in unittest_utils.selenium_utils.selenium2fakes_response

    * assertResponse used assertContains from django

    * Add QueryLogMiddleware (TODO: add tests)

* v0.29.1 - 17.06.2015 - `compare v0.29.0...v0.29.1 <https://github.com/jedie/django-tools/compare/v0.29.0...v0.29.1>`_ 

    * Bugfixes for Py2 and Py3

    * add StdoutStderrBuffer()

* v0.29.0 - 09.06.2015 - `compare v0.26.0...v0.29.0 <https://github.com/jedie/django-tools/compare/v0.26.0...v0.29.0>`_ 

    * WIP: Refactor unittests (DocTests must be updated for Py3 and more unittests must be written to cover all)

    * catch more directory traversal attacks in BaseFilesystemBrowser (and merge code parts)

    * Bugfix for "django.core.exceptions.AppRegistryNotReady: Models aren't loaded yet." if using **UpdateInfoBaseModel**

    * Bugfixes in **dynamic_site** for django 1.7

    * add: `django_tools.settings_utils.InternalIps <https://github.com/jedie/django-tools/blob/master/django_tools/settings_utils.py>`_

* v0.28.0 - 12.02.2015 - `compare v0.26.0...v0.28.0 <https://github.com/jedie/django-tools/compare/v0.26.0...v0.28.0>`_ 

    * Work-a-round for import loops

    * (new Version number, because of PyPi stress)

* v0.26.0 - 11.02.2015 - `compare v0.25.1...v0.26.0 <https://github.com/jedie/django-tools/compare/v0.25.1...v0.26.0>`_ 

    * Updates for Django 1.6 and Python 3

* v0.25.1 - 18.11.2013

    * Bugfix: Fall back to "UTF-8" if server send no encoding info

* v0.25.0 - 28.08.2012

    * Rename **cache.clear()** in SmoothCacheBackends to **cache.smooth_update()**, so that reset timestamp is independ from clear the cache.

* v0.24.10 - 24.08.2012

    * Add **SmoothCacheBackends**: `./cache/README.creole <https://github.com/jedie/django-tools/blob/master/django_tools/cache/README.creole>`_

* v0.24.9 - 24.08.2012

    * Bugfix in per-site cache middleware: set inital count values to None, if counting is disabled.

* v0.24.8 - 24.08.2012

    * Enhanced **per-site cache middleware**: `./cache/README.creole`_

    * Add **SetRequestDebugMiddleware**: `./debug/README.creole`_

* v0.24.7 - 21.08.2012

    * Add the **per-site cache middleware** (see above)

    * Add **import lib helper**: `./utils/importlib.py`_

* v0.24.6 - 21.08.2012

    * Add the **filemanager library** (see above)

* v0.24.5 - 06.08.2012

    * Add **Print SQL Queries** context manager. (see above)

* v0.24.4 - 26.07.2012

    * remove date from version string, cause of side-effects e.g.: user clone the repo and has the filter not installed

* v0.24.3 - 25.07.2012

    * "Hardcode" the version string date attachment via `gitattribute filter script <https://github.com/jedie/python-code-snippets/tree/master/CodeSnippets/git>`_ to fix `a reported issues <https://github.com/jedie/django-tools/issues/1>`_ with `pip requirements file bug <https://github.com/pypa/pip/issues/145>`_.

* v0.24.2 - 10.07.2012

    * Split `UpdateInfoBaseModel() <https://github.com/jedie/django-tools/blob/master/django_tools/models.py>`_: So you can only set "createtime", "lastupdatetime" or "createby", "lastupdateby" or both types (This is backwards compatible)

* v0.24.1 - 12.06.2012

    * Bugfix: UsergroupsModelField() and add unittests for it

    * Add "normal users" in UsergroupsModelField()

    * New: Add create_user() and create_testusers() to BaseTestCase

    * Add a test project for the unittests. TODO: use this for all tests

* v0.24.0 - 04.06.2012

    * `Don't use auto_now_add and auto_now in UpdateInfoBaseModel <https://github.com/jedie/django-tools/commit/a3cf1f7b2e9dbe4964306f4793c74f1782f8b2ea>`_

    * Bugfix in `UsergroupsModelField <https://github.com/jedie/django-tools/blob/master/django_tools/limit_to_usergroups.py>`_

* v0.23.1

    * `Dynamic Site <https://github.com/jedie/django-tools/tree/master/django_tools/dynamic_site#dynamic-site-id>`_ would be only initialised if settings.USE_DYNAMIC_SITE_MIDDLEWARE = True

* v0.23.0

    * Use cryptographic signing tools from django 1.4 in django_tools.utils.client_storage

* v0.22.0

    * Add `static_path.py <https://github.com/jedie/django-tools/blob/master/django_tools/fields/static_path.py>`_ thats used settings.STATIC_ROOT.

    * The old `media_path.py <https://github.com/jedie/django-tools/blob/master/django_tools/fields/media_path.py>`_ which used settings.MEDIA_ROOT is deprecated and will be removed in the future.

    * auto_add_check_unique_together() can use settings.DATABASES["default"]["ENGINE"], too.

* v0.21.1

    * Bugfixes in `Dynamic Site`_.

* v0.21.0beta

    * New: site alias function

    * refractory 'DynamicSiteMiddleware' to a own app (**Backwards-incompatible change:** change your settings if you use the old DynamicSiteMiddleware.)

* v0.20.1

    * New: `debug_csrf_failure() <https://github.com/jedie/django-tools/blob/master/django_tools/views/csrf.py>`_ to display the normal debug page and not the minimal csrf debug page.

* v0.20.0

    * Add experimental `DynamicSiteMiddleware <https://github.com/jedie/django-tools/blob/master/django_tools/middlewares/DynamicSite.py>`_, please test it and give feedback.

* v0.19.6

    * Add some south introspection rules for LanguageCodeModelField and jQueryTagModelField

    * fallback if message for anonymous user can't created, because django.contrib.messages middleware not used.

    * Bugfix in django_tools.utils.messages.StackInfoStorage

* v0.19.5

    * Add `http://bugs.python.org/file22767/hp_fix.diff <http://bugs.python.org/file22767/hp_fix.diff>`_ for `https://github.com/gregmuellegger/django/issues/1 <https://github.com/gregmuellegger/django/issues/1>`_

* v0.19.4

    * Bugfix for PyPy in local_sync_cache get_cache_information(): sys.getsizeof() not implemented on PyPy

    * Bugfix in template.filters.chmod_symbol()

    * Nicer solution for template.filters.human_duration()

* v0.19.3

    * Add support for https in utils/http.py

* v0.19.2

    * Bugfix in utils/http.py timeout work-a-round

* v0.19.1

    * utils/http.py changes:

        * Use a better solution, see:

        * Add timeout and add a work-a-round for Python < 2.6

* v0.19.0

    * NEW: Add utils/http.py with helpers to get a webpage via http GET in unicode

    * Change README from textile to creole ;)

* v0.18.2

    * Bugfix: Add missing template in pypi package

* v0.18.0

    * NEW: Add DOM compare from Gregor Müllegger GSoC work into unittest utils.

* v0.17.1

    * Bugfix in “limit_to_usergroups”: Make choices “lazy”: Don’t access the database in *init*

* v0.17

    * Add the script “upgrade_virtualenv.py”

    * Add “limit_to_usergroups”

    * Add “local sync cache”

    * Add models.UpdateInfoBaseModel

    * Update decorators.render_to

    * render_to pass keyword arguments to render_to_response() (e.g.: mimetype=“text/plain”)

    * new argument “skip_fail” in get_filtered_apps(): If True: raise excaption if app is not importable

* v0.16.4

    * Bugfix: ``get_db_prep_save() got an unexpected keyword argument 'connection’`` when save a SignSeparatedModelField()

* v0.16.3

    * Update BrowserDebug: Use response.templates instead of response.template and make output nicer

* v0.16.2

    * Merge stack info code and display better stack info on browser debug page

* v0.16.1

    * Update django_tools.utils.messages.StackInfoStorage for django code changes.

* v0.16.0

    * NEW: path model field (check if direcotry exist)

* v0.15.0

    * NEW: Add a flexible URL field (own validator, model- and form-field)

* v0.14.1

    * Bugfix: make path in MediaPathModelField relativ (remove slashes)

* v0.14

    * NEW: django-tagging addon: Display existing tags under a tag field

* v0.13

    * Bugfix UnicodeEncodeError in Browser debug

* v0.12

    * NEW: django_tools.utils.messages.failsafe_message

* v0.11

    * NEW: Store data in a secure cookie, see: utils/client_storage.py

* v0.10.1

    * New: Display used templates in unittest BrowserDebug

    * Bugfix: catch if last usermessages exist

* v0.10.0

    * NEW: utils around django messages, see: /django_tools/utils/messages.py

* v0.9.1

    * Bugfix: database column was not created: don’t overwrite get_internal_type()

* v0.9

    * New: stuff in /django_tools/fields/

    * see also backwards-incompatible changes, above!

* v0.8.2

    * New: widgets.SelectMediaPath(): Select a sub directory in settings.MEDIA_ROOT

    * New: fields.SignSeparatedField()

* v0.8.1

    * Add “no_args” keyword argument to installed_apps_utils.get_filtered_apps()

* v0.8.0

    * Add model LanguageCode field and form LanguageCode field in Accept-Language header format (RFC 2616)

* v0.7.0

    * Add decorators.py

* v0.6.0

    * Add forms_utils.LimitManyToManyFields, crosspost: `http://www.djangosnippets.org/snippets/1691/ <http://www.djangosnippets.org/snippets/1691/>`_

* v0.5.0

    * Add template/filters.py from PyLucid v0.8.x

* v0.4.0

    * Add experimental “warn_invalid_template_vars”

* v0.3.1

    * Bugfix: Exclude the instance if it was saved in the past.

* v0.3.0

    * Add utils.installed_apps_utils

* v0.2.0

    * Add models_utils, see: `http://www.jensdiemer.de/_command/118/blog/detail/67/ <http://www.jensdiemer.de/_command/118/blog/detail/67/>`_ (de)

* v0.1.0

    * first version cut out from PyLucid CMS – `http://www.pylucid.org <http://www.pylucid.org>`_

-----------
pip upgrade
-----------

To do a pip upgrade in a virtual environment, run this:

::

    ~$ cd /YourVirtualEnv/bin
    ~/YourVirtualEnv/bin$ source activate
    (YourVirtualEnv)~/YourVirtualEnv/bin$ pip install --upgrade --verbose --editable=git+git://github.com/jedie/django-tools.git#egg=django-tools

The example used git readonly clone url. If you use subversion do this:

::

    (YourVirtualEnv)~/YourVirtualEnv/bin$ pip install --upgrade --verbose --editable=http://svn.github.com/jedie/django-tools.git#egg=django-tools

If you have git write access, use this:

::

    (YourVirtualEnv)~/YourVirtualEnv/bin$ pip install --upgrade --verbose --editable=git+git@github.com:jedie/django-tools.git#egg=django-tools

...or just use our limit_to_usergroups.py script (see above)

----------------
fast repo update
----------------

To made a fast repository update, you can run this simple shell script:

::

    ~$ cd /path/to/django-tools
    /path/to/django-tools$ ./update.sh

the update script runs “git pull origin master” or “svn update”.

-----
links
-----

+------------+----------------------------------------------+
| Homepage   | `http://code.google.com/p/django-tools/`_    |
+------------+----------------------------------------------+
| Sourcecode | `http://github.com/jedie/django-tools`_      |
+------------+----------------------------------------------+
| PyPi       | `http://pypi.python.org/pypi/django-tools/`_ |
+------------+----------------------------------------------+

.. _http://code.google.com/p/django-tools/: http://code.google.com/p/django-tools/
.. _http://github.com/jedie/django-tools: http://github.com/jedie/django-tools
.. _http://pypi.python.org/pypi/django-tools/: http://pypi.python.org/pypi/django-tools/

-------
contact
-------

Come into the conversation, besides the github communication features:

+---------+--------------------------------------------------------+
| Forum   | `official 'django-tools' Forum`_                       |
+---------+--------------------------------------------------------+
| IRC     | #pylucid on freenode.net (Yes, the PyLucid channel...) |
+---------+--------------------------------------------------------+
| webchat | `http://webchat.freenode.net/?channels=pylucid`_       |
+---------+--------------------------------------------------------+

.. _official 'django-tools' Forum: http://www.pylucid.org/en/forum/12/
.. _http://webchat.freenode.net/?channels=pylucid: http://webchat.freenode.net/?channels=pylucid

--------
donation
--------

* `Flattr This! <https://flattr.com/submit/auto?uid=jedie&url=https%3A%2F%2Fgithub.com%2Fjedie%2Fdjango-tools%2F>`_

* Send `Bitcoins <http://www.bitcoin.org/>`_ to `1823RZ5Md1Q2X5aSXRC5LRPcYdveCiVX6F <https://blockexplorer.com/address/1823RZ5Md1Q2X5aSXRC5LRPcYdveCiVX6F>`_

