Permalink
Browse files

Merge pull request #1 from rdegges/master

Removing Trailing Whitespace from Docs, Fixing Wording
  • Loading branch information...
2 parents 2b86bd5 + b50fb66 commit e774382d381de8940cde070ebacedfa577b0465a @jezdez jezdez committed Dec 3, 2011
View
@@ -19,10 +19,10 @@ Lets start with an example permission::
class FlatpagePermission(permissions.BasePermission):
label = 'flatpage_permission'
checks = ('can_do_foo',)
-
+
def can_do_foo(self):
# ...
-
+
authority.register(Campaign, FlatpagePermission)
A decorator for such a simple view would look like::
@@ -53,12 +53,12 @@ a string on the decorator::
@permission_required('flatpage_permission.can_do_foo', 'arg1', 'arg2')
def my_view(required, arg1, arg2):
# ...
-
+
What happens under the hood?::
# Assumed the view gets called like this
my_view(request, 'bla', 'blubb')
-
+
# At the end, the decorator would been called like this
can_do_foo('bla', 'blubb')
@@ -78,10 +78,10 @@ Here is an example::
# permission.py
def can_do_foo(self, flatpage_instance=None):
# ...
-
- # views.py
- from django.contrib.flatpages.models import Flatpage
- @permission_required('flatpage_permission.can_do_foo', (Flatpage, 'url__iexact', 'url))
+
+ # views.py
+ from django.contrib.flatpages.models import Flatpage
+ @permission_required('flatpage_permission.can_do_foo', (Flatpage, 'url__iexact', 'url'))
def flatpage(required, url):
# ...
View
@@ -4,4 +4,4 @@
Check permissions in python code
================================
-*to be written*
+*to be written*
View
@@ -50,7 +50,7 @@ Syntax and example::
{% get_permissions obj as "my_permissions" %}
{% get_permissions obj for request.user as "my_permissions" %}
-
+
get_permission
==============
@@ -66,7 +66,7 @@ Example::
{% get_permission "poll_permission.change_poll" for request.user and poll as "is_allowed" %}
{% get_permission "poll_permission.change_poll" for request.user and poll,second_poll as "is_allowed" %}
-
+
{% if is_allowed %}
I've got ze power to change ze pollllllzzz. Muahahaa.
{% else %}
View
@@ -1,5 +1,5 @@
.. _configuration:
-
+
=============
Configuration
=============
@@ -31,7 +31,7 @@ context processors::
'django.core.context_processors.media',
'django.core.context_processors.request',
)
-
+
urls.py
=======
@@ -70,7 +70,7 @@ In your python code
-------------------
::
- def my_view(request):
+ def my_view(request):
check = FlatPagePermission(request.user)
if check.change_flatpage():
print "Yay, you can change a flatpage!"
@@ -84,9 +84,9 @@ Using the view decorator
@permission_required_or_403('flatpage_permission.change_flatpage')
def my_view(request):
# ...
-
+
See :ref:`check-decorator` how the decorator works in detail.
-
+
In your templates
-----------------
::
@@ -108,7 +108,7 @@ applications. See :ref:`configuration` how to set up ``autodiscover``.
.. image:: .static/authority-permission-py.png
:align: left
-
+
We encourage you to place your permission classes in a file called
``permissions.py`` inside your application directories. This will not only
keep your application files clean, but it will also load every permission
@@ -25,12 +25,12 @@ A custom permission is a simple method of the permission class::
class FlatpagePermission(permissions.BasePermission):
label = 'flatpage_permission'
checks = ('my_custom_check',)
-
+
def my_custom_check(self, flatpage):
if(flatpage.url == '/about/'):
return True
return False
-
+
authority.register(Flatpage, FlatpagePermission)
Note that we first added the name of your custom permission to the ``checks``
@@ -47,13 +47,12 @@ permission is True or False::
return True
return False
-.. warning:: Although it's possible to return other values than ``True``, for
+.. warning:: Although it's possible to return other values than ``True``, for
example an object which also evluates to True, we highly advise to only
return booleans.
-Custom permissions are not necessary related to a model, you can define more
-simpler permissions too. For example, return True if it's between 10 and 12
-o'clock::
+Custom permissions are not necessary related to a model, you can define simpler
+permissions too. For example, return True if it's between 10 and 12 o'clock::
def datetime_check(self):
hour = int(datetime.datetime.now().strftime("%H"))
@@ -86,7 +85,7 @@ In your python code
::
from myapp.permissions import FlatPagePermission
- def my_view(request):
+ def my_view(request):
check = FlatPagePermission(request.user)
flatpage_object = Flatpage.objects.get(url='/homepage/')
if check.my_custom_check(flatpage=flatpage_object):
@@ -103,9 +102,9 @@ Using the view decorator
(Flatpage, 'url__iexact', 'url')) # The flatpage_object
def my_view(request, url):
# ...
-
+
See :ref:`check-decorator` how the decorator works in detail.
-
+
In your templates
-----------------
::
@@ -9,7 +9,7 @@ permission*. A description would be::
Attach a <codename> to an object
Attach a <codename> to an user
-
+
If the user has <codename> and the object has <codename> then do-something,
otherwise do-something-else.
@@ -39,7 +39,7 @@ Create per-object permissions
Creating per-object permissions is super simple. See this piece of permission
class code::
-
+
class FlatPagePermission(BasePermission):
label = 'flatpage_permission'
checks = ('review',)
@@ -85,7 +85,7 @@ In your python code
::
from myapp.permissions import FlatPagePermission
- def my_view(request):
+ def my_view(request):
check = FlatPagePermission(request.user)
flatpage_object = Flatpage.objects.get(url='/homepage/')
if check.review_flatpage(flatpage_object):
@@ -102,9 +102,9 @@ Using the view decorator
(Flatpage, 'url__iexact', 'url')) # The flatpage_object
def my_view(request, url):
# ...
-
+
See :ref:`check-decorator` how the decorator works in detail.
-
+
In your templates
-----------------
::
@@ -13,13 +13,13 @@ Headline scheme
===================================
First level (equals top and bottom)
===================================
-
+
Second Level (equals bottom)
============================
-
+
Third level (dashes botton)
---------------------------
-
+
Fourth level (drunken dashes bottom)
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
@@ -31,10 +31,10 @@ Overall salutation guidelines
Use the *We* and *you*::
We think that you should send us a bottle of your local beer.
-
+
Some thoughts
=============
* Many internal links are good
* Text should not be wider than 80 characters
-* Two pages are better than one ultra-long page
+* Two pages are better than one ultra-long page
View
@@ -4,4 +4,4 @@
Handling permissions in python code
===================================
-*to be written*
+*to be written*
@@ -4,4 +4,4 @@
Handling permissions using templates
====================================
-*to be written*
+*to be written*
View
@@ -37,15 +37,15 @@ Documentation
.. toctree::
:maxdepth: 1
-
+
installation
configuration
**Create and check permissions:**
-
+
.. toctree::
:maxdepth: 1
-
+
create_basic_permission
create_per_object_permission
create_custom_permission
@@ -54,7 +54,7 @@ Documentation
.. toctree::
:maxdepth: 2
-
+
check_python
check_decorator
check_templates
@@ -63,21 +63,21 @@ Documentation
.. toctree::
:maxdepth: 1
-
+
handling_python
handling_admin
handling_template
Other pages
===========
-
+
* :ref:`search`
* :ref:`genindex`
.. toctree::
:maxdepth: 1
:glob:
-
+
tips_tricks
support
documentation_guidelines
View
@@ -15,9 +15,9 @@ The latest, stable version is always available via the `Python package index_`
would prefer either ``pip`` or ``easy_install``::
pip install django-authority
-
+
# .. or with easy_install:
-
+
easy_install django-authority
.. _the site: http://pypi.python.org/pypi/django-authority/

0 comments on commit e774382

Please sign in to comment.