<s> import datetime <EOL> from django . shortcuts import get_object_or_404 , redirect <EOL> from django . core . exceptions import PermissionDenied <EOL> from django . contrib import messages <EOL> from django . contrib . auth . decorators import login_required <EOL> from django . contrib . auth . models import User <EOL> from django . http import HttpResponse <EOL> from django . utils . translation import ugettext as _ <EOL> from django . utils . decorators import method_decorator <EOL> from django . utils . simplejson import dumps <EOL> from projector . models import Task <EOL> from projector . forms import TaskForm , TaskEditForm <EOL> from projector . filters import TaskFilter <EOL> from projector . views . project import ProjectView <EOL> from richtemplates . shortcuts import get_json_response <EOL> login_required_m = method_decorator ( login_required ) <EOL> class TaskListView ( ProjectView ) : <EOL> """<STR_LIT>""" <EOL> template_name = '<STR_LIT>' <EOL> perms_private = [ '<STR_LIT>' , '<STR_LIT>' ] <EOL> def response ( self , request , username , project_slug ) : <EOL> task_list = Task . objects . filter ( project__id = self . project . id ) . select_related ( '<STR_LIT>' , '<STR_LIT:status>' , '<STR_LIT>' , '<STR_LIT>' ) <EOL> filters = TaskFilter ( self . request . GET , queryset = task_list , <EOL> project = self . project ) <EOL> if self . request . GET and '<STR_LIT:id>' in self . request . GET and self . request . GET [ '<STR_LIT:id>' ] and filters . qs . count ( ) == <NUM_LIT:1> : <EOL> task = filters . qs [ <NUM_LIT:0> ] <EOL> messages . info ( self . request , _ ( "<STR_LIT>" ) ) <EOL> return redirect ( task . get_absolute_url ( ) ) <EOL> self . context [ '<STR_LIT>' ] = filters <EOL> return self . context <EOL> class TaskListDataView ( ProjectView ) : <EOL> """<STR_LIT>""" <EOL> def response ( self , request , username , project_slug ) : <EOL> import random <EOL> import pyofc2 <EOL> t = pyofc2 . title ( text = _ ( "<STR_LIT>" ) ) <EOL> b1 = pyofc2 . bar ( ) <EOL> b1 . values = range ( <NUM_LIT:10> ) <EOL> b2 = pyofc2 . bar ( ) <EOL> b2 . values = [ random . randint ( <NUM_LIT:0> , <NUM_LIT:9> ) for i in range ( <NUM_LIT:9> ) ] <EOL> b2 . colour = '<STR_LIT>' <EOL> chart = pyofc2 . open_flash_chart ( ) <EOL> chart . title = t <EOL> chart . add_element ( b1 ) <EOL> chart . add_element ( b2 ) <EOL> return HttpResponse ( chart . render ( ) ) <EOL> class TaskDetailView ( ProjectView ) : <EOL> """<STR_LIT>""" <EOL> template_name = '<STR_LIT>' <EOL> perms_private = [ '<STR_LIT>' , '<STR_LIT>' ] <EOL> perms_POST = [ '<STR_LIT>' ] <EOL> def response ( self , request , username , project_slug , task_id ) : <EOL> task = get_object_or_404 ( <EOL> Task . objects . select_related ( '<STR_LIT:type>' , '<STR_LIT>' , '<STR_LIT:status>' , '<STR_LIT>' , <EOL> '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ) , <EOL> id = task_id , <EOL> project__author__username = username , <EOL> project__slug = project_slug ) <EOL> self . context [ '<STR_LIT>' ] = task <EOL> self . context [ '<STR_LIT>' ] = task . is_watched ( request . user ) <EOL> self . context [ '<STR_LIT>' ] = datetime . datetime . now ( ) <EOL> return self . context <EOL> class TaskCreateView ( ProjectView ) : <EOL> """<STR_LIT>""" <EOL> template_name = '<STR_LIT>' <EOL> perms = ProjectView . perms + [ '<STR_LIT>' ] <EOL> @ login_required_m <EOL> def response ( self , request , username , project_slug ) : <EOL> initial = { <EOL> '<STR_LIT>' : request . user . username , <EOL> } <EOL> instance = Task . objects . get_for_project ( self . project ) <EOL> instance . author = request . user <EOL> instance . author_ip = request . META . get ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> instance . editor = instance . author <EOL> instance . editor_ip = instance . author_ip <EOL> form = TaskForm ( request . POST or None , initial = initial , instance = instance ) <EOL> if request . method == '<STR_LIT:POST>' : <EOL> if form . is_valid ( ) : <EOL> task = form . save ( <EOL> editor = request . user , <EOL> editor_ip = request . META . get ( '<STR_LIT>' , '<STR_LIT>' ) , <EOL> ) <EOL> task . create_revision ( ) <EOL> messages . success ( request , _ ( "<STR_LIT>" ) ) <EOL> task . notify ( ) <EOL> return redirect ( task . get_absolute_url ( ) ) <EOL> self . context [ '<STR_LIT>' ] = form <EOL> return self . context <EOL> class TaskEditView ( ProjectView ) : <EOL> """<STR_LIT>""" <EOL> template_name = '<STR_LIT>' <EOL> perms = [ '<STR_LIT>' ] <EOL> @ login_required_m <EOL> def response ( self , request , username , project_slug , task_id ) : <EOL> task = get_object_or_404 ( Task , id = task_id , <EOL> project__author__username = username , project__slug = project_slug ) <EOL> if request . method == '<STR_LIT:POST>' : <EOL> form = TaskEditForm ( request . POST , instance = task ) <EOL> if form . is_valid ( ) : <EOL> if request . user . is_authenticated ( ) : <EOL> editor = request . user <EOL> else : <EOL> editor = User . get_anonymous ( ) <EOL> task = form . save ( <EOL> editor = editor , <EOL> editor_ip = request . META . get ( '<STR_LIT>' , '<STR_LIT>' ) , <EOL> ) <EOL> task . create_revision ( ) <EOL> messages . success ( request , _ ( "<STR_LIT>" ) ) <EOL> task . notify ( ) <EOL> return redirect ( task . get_absolute_url ( ) ) <EOL> else : <EOL> form = TaskEditForm ( instance = task , initial = { <EOL> '<STR_LIT>' : task . owner and task . owner . username or None , <EOL> } ) <EOL> self . context [ '<STR_LIT>' ] = form <EOL> return self . context <EOL> class TaskWatchView ( ProjectView ) : <EOL> """<STR_LIT>""" <EOL> perms_private = [ '<STR_LIT>' , '<STR_LIT>' ] <EOL> def response ( self , request , username , project_slug , task_id ) : <EOL> task = get_object_or_404 ( Task , id = task_id , <EOL> project__author__username = username , project__slug = project_slug ) <EOL> if request . method == '<STR_LIT:POST>' : <EOL> task . watch ( request . user ) <EOL> if request . is_ajax ( ) : <EOL> return get_json_response ( ) <EOL> return redirect ( task . get_absolute_url ( ) ) <EOL> else : <EOL> raise PermissionDenied ( ) <EOL> class TaskUnwatchView ( ProjectView ) : <EOL> """<STR_LIT>""" <EOL> perms_private = [ '<STR_LIT>' , '<STR_LIT>' ] <EOL> def response ( self , request , username , project_slug , task_id ) : <EOL> task = get_object_or_404 ( Task , id = task_id , <EOL> project__author__username = username , project__slug = project_slug ) <EOL> if request . method == '<STR_LIT:POST>' : <EOL> if request . is_ajax ( ) : <EOL> return get_json_response ( ) <EOL> task . unwatch ( request . user ) <EOL> return redirect ( task . get_absolute_url ( ) ) <EOL> else : <EOL> raise PermissionDenied ( ) </s>
