Depends on your code editor ?
--
Łukasz Rekucki
That's not very DRY, is it :-) Try class-based views (Django 1.3/trunk).
If you can't/don't want to use Django 1.3, you could do some automagic
"decorating" at the end of the file:
for view in ['view1, 'view2', ...]:
eval('{0} = your_decorator({0})'.format(view)')
Of couse you should prefer the first way.
Hope this helps :-)
Jonas
1. Write a middleware which will force authentication on all your
views (easy), or
2. If you absolutely must have this happen at the view level, stick
some code in the views file which loops over the views defined in the
file and applies the auth decorator to each one.
--
"Bureaucrat Conrad, you are technically correct -- the best kind of correct."
Class-based views won't help much here. Were do you put the
"login_required" decorator. You can make a common base class or a
mixin, but then you have to remember to inherit from that - pretty
much the same amount of work as using a decorator.
>
> If you can't/don't want to use Django 1.3, you could do some automagic
> "decorating" at the end of the file:
>
> for view in ['view1, 'view2', ...]:
> eval('{0} = your_decorator({0})'.format(view)')
>
You can always do some "automagic", but as the project grows it and
you introduce more magical decorators, you really start to understand
why "explicit is better the implicit". So I wouldn't recommend that.
--
Łukasz Rekucki
You just have to remember to exclude the login view somehow. This is
troublesome if you want to use a 3rd party app for authentication.
Using decorator like @login_not_required will make you fork it. Second
options is to hardcode excluded views in the middleware. I had this
problem too and decided to bite the bullet for the sake of simplicity.
>
> 2. If you absolutely must have this happen at the view level, stick
> some code in the views file which loops over the views defined in the
> file and applies the auth decorator to each one.
>
Now that's some "automagic" :). IMHO, putting a single line in front
of a view isn't THAT bad and gives important information to the person
reading the code.
--
Łukasz Rekucki
--
blog http://piotr.zalewa.info
jobs http://webdev.zalewa.info
twit http://twitter.com/zalun
face http://www.facebook.com/zaloon