Commits

phuihock committed 3a17038

  • Participants
  • Parent commits 6f77fe0

Comments (0)

Files changed (1)

-== Welcome ==
-
-Welcome to your wiki! This is the default page we've installed for your convenience. Go ahead and edit it.
-
-=== Wiki features ===
-
-This wiki uses the [[http://www.wikicreole.org/|Creole]] syntax, and is fully compatible with the 1.0 specification.
-
-The wiki itself is actually a hg repository, which means you can clone it, edit it locally/offline, add images or any other file type, and push it back to us. It will be live immediately.
-
-Go ahead and try:
-
-{{{
-$ hg clone http://bitbucket.org/phuihock/django-pobject/wiki
-}}}
-
-Wiki pages are normal files, with the .wiki extension. You can edit them locally, as well as creating new ones.
-
-=== Syntax highlighting ===
-
-You can also highlight snippets of text, we use the excellent [[http://www.pygments.org/|Pygments]] library.
-
-Here's an example of some Python code:
-
-{{{
-#!python
-
-def wiki_rocks(text):
-	formatter = lambda t: "funky"+t
-	return formatter(text)
-}}}
-
-You can check out the source of this page to see how that's done, and make sure to bookmark [[http://pygments.org/docs/lexers/|the vast library of Pygment lexers]], we accept the 'short name' or the 'mimetype' of anything in there.
-
-Have fun!
+=== About ===
+An expressive and concise mini permission framework for Django views.
+
+Django lacks an object level permission checking mechanism. While there are other attempts to the problem, django-pobject presents a simpler and more straight forward way to achieve similar result.
+
+=== Examples ===
+**Senario 1:**\\
+Only family member can add new family member
+
+{{{
+#!python
+
+# permissions.py
+def is_family_member(request, family_id):
+    return request.user.is_family_member(family_id)
+}}}
+\\
+{{{
+#!python
+# views.py
+from permissions import *
+from pobject import P
+from pobject.decorators import permission_required
+
+@permission_required('', is_family_member)
+def add_family_member(request, family_id):
+    # adds a family member and returns response
+}}}
+\\
+If the current user is not a family member, an HttpForbidden will be raised. Otherwise, the view will be executed.
+\\
+\\
+
+**Senario 2:**\\
+Only parent can delete a family member
+
+{{{
+#!python
+
+# permissions.py
+def is_father(request, family_id, member_id):
+    return request.user.is_father(family_id)
+
+def is_mother(request, family_id, member_id):
+    return request.user.is_father(family_id)
+}}}
+\\
+{{{
+#!python
+
+# views.py
+from permissions import *
+from pobject import P
+from pobject.decorators import permission_required
+
+@permission_required('', P(is_father) & P(is_mother))
+def delete_family_member(request, family_id, member_id):
+    # deletes family member member_id and returns a response
+}}}
+\\
+
+**Senario 3:**\\
+Only family members can make announcement
+
+{{{
+#!python
+
+# permissions.py
+def is_child(request, family_id):
+    return request.user.is_child(family_id)
+
+def neighbor(request, family_id):
+    return request.user. neighbor(family_id)
+}}}
+\\
+{{{
+#!python
+
+# views.py
+from permissions import *
+from pobject import P
+from pobject.decorators import permission_required
+
+@permission_required('', (P(is_father) | P(is_mother) | P(is_child)) & ~(neighbor))
+def announce(request, family_id):
+    # makes announcement and returns a response
+}}}
+\\
+
+As you can see, it is possible to create permission checking of any level of complexity using bitwise operators similar to Q object in django.db. 
+
+The supported bitwise operators are summarized follow:
+ * {{{ & }}} for AND
+ * {{{ | }}} for OR
+ * {{{ ^ }}} for XOR
+ * {{{ ~ }}} negates a P object
+
+More examples can be found in [[https://bitbucket.org/phuihock/django-pobject/src/a20c354b7b3c/pobject/tests.py|tests.py]].
+
+=== Dependencies ===
+# [[https://bitbucket.org/phuihock/django-pobject/src/a20c354b7b3c/pobject/tests.py|exceptional_middelware]]
+
+=== Installation ===
+
+There is no official release yet since I am not sure how well it works or even accepted by the community. But if you decide to give it a try, do the following:
+
+{{{
+#!bash
+
+$ hg clone https://phuihock@bitbucket.org/phuihock/django-pobject
+$ cd django-pobject
+$ python bootstrap.py -d
+$ bin/buildout
+$ bin/django test pobject
+}}}
+\\
+
+I hope you like it!