{ "info": { "author": "Benjamin Stookey", "author_email": "ben@aashe.org", "bugtrack_url": null, "classifiers": [ "Development Status :: 4 - Beta", "Environment :: Web Environment", "Framework :: Django", "Intended Audience :: Developers", "License :: OSI Approved :: BSD License", "Operating System :: OS Independent", "Programming Language :: Python", "Topic :: Utilities" ], "description": "====================\ndjango-logical-rules\n====================\n\n.. image:: https://pypip.in/v/django-logical-rules/badge.png\n :target: https://crate.io/packages/django-logical-rules\n.. image:: https://pypip.in/d/django-logical-rules/badge.png\n :target: https://crate.io/packages/django-logical-rules\n.. image:: https://drone.io/bitbucket.org/aashe/django-logical-rules/status.png\n :target: https://drone.io/bitbucket.org/aashe/django-logical-rules/latest\n\nA tool to manage logical rules throughout your application. Logical rules are more powerful than permission or rule tables because they are written in python. Register a rule once and work with it throughout your app, from templates to generic view mixins. Instead of cluttering your models with rule-style and permission-style methods define those rules in **rules.py** and then get easy access to them in your views and templates.\n\nInstallation\n============\n\nUse ``pip`` to install from PyPI::\n\n\tpip install django-logical-rules\n\nAdd ``logical_rules`` to your settings.py file::\n\n\tINSTALLED_APPS = (\n\t ...\n\t 'logical_rules',\n\t ...\n\t)\n\nAdditional Requirements\n=======================\n\nIf you want to use the messaging features install `Django messages framework`__.\n\nConfiguration\n=============\n\nRules are defined in **rules.py** files within your apps. Here's an example of a rule::\n\n\timport logical_rules\n\n\tdef user_can_edit_mymodel(object, user):\n\t\t\"\"\"\n\t\t\tConfirms a user can edit a specific model\n\t\t\t...owners only!\n\t\t\"\"\"\n\t\treturn object.owner == user\n\tlogical_rules.site.register(\"user_can_edit_mymodel\", user_can_edit_mymodel)\n\t\nTo include your models in the registry you will need to do run the autodiscover, a bit like django.contrib.admin (I generally put this in **urls.py**)::\n\n\timport logical_rules\n\tlogical_rules.autodiscover()\n\n\nUsage\n=====\n\nTemplate Tag\n------------\n\nOnce you have created a rule, it's easy to use anywhere in your templates::\n\n\t{% load logical_rules_tags %}\n\t{% testrule user_can_edit_mymodel object request.user %}\n\t\t
You are the owner!
\n\t{% endtestrule %}\n\t\n**Note:** *Don't use quotes around the rule name in the template.*\n\nRulesMixin\n----------\n\nIf you are extending Django's class-based generic views, you might find this mixin useful. It allows you to define rules that should be applied before rendering a view. Here's an example usage::\n\n class MyView(RulesMixin, DetailView):\n\n def update_logical_rules(self):\n super(MyView, self).update_logical_rules()\n self.add_logical_rule({\n 'name': 'user_can_edit_mymodel',\n 'param_callbacks': [\n ('object', 'get_object'),\n ('user', 'get_request_user')\n ]\n })\n\n``param_callbacks`` are our technique for getting the parameters for your rule. These are assumed to be methods on your class. ``get_request_user()`` is defined in RuleMixin since it's so common. ``get_object()`` is a method on the DetailView class.\n\nRule dictionaries can have other properties, like ``redirect_url`` and ``response_callback``. If ``redirect_url`` is defined, then the view will return an ``HttpResponseRedirect`` to that URL. If ``response_callback`` is defined, then the view will return the result of that method.\n\nMessaging integration is possible with ``message`` and ``message_level`` options.\n\nFinally, we've added two commonly used rules. As an optional substitute for ``login_required``, we have ``user_is_authenticated`` and to test a generic expression, we have ``evaluate_expression``.\n\nDirect Calling\n--------------\n\n::\n\n\timport logical_rules\n\tif logical_rules.site.test_rule(rule['name'], arg1, arg2):\n\t\tprint \"passed\"\n\telse:\n\t\tprint \"failed\"\n\nContributing\n============\n\nThink this needs something else? To contribute to ``django-logical-rules`` create a fork on Bitbucket_. Clone your fork, make some changes, and submit a pull request.\n\nBugs are great contributions too! Feel free to add an issue on Bitbucket_:\n\n.. _Bitbucket: https://bitbucket.org/aashe/django-logical-rules \n\n.. _DjangoMessaging: https://docs.djangoproject.com/en/dev/ref/contrib/messages/\n\n__ DjangoMessaging_", "description_content_type": null, "docs_url": null, "download_url": "UNKNOWN", "downloads": { "last_day": -1, "last_month": -1, "last_week": -1 }, "home_page": "https://bitbucket.org/aashe/django-logical-rules", "keywords": null, "license": "LICENSE", "maintainer": null, "maintainer_email": null, "name": "django-logical-rules", "package_url": "https://pypi.org/project/django-logical-rules/", "platform": "UNKNOWN", "project_url": "https://pypi.org/project/django-logical-rules/", "project_urls": { "Download": "UNKNOWN", "Homepage": "https://bitbucket.org/aashe/django-logical-rules" }, "release_url": "https://pypi.org/project/django-logical-rules/1.0/", "requires_dist": null, "requires_python": null, "summary": "A rule engine for Django apps.", "version": "1.0" }, "last_serial": 934168, "releases": { "0.1": [ { "comment_text": "", "digests": { "md5": "fa846c845ec15eaf344a75200ea42949", "sha256": "8aaa6a58b151271be63ce5402b7f5a88ec6dc377354490ce72009925253fc967" }, "downloads": -1, "filename": "django-logical-rules-0.1.tar.gz", "has_sig": false, "md5_digest": "fa846c845ec15eaf344a75200ea42949", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 9135, "upload_time": "2013-04-16T23:44:23", "url": "https://files.pythonhosted.org/packages/e6/b8/dfdd2eb5982c2cfbaae0b9639559305875167e74da8bb8e326528c8091c0/django-logical-rules-0.1.tar.gz" } ], "0.1.1": [ { "comment_text": "", "digests": { "md5": "c7e9bb78aee0da7b4c925fa17b898418", "sha256": "f58b45755412a446cb3d98a74a71715a34c789fcd1d5d3eebfb9cf9f4296fb62" }, "downloads": -1, "filename": "django-logical-rules-0.1.1.tar.gz", "has_sig": false, "md5_digest": "c7e9bb78aee0da7b4c925fa17b898418", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 9177, "upload_time": "2013-05-02T19:35:15", "url": "https://files.pythonhosted.org/packages/cf/bc/1696c69c83fa72410b22ef123aa1b991ef2d3e5c959e1e52388b33689ba6/django-logical-rules-0.1.1.tar.gz" } ], "1.0": [ { "comment_text": "", "digests": { "md5": "40ae2b01616dc17e39d8a5fed35da504", "sha256": "81060931c4692307678e1494c520db684af8050baa149d3e1b9e89b96f2cc4d1" }, "downloads": -1, "filename": "django-logical-rules-1.0.tar.gz", "has_sig": false, "md5_digest": "40ae2b01616dc17e39d8a5fed35da504", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 9653, "upload_time": "2013-12-02T21:28:48", "url": "https://files.pythonhosted.org/packages/e4/03/3bbe4cb8ed862271026e3328e9c815e6c926486834db692eec8edd14d91e/django-logical-rules-1.0.tar.gz" } ] }, "urls": [ { "comment_text": "", "digests": { "md5": "40ae2b01616dc17e39d8a5fed35da504", "sha256": "81060931c4692307678e1494c520db684af8050baa149d3e1b9e89b96f2cc4d1" }, "downloads": -1, "filename": "django-logical-rules-1.0.tar.gz", "has_sig": false, "md5_digest": "40ae2b01616dc17e39d8a5fed35da504", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 9653, "upload_time": "2013-12-02T21:28:48", "url": "https://files.pythonhosted.org/packages/e4/03/3bbe4cb8ed862271026e3328e9c815e6c926486834db692eec8edd14d91e/django-logical-rules-1.0.tar.gz" } ] }