Skip to content

Commit

Permalink
Let's these rather be well-behaved decorators.
Browse files Browse the repository at this point in the history
  • Loading branch information
julen committed Aug 9, 2012
1 parent 51a3125 commit 3d0d1b2
Showing 1 changed file with 17 additions and 3 deletions.
20 changes: 17 additions & 3 deletions pootle/apps/pootle_app/views/language/view.py
@@ -1,7 +1,7 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
#
# Copyright 2008-2009 Zuza Software Foundation
# Copyright 2008-2012 Zuza Software Foundation
#
# This file is part of Pootle.
#
Expand All @@ -22,6 +22,8 @@
from django.shortcuts import get_object_or_404
from django.utils.translation import ugettext as _

from translate.misc.decorators import decorate

from pootle_app.models.directory import Directory
from pootle_app.models.permissions import (get_matching_permissions,
check_permission)
Expand Down Expand Up @@ -56,20 +58,32 @@ def get_stats_headings():
"suggestions": _("Suggestions"),
}


@decorate
def get_translation_project(f):
def decorated_f(request, language_code, project_code, *args, **kwargs):
translation_project = get_object_or_404(TranslationProject, language__code=language_code, project__code=project_code)
translation_project = get_object_or_404(
TranslationProject,
language__code=language_code,
project__code=project_code
)
return f(request, translation_project, *args, **kwargs)

return decorated_f


@decorate
def set_request_context(f):
def decorated_f(request, translation_project, *args, **kwargs):
# For now, all permissions in a translation project are
# relative to the root of that translation project.
request.profile = get_profile(request.user)
request.permissions = get_matching_permissions(request.profile, translation_project.directory)
request.permissions = get_matching_permissions(
request.profile, translation_project.directory
)
request.translation_project = translation_project
return f(request, translation_project, *args, **kwargs)

return decorated_f


Expand Down

0 comments on commit 3d0d1b2

Please sign in to comment.