161d99ffe55a1333fcec866dc870eb615ed4bb32
1 # GNU MediaGoblin -- federated, autonomous media hosting
2 # Copyright (C) 2011 Free Software Foundation, Inc
4 # This program is free software: you can redistribute it and/or modify
5 # it under the terms of the GNU Affero General Public License as published by
6 # the Free Software Foundation, either version 3 of the License, or
7 # (at your option) any later version.
9 # This program is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 # GNU Affero General Public License for more details.
14 # You should have received a copy of the GNU Affero General Public License
15 # along with this program. If not, see <http://www.gnu.org/licenses/>.
21 def _make_safe(decorator
, original
):
23 Copy the function data from the old function to the decorator.
25 decorator
.__name
__ = original
.__name
__
26 decorator
.__dict
__ = original
.__dict
__
27 decorator
.__doc
__ = original
.__doc
__
31 def require_active_login(controller
):
33 Require an active login from the user.
35 def new_controller_func(request
, *args
, **kwargs
):
36 if not request
.user
or not request
.user
.get('status') == u
'active':
37 # TODO: Indicate to the user that they were redirected
38 # here because an *active* user is required.
40 location
="%s?next=%s" % (
41 request
.urlgen("mediagoblin.auth.login"),
44 return controller(request
, *args
, **kwargs
)
46 return _make_safe(new_controller_func
, controller
)
49 def uses_pagination(controller
):
51 Check request GET 'page' key for wrong values
53 def wrapper(request
, *args
, **kwargs
):
55 page
= int(request
.str_GET
['page'])
57 return exc
.HTTPNotFound()
59 return exc
.HTTPNotFound()
61 request
.str_GET
['page'] = 1
63 return controller(request
, *args
, **kwargs
)
65 return _make_safe(wrapper
,controller
)