<s> from django . core . urlresolvers import reverse <EOL> from django . http import Http404 , HttpResponseRedirect , HttpResponse <EOL> from django . shortcuts import render_to_response , get_object_or_404 <EOL> from django . template import RequestContext <EOL> from django . utils . translation import ugettext as _ <EOL> from django . conf import settings <EOL> from django . contrib import messages <EOL> from django . contrib . auth . decorators import login_required <EOL> from django . contrib . auth . models import AnonymousUser <EOL> from django . db . models import F <EOL> from actionlog . models import action_logging <EOL> from transifex . languages . models import Language <EOL> from transifex . projects . models import Project <EOL> from transifex . projects . signals import post_release_save <EOL> from transifex . projects . permissions import * <EOL> from transifex . releases import RELEASE_ALL_DATA <EOL> from transifex . releases . models import Release <EOL> from transifex . releases . forms import ReleaseForm <EOL> from transifex . resources . models import Resource , RLStats <EOL> from transifex . txcommon import notifications as txnotification <EOL> from transifex . txcommon . decorators import one_perm_required_or_403 <EOL> from transifex . txcommon . log import logger <EOL> from django . contrib . syndication . views import feed <EOL> from transifex . projects . permissions import pr_project_private_perm <EOL> @ login_required <EOL> @ one_perm_required_or_403 ( pr_release_add_change , <EOL> ( Project , '<STR_LIT>' , '<STR_LIT>' ) ) <EOL> def release_create_update ( request , project_slug , release_slug = None , * args , ** kwargs ) : <EOL> project = get_object_or_404 ( Project , slug__exact = project_slug ) <EOL> if release_slug : <EOL> release = get_object_or_404 ( Release , slug = release_slug , <EOL> project__slug = project_slug ) <EOL> else : <EOL> release = None <EOL> if request . method == '<STR_LIT:POST>' : <EOL> release_form = ReleaseForm ( <EOL> project , request . user , request . POST , instance = release <EOL> ) <EOL> if release_form . is_valid ( ) : <EOL> if release : <EOL> nt = "<STR_LIT>" <EOL> created = False <EOL> else : <EOL> nt = "<STR_LIT>" <EOL> created = True <EOL> release = release_form . save ( ) <EOL> context = { '<STR_LIT>' : project , <EOL> '<STR_LIT>' : release , } <EOL> object_list = [ project , release ] <EOL> action_logging ( request . user , object_list , nt , context = context ) <EOL> post_release_save . send ( sender = None , instance = release , <EOL> created = created , user = request . user ) <EOL> return HttpResponseRedirect ( <EOL> reverse ( '<STR_LIT>' , <EOL> args = [ project_slug , release . slug ] ) ) <EOL> else : <EOL> release_form = ReleaseForm ( project , request . user , instance = release ) <EOL> return render_to_response ( '<STR_LIT>' , { <EOL> '<STR_LIT>' : release_form , <EOL> '<STR_LIT>' : project , <EOL> '<STR_LIT>' : release , <EOL> } , context_instance = RequestContext ( request ) ) <EOL> @ one_perm_required_or_403 ( pr_project_private_perm , <EOL> ( Project , '<STR_LIT>' , '<STR_LIT>' ) , anonymous_access = True ) <EOL> def release_detail ( request , project_slug , release_slug ) : <EOL> release = get_object_or_404 ( Release , slug = release_slug , <EOL> project__slug = project_slug ) <EOL> resources = Resource . objects . select_related ( '<STR_LIT>' , <EOL> '<STR_LIT>' ) . filter ( releases = release , project__private = False <EOL> ) . order_by ( '<STR_LIT>' ) <EOL> source_languages = set ( ) <EOL> for resource in resources : <EOL> source_languages . add ( resource . source_language ) <EOL> if request . user in ( None , AnonymousUser ( ) ) : <EOL> private_resources = [ ] <EOL> else : <EOL> private_resources = Resource . objects . select_related ( '<STR_LIT>' , <EOL> '<STR_LIT>' ) . for_user ( request . user ) . filter ( <EOL> releases = release , project__private = True <EOL> ) . order_by ( '<STR_LIT>' ) . distinct ( ) <EOL> if not len ( source_languages ) == <NUM_LIT:1> : <EOL> source_languages = ( ) <EOL> statslist = RLStats . objects . select_related ( '<STR_LIT>' , '<STR_LIT>' <EOL> ) . for_user ( request . user ) . by_release_aggregated ( release ) <EOL> return render_to_response ( '<STR_LIT>' , { <EOL> '<STR_LIT>' : release , <EOL> '<STR_LIT>' : RELEASE_ALL_DATA [ '<STR_LIT>' ] , <EOL> '<STR_LIT>' : release . project , <EOL> '<STR_LIT>' : resources , <EOL> '<STR_LIT>' : private_resources , <EOL> '<STR_LIT>' : source_languages , <EOL> '<STR_LIT>' : statslist , <EOL> } , context_instance = RequestContext ( request ) ) <EOL> @ one_perm_required_or_403 ( pr_project_private_perm , <EOL> ( Project , '<STR_LIT>' , '<STR_LIT>' ) , anonymous_access = True ) <EOL> def release_language_detail ( request , project_slug , release_slug , language_code ) : <EOL> language = get_object_or_404 ( Language , code__iexact = language_code ) <EOL> project = get_object_or_404 ( Project , slug__exact = project_slug ) <EOL> release = get_object_or_404 ( Release , slug__exact = release_slug , <EOL> project__id = project . pk ) <EOL> stats = RLStats . objects . select_related ( '<STR_LIT>' , <EOL> '<STR_LIT>' ) . public ( ) . by_release_and_language ( release , language ) <EOL> private_stats = RLStats . objects . select_related ( '<STR_LIT>' , <EOL> '<STR_LIT>' , '<STR_LIT>' ) . for_user ( request . user <EOL> ) . private ( ) . by_release_and_language ( release , language ) <EOL> empty_rlstats = Resource . objects . filter ( id__in = release . resources . all ( ) , <EOL> project__private = False ) . exclude ( <EOL> id__in = stats . values ( '<STR_LIT>' ) ) <EOL> empty_private_rlstats = Resource . objects . for_user ( request . user ) . filter ( <EOL> id__in = release . resources . all ( ) , project__private = True ) . exclude ( <EOL> id__in = private_stats . values ( '<STR_LIT>' ) ) <EOL> return render_to_response ( '<STR_LIT>' , { <EOL> '<STR_LIT>' : project , <EOL> '<STR_LIT>' : release , <EOL> '<STR_LIT>' : language , <EOL> '<STR_LIT>' : stats , <EOL> '<STR_LIT>' : empty_rlstats , <EOL> '<STR_LIT>' : empty_private_rlstats , <EOL> '<STR_LIT>' : private_stats , <EOL> } , context_instance = RequestContext ( request ) ) <EOL> @ login_required <EOL> @ one_perm_required_or_403 ( pr_release_delete , <EOL> ( Project , '<STR_LIT>' , '<STR_LIT>' ) ) <EOL> def release_delete ( request , project_slug , release_slug ) : <EOL> release = get_object_or_404 ( Release , slug = release_slug , <EOL> project__slug = project_slug ) <EOL> if request . method == '<STR_LIT:POST>' : <EOL> import copy <EOL> release_ = copy . copy ( release ) <EOL> release . delete ( ) <EOL> messages . success ( request , <EOL> _ ( "<STR_LIT>" ) % release . full_name ) <EOL> nt = '<STR_LIT>' <EOL> context = { '<STR_LIT>' : release_ } <EOL> action_logging ( request . user , [ release_ . project ] , nt , context = context ) <EOL> if settings . ENABLE_NOTICES : <EOL> txnotification . send_observation_notices_for ( release_ . project , <EOL> signal = nt , extra_context = context ) <EOL> return HttpResponseRedirect ( reverse ( '<STR_LIT>' , <EOL> args = ( project_slug , ) ) ) <EOL> else : <EOL> return render_to_response ( '<STR_LIT>' , <EOL> { '<STR_LIT>' : release , } , <EOL> context_instance = RequestContext ( request ) ) <EOL> @ one_perm_required_or_403 ( pr_project_private_perm , <EOL> ( Project , '<STR_LIT>' , '<STR_LIT>' ) , anonymous_access = True ) <EOL> def release_feed ( request , project_slug , release_slug , slug = None , param = '<STR_LIT>' , <EOL> feed_dict = None , ) : <EOL> param = '<STR_LIT>' % ( project_slug , release_slug ) <EOL> if slug : <EOL> url = "<STR_LIT>" % ( slug , param ) <EOL> else : <EOL> url = param <EOL> return feed ( request , url , feed_dict ) <EOL> @ one_perm_required_or_403 ( pr_project_private_perm , <EOL> ( Project , '<STR_LIT>' , '<STR_LIT>' ) , anonymous_access = True ) <EOL> def release_language_feed ( request , project_slug , release_slug , language_code , <EOL> slug = None , param = '<STR_LIT>' , feed_dict = None , ) : <EOL> param = '<STR_LIT>' % ( project_slug , release_slug , language_code ) <EOL> if slug : <EOL> url = "<STR_LIT>" % ( slug , param ) <EOL> else : <EOL> url = param <EOL> return feed ( request , url , feed_dict ) </s>
