<commit_before>#Get the main project for a team Amara, universalsubtitles.org
#
# Copyright (C) 2013 Participatory Culture Foundation
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as
# published by the Free Software Foundation, either version 3 of the
# License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program.  If not, see
# http://www.gnu.org/licenses/agpl-3.0.html.

"""new_views -- New team views

This module holds view functions for new-style teams.  Eventually it should
replace the old views.py module.
"""

from __future__ import absolute_import
import functools
import json
import logging
import pickle
from collections import namedtuple, OrderedDict

from django.conf import settings
from django.contrib import messages
from django.contrib.admin.views.decorators import staff_member_required
from django.contrib.auth.decorators import login_required
from django.contrib.auth.views import redirect_to_login
from django.core.cache import cache
from django.core.paginator import Paginator
from django.core.urlresolvers import reverse
from django.db.models import Q
from django.http import (Http404, HttpResponse, HttpResponseRedirect,
                         HttpResponseBadRequest)
from django.shortcuts import render, redirect, get_object_or_404
from django.utils.translation import ugettext as _

from . import views as old_views
from . import forms
from . import permissions
from . import signals
from . import tasks
from .behaviors import get_main_project
from .exceptions import ApplicationInvalidException
from .models import (Invite, Setting, Team, Project, TeamVideo,
                     TeamLanguagePreference, TeamMember, Application)
from .statistics import compute_statistics
from auth.models import CustomUser as User
from messages import tasks as messages_tasks
from subtitles.models import SubtitleLanguage
from teams.workflows import TeamWorkflow
from utils.breadcrumbs import BreadCrumb
from utils.pagination import AmaraPaginator
from utils.forms import autocomplete_user_view, FormRouter
from utils.text import fmt
from utils.translation import get_language_choices, get_language_label
from videos.models import Action, Video

logger = logging.getLogger('teams.views')

ACTIONS_PER_PAGE = 20
VIDEOS_PER_PAGE = 8
MEMBERS_PER_PAGE = 10

def team_view(view_func):
    @functools.wraps(view_func)
    def wrapper(request, slug, *args, **kwargs):
        if not request.user.is_authenticated():
            return redirect_to_login(request.path)
        if isinstance(slug, Team):
            # we've already fetched the team in with_old_view
            team = slug
        try:
            team = Team.objects.get(slug=slug)
        except Team.DoesNotExist:
            raise Http404
        if not team.user_is_member(request.user):
            raise Http404
        return view_func(request, team, *args, **kwargs)
    return wrapper

def with_old_view(old_view_func):
    def wrap(view_func):
        @functools.wraps(view_func)
        def wrapper(request, slug, *args, **kwargs):
            try:
                team = Team.objects.get(slug=slug)
            except Team.DoesNotExist:
                raise Http404
            if team.is_old_style():
                return old_view_func(request, team, *args, **kwargs)
            return view_func(request, team, *args, **kwargs)
        return wrapper
    return wrap

def admin_only_view(view_func):
    @functools.wraps(view_func)
    @team_view
    def wrapper(request, team, *args, **kwargs):
        member = team.get_member(request.user)
        if not member.is_admin():<commit_msg>Fixed 404 error on team member pages (#2376)<commit_after>#Get the main project for a team Amara, universalsubtitles.org
#
# Copyright (C) 2013 Participatory Culture Foundation
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as
# published by the Free Software Foundation, either version 3 of the
# License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program.  If not, see
# http://www.gnu.org/licenses/agpl-3.0.html.

"""new_views -- New team views

This module holds view functions for new-style teams.  Eventually it should
replace the old views.py module.
"""

from __future__ import absolute_import
import functools
import json
import logging
import pickle
from collections import namedtuple, OrderedDict

from django.conf import settings
from django.contrib import messages
from django.contrib.admin.views.decorators import staff_member_required
from django.contrib.auth.decorators import login_required
from django.contrib.auth.views import redirect_to_login
from django.core.cache import cache
from django.core.paginator import Paginator
from django.core.urlresolvers import reverse
from django.db.models import Q
from django.http import (Http404, HttpResponse, HttpResponseRedirect,
                         HttpResponseBadRequest)
from django.shortcuts import render, redirect, get_object_or_404
from django.utils.translation import ugettext as _

from . import views as old_views
from . import forms
from . import permissions
from . import signals
from . import tasks
from .behaviors import get_main_project
from .exceptions import ApplicationInvalidException
from .models import (Invite, Setting, Team, Project, TeamVideo,
                     TeamLanguagePreference, TeamMember, Application)
from .statistics import compute_statistics
from auth.models import CustomUser as User
from messages import tasks as messages_tasks
from subtitles.models import SubtitleLanguage
from teams.workflows import TeamWorkflow
from utils.breadcrumbs import BreadCrumb
from utils.pagination import AmaraPaginator
from utils.forms import autocomplete_user_view, FormRouter
from utils.text import fmt
from utils.translation import get_language_choices, get_language_label
from videos.models import Action, Video

logger = logging.getLogger('teams.views')

ACTIONS_PER_PAGE = 20
VIDEOS_PER_PAGE = 8
MEMBERS_PER_PAGE = 10

def team_view(view_func):
    @functools.wraps(view_func)
    def wrapper(request, slug, *args, **kwargs):
        if not request.user.is_authenticated():
            return redirect_to_login(request.path)
        if isinstance(slug, Team):
            # we've already fetched the team in with_old_view
            team = slug
        else:
            try:
                team = Team.objects.get(slug=slug)
            except Team.DoesNotExist:
                raise Http404
        if not team.user_is_member(request.user):
            raise Http404
        return view_func(request, team, *args, **kwargs)
    return wrapper

def with_old_view(old_view_func):
    def wrap(view_func):
        @functools.wraps(view_func)
        def wrapper(request, slug, *args, **kwargs):
            try:
                team = Team.objects.get(slug=slug)
            except Team.DoesNotExist:
                raise Http404
            if team.is_old_style():
                return old_view_func(request, team, *args, **kwargs)
            return view_func(request, team, *args, **kwargs)
        return wrapper
    return wrap

def admin_only_view(view_func):
    @functools.wraps(view_func)
    @team_view
    def wrapper(request, team, *args, **kwargs):
        member = team.get_member(request.user)
        if not member.is_admin():
{'fraction_non_alphanumeric': 0.06459596584581116, 'fraction_numerical': 0.007548570721445365, 'mean_word_length': 3.62621637092158, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4589737', 'n_tokens_mistral': 2227, 'n_tokens_neox': 2179, 'n_words': 795}