<s> """<STR_LIT>""" <EOL> from django . shortcuts import get_object_or_404 , redirect <EOL> from django . template . response import TemplateResponse <EOL> from django . views . decorators . cache import never_cache <EOL> from django . contrib import messages <EOL> from moztrap import model <EOL> from moztrap . model . mtmodel import NotDeletedCount <EOL> from moztrap . view . filters import RunFilterSet <EOL> from moztrap . view . lists import decorators as lists <EOL> from moztrap . view . lists . filters import PinnedFilters <EOL> from moztrap . view . users . decorators import permission_required <EOL> from moztrap . view . utils . ajax import ajax <EOL> from moztrap . view . utils . auth import login_maybe_required <EOL> from . . finders import ManageFinder <EOL> from . import forms <EOL> @ never_cache <EOL> @ login_maybe_required <EOL> @ lists . actions ( <EOL> model . Run , <EOL> [ "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" ] , <EOL> permission = "<STR_LIT>" ) <EOL> @ lists . finder ( ManageFinder ) <EOL> @ lists . filter ( "<STR_LIT>" , filterset_class = RunFilterSet ) <EOL> @ lists . sort ( "<STR_LIT>" ) <EOL> @ ajax ( "<STR_LIT>" ) <EOL> def runs_list ( request ) : <EOL> """<STR_LIT>""" <EOL> return TemplateResponse ( <EOL> request , <EOL> "<STR_LIT>" , <EOL> { <EOL> "<STR_LIT>" : model . Run . objects . select_related ( ) . annotate ( <EOL> suite_count = NotDeletedCount ( "<STR_LIT>" , distinct = True ) ) , <EOL> } <EOL> ) <EOL> @ never_cache <EOL> @ login_maybe_required <EOL> def run_details ( request , run_id ) : <EOL> """<STR_LIT>""" <EOL> run = get_object_or_404 ( <EOL> model . Run , pk = run_id ) <EOL> return TemplateResponse ( <EOL> request , <EOL> "<STR_LIT>" , <EOL> { <EOL> "<STR_LIT>" : run <EOL> } <EOL> ) <EOL> @ never_cache <EOL> @ permission_required ( "<STR_LIT>" ) <EOL> def run_add ( request ) : <EOL> """<STR_LIT>""" <EOL> if request . method == "<STR_LIT:POST>" : <EOL> form = forms . AddRunForm ( request . POST , user = request . user ) <EOL> run = form . save_if_valid ( ) <EOL> if run is not None : <EOL> messages . success ( <EOL> request , u"<STR_LIT>" . format ( <EOL> run . name ) <EOL> ) <EOL> return redirect ( "<STR_LIT>" ) <EOL> else : <EOL> pf = PinnedFilters ( request . COOKIES ) <EOL> form = forms . AddRunForm ( <EOL> user = request . user , <EOL> initial = pf . fill_form_querystring ( request . GET ) . dict ( ) , <EOL> ) <EOL> return TemplateResponse ( <EOL> request , <EOL> "<STR_LIT>" , <EOL> { <EOL> "<STR_LIT>" : form <EOL> } <EOL> ) <EOL> @ never_cache <EOL> @ permission_required ( "<STR_LIT>" ) <EOL> def run_edit ( request , run_id ) : <EOL> """<STR_LIT>""" <EOL> run = get_object_or_404 ( <EOL> model . Run , pk = run_id ) <EOL> if request . method == "<STR_LIT:POST>" : <EOL> form = forms . EditRunForm ( <EOL> request . POST , instance = run , user = request . user ) <EOL> saved_run = form . save_if_valid ( ) <EOL> if saved_run is not None : <EOL> messages . success ( request , u"<STR_LIT>" . format ( saved_run . name ) ) <EOL> pre_page = request . GET . get ( '<STR_LIT>' , "<STR_LIT>" ) <EOL> return redirect ( pre_page ) <EOL> else : <EOL> form = forms . EditRunForm ( <EOL> instance = run , user = request . user ) <EOL> return TemplateResponse ( <EOL> request , <EOL> "<STR_LIT>" , <EOL> { <EOL> "<STR_LIT>" : form , <EOL> "<STR_LIT>" : run , <EOL> } <EOL> ) </s>
