{ "info": { "author": "Illia Polosukhin, Vlad Frolov", "author_email": "ilblackdragon@gmail.com", "bugtrack_url": null, "classifiers": [], "description": ".. -*- mode: rst -*-\n\ndjango-misc\n===========\n\n**Django misc** is module with set of utilities, decorators, templatetags that everybody uses at least once in project.\nSo here they all in one application, that will grow to aggregate all usefull utilities for Django.\n\n.. contents::\n\nQuick overview\n==============\n\nHere you'll find:\n\n* Couple decorators, like render_to and receive\n* Json_encode module for simplify work with json\n* Some usefull templatetags, like set, filter, get etc\n* Some additional utilities\n* Bbcode template tags\n* Template tags that provide like and share for social sevices\n\n\n\nRequirements\n==============\n\n- python >= 2.5\n- pip >= 0.8\n- django >= 1.2\n\nOptional (for html clearing and bbcodes):\n\n- BeautifulSoup \n- git+git://github.com/frol/postmarkup.git\n\nInstallation\n=============\n\n**Django misc** should be installed using pip: ::\n\n pip install git+git://github.com/ilblackdragon/django-misc.git\n \nor for stable version: ::\n\n pip install django-misc\n\n\nSetup\n============\n\n- Add 'misc' to INSTALLED_APPS ::\n\n INSTALLED_APPS += ( 'misc', )\n \n- If you want to use the html clearer ::\n \n pip install BeautifulSoup\n \n- If you want to use bbcodes ::\n \n pip install git+git://github.com/frol/postmarkup.git\n \n \nUse django-misc\n===============\n\nTemplate tags\n-------------\n\n{% load html_tags %}\n~~~~~~~~~~~~~~~~~~~~\n\n::\n\n {% remove_tags %}\n\nRemoves html tags and replace
by \\n\n\n{% load misc_tags %}\n~~~~~~~~~~~~~~~~~~~~\n\n::\n\n {{ text|cutafter:\"\" }}\n\nCut text after characters and, if necessary, add tree dots (...) to the end\n\n::\n\n {% get_range %}\n\nReturn simple python range() list\n\n::\n\n {% get_element [] %}\n\nReturn a dict value by key1 and, if specified, key2 (i.e. dict[key1][key2])\n\njson_encode\n-----------\n\nJSONTemplateResponse\n~~~~~~~~~~~~~~~~~~~~\n\nIt works like TemplateResponse, but return JSON response\n\nin view.py::\n\n ...\n return JSONTemplateResponse(request, template_name, template_context, data={'status': 'ok', 'user': request.user})\n\n\nThis line will create response\n\n::\n\n {\n \"status\": \"ok\",\n \"user\": {\n \"username\": \"frol\",\n \"first_name\": \"\",\n \"last_name\": \"\",\n \"is_active\": true,\n \"email\": \"qq@qq.qq\",\n \"is_superuser\": true,\n \"is_staff\": true,\n \"last_login\": \"2012-01-24 18:59:55\",\n \"password\": \"sha1$fffff$1b4d68b3731ec29a797d61658c716e2400000000\",\n \"id\": 1,\n \"date_joined\": \"2011-07-09 05:57:21\"\n },\n \"html\": \"\"\n }\n\nWARNING: Be carefull with serialization of model objects. As you can see in example, password hash has been serialized.\n\njson_encode\n~~~~~~~~~~~\n\njson_encode(data)\n\nSerialize python object into JSON string.\n \nThe main issues with django's default json serializer is that properties that\nhad been added to an object dynamically are being ignored (and it also has \nproblems with some models).\n\njson_response\n~~~~~~~~~~~~~\n\njson_response(data)\n\nSerialize python object into JSON string and return HttpResponse with correct content_type (application/json)\n\njson_template\n~~~~~~~~~~~~~\n\njson_template(data, template_name, template_context)\n\nRender template, add it for serialization data, serialize data into JSON string and return HttpResponse with correct content_type.\n\nContext processors\n------------------\n\nuseful_constants\n~~~~~~~~~~~~~~~~\n\nIf you want use True, False, None in django templates, add line to TEMPLATE_CONTEXT_PROCESSORS in settings.py::\n\n 'misc.context_processors.useful_constants',\n\nExample, A = True, B = False, C = None, D - undefined::\n\n {% if A == True %}A is True{% endif %}\n {% if A == False %}A is False{% endif %}\n {% if A == None %}A is None{% endif %}\n\n {% if B == True %}B is True{% endif %}\n {% if B == False %}B is False{% endif %}\n {% if B == None %}B is None{% endif %}\n\n {% if C == True %}C is True{% endif %}\n {% if C == False %}C is False{% endif %}\n {% if C == None %}C is None{% endif %}\n\n {% if D == True %}D is True{% endif %}\n {% if D == False %}D is False{% endif %}\n {% if D == None %}D is None{% endif %}\n\nWill produce output::\n\n A is True\n B is False\n C is None\n D is None\n\n\nViews utils\n-----------\n\nserver_error\n~~~~~~~~~~~~\n\nmisc.views.server_error(request)\n\nPut server_error as your handler500 in urls.py and add templates/errors/500.html ::\n\n handler500 = 'misc.views.server_error'\n\ndecorator to_template or render_to\n~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n\nto_template(template_name=None)\n\nDecorator to simply call direct_to_template: ::\n \n @to_template(\"test.html\")\n def test(request):\n return {'test': 100}\n\n @to_template\n def test2(request):\n return {'test': 100, 'TEMPLATE': 'test.html'}\n\n @to_template\n def test2(request, template_name='test.html'):\n return {'test': 100, 'TEMPLATE': template_name}\n\nHttpResponseReload\n~~~~~~~~~~~~~~~~~~\n\nutils.HttpResponseReload(request)\n\nReload current page. ::\n\n def simple_view(request, form_class=CommentForm, template_name='some_template.html'):\n form = CommentForm(request.POST or None)\n if form.valid():\n form.save()\n return HttpResponseReload(request)\n return render(template_name, {'form': form})\n\nstr_to_class\n~~~~~~~~~~~~\n\nutils.str_to_class(class_name)\n\nReturns a class based on class name\n\nget_alphabets\n~~~~~~~~~~~~~\n\nutils.get_alphabets()\n\nReturns pair of english and russian alphabets.\nUseful for creating filters.\n \nManagement utils\n----------------\n\nhandle_lock\n~~~~~~~~~~~\n\nmanagement.handle_lock(handle)\n\nDecorate the handle method with a file lock to ensure there is only ever one process running at any one time.\n\nsync_site\n~~~~~~~~~\n\nsync_site is post syncdb event, that will sync current Site object with settings like SITE_NAME and SITE_DOMAIN\n\nHTML utils\n----------\n\nclear_html_code\n~~~~~~~~~~~~~~~\n\nhtml.clear.clear_html_code(text)\n\nClean up HTML code from tags that are not allowed. Structure of allowed tags can be found at needs.cfg.\nclear.py is generated by html/generator.py with needs.cfg as config file\n\ngenerator\n~~~~~~~~~\n\n./generator.py\n\nWill generate clear.py source code file, according to rules specified at needs.cfg.\nExample of simpler configuration file can be found in example.cfg\n\n\nContributing\n============\n\nDevelopment of django-misc happens at github: https://github.com/ilblackdragon/django-misc\n\nLicense\n============\n\nCopyright (C) 2009-2013 Illia Polosukhin, Vladyslav Frolov\nThis program is licensed under the MIT License (see LICENSE)", "description_content_type": null, "docs_url": null, "download_url": "UNKNOWN", "downloads": { "last_day": -1, "last_month": -1, "last_week": -1 }, "home_page": "http://github.com/ilblackdragon/django-misc.git", "keywords": null, "license": "MIT", "maintainer": null, "maintainer_email": null, "name": "django-misc", "package_url": "https://pypi.org/project/django-misc/", "platform": "UNKNOWN", "project_url": "https://pypi.org/project/django-misc/", "project_urls": { "Download": "UNKNOWN", "Homepage": "http://github.com/ilblackdragon/django-misc.git" }, "release_url": "https://pypi.org/project/django-misc/0.1.0/", "requires_dist": null, "requires_python": null, "summary": "Django miscellaneous - module with different useful stuff for django. \nHere you'll find: \n- couple decorators, like render_to and receive; \n- json_encode module for simplify work with json; \n- some usefull templatetags, like set, filter, get etc; some additional utilities; \n- bbcode template tags; \n- template tags that provide like and share for social sevices.", "version": "0.1.0" }, "last_serial": 790087, "releases": { "0.0.1": [ { "comment_text": "", "digests": { "md5": "ac7b1811f0f9c623bdce63ffeb8a9ed8", "sha256": "872908fb44822c68ccff33c7fd1f3cf6a54ae1c83f65925cf079e75ffbb15bbd" }, "downloads": -1, "filename": "django-misc-0.0.1.tar.gz", "has_sig": false, "md5_digest": "ac7b1811f0f9c623bdce63ffeb8a9ed8", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 15138, "upload_time": "2011-04-18T19:47:14", "url": "https://files.pythonhosted.org/packages/f0/b8/87d575c71a0e3faf8360e31c24dd4a104df988914a18c6ccaf0c4c27506c/django-misc-0.0.1.tar.gz" } ], "0.0.2": [ { "comment_text": "", "digests": { "md5": "f31ca03ceb4a05a45381a0dece1ae1fc", "sha256": "401e34dc7d36d49a27b5e89f0884afa3f78bd5844a5559f6bf81256348b47054" }, "downloads": -1, "filename": "django-misc-0.0.2.tar.gz", "has_sig": false, "md5_digest": "f31ca03ceb4a05a45381a0dece1ae1fc", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 16086, "upload_time": "2011-04-28T18:42:47", "url": "https://files.pythonhosted.org/packages/15/34/9bd672802ee3f7b56e336d4d62c06faf76e16f17955b62661719fb6a202d/django-misc-0.0.2.tar.gz" } ], "0.0.6": [ { "comment_text": "", "digests": { "md5": "ce025cf290acd316b6ded80ada607cb9", "sha256": "458c7c6656a15194a079e58e6d7adf61e7ccf7a99f9c303cb5dd795365e9fb65" }, "downloads": -1, "filename": "django-misc-0.0.6.zip", "has_sig": false, "md5_digest": "ce025cf290acd316b6ded80ada607cb9", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 26244, "upload_time": "2011-12-01T22:48:58", "url": "https://files.pythonhosted.org/packages/82/d6/c16d8a99ba0fb1e79d7b8f76c7fcd0841003e8097e5c8ce7c279ae2ce099/django-misc-0.0.6.zip" } ], "0.0.9": [ { "comment_text": "", "digests": { "md5": "bd02e2919ba6b8d594d5cb8625d26cb0", "sha256": "718908564e0ff17ded35fc9eb47d308765aaccf0f2ee276a980aaf82b65aa673" }, "downloads": -1, "filename": "django-misc-0.0.9.zip", "has_sig": false, "md5_digest": "bd02e2919ba6b8d594d5cb8625d26cb0", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 33973, "upload_time": "2012-11-18T07:20:23", "url": "https://files.pythonhosted.org/packages/64/3d/d15629cc6cbdd9a73cf38684f83ee21de7d639353c502b42584b7d1e8ec5/django-misc-0.0.9.zip" } ], "0.1.0": [ { "comment_text": "", "digests": { "md5": "dd12fd9c13801e6242682f772f1f3dea", "sha256": "80af0db27930596925e348b7828781eb904d7732a2f8de466f9b5838956d987e" }, "downloads": -1, "filename": "django-misc-0.1.0.zip", "has_sig": false, "md5_digest": "dd12fd9c13801e6242682f772f1f3dea", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 35437, "upload_time": "2012-11-18T07:45:55", "url": "https://files.pythonhosted.org/packages/26/57/1c27d21980f2119a7d7eea9413fdc3caa3efc98b12a9ae8b24be45f8c90f/django-misc-0.1.0.zip" } ] }, "urls": [ { "comment_text": "", "digests": { "md5": "dd12fd9c13801e6242682f772f1f3dea", "sha256": "80af0db27930596925e348b7828781eb904d7732a2f8de466f9b5838956d987e" }, "downloads": -1, "filename": "django-misc-0.1.0.zip", "has_sig": false, "md5_digest": "dd12fd9c13801e6242682f772f1f3dea", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 35437, "upload_time": "2012-11-18T07:45:55", "url": "https://files.pythonhosted.org/packages/26/57/1c27d21980f2119a7d7eea9413fdc3caa3efc98b12a9ae8b24be45f8c90f/django-misc-0.1.0.zip" } ] }