<s> import logging <EOL> from operator import itemgetter <EOL> from itertools import chain <EOL> from django . utils . translation import ugettext_lazy as _ <EOL> from django . contrib . auth . decorators import login_required <EOL> from django . contrib . auth . models import User <EOL> from django . template import RequestContext <EOL> from django . db . models import Count <EOL> from django . http import ( HttpResponseRedirect , HttpResponseNotAllowed , <EOL> HttpResponseForbidden ) <EOL> from django . shortcuts import get_object_or_404 , render_to_response <EOL> from django . core . urlresolvers import reverse <EOL> from django . core . cache import cache <EOL> from django . views . decorators . csrf import ensure_csrf_cookie <EOL> from django . utils . decorators import method_decorator <EOL> from hashnav import DetailView , ListView <EOL> from mks . models import Member , Party <EOL> from forms import ( EditAgendaForm , AddAgendaForm , VoteLinkingFormSet , <EOL> MeetingLinkingFormSet ) <EOL> from models import Agenda , AgendaVote , AgendaMeeting , AgendaBill <EOL> import queries <EOL> from auxiliary . views import GetMoreView <EOL> logger = logging . getLogger ( "<STR_LIT>" ) <EOL> class AgendaListView ( ListView ) : <EOL> def get_queryset ( self ) : <EOL> if not self . request . user . is_authenticated ( ) : <EOL> return Agenda . objects . get_relevant_for_user ( user = None ) <EOL> else : <EOL> return Agenda . objects . get_relevant_for_user ( user = self . request . user ) <EOL> def get_context ( self , * args , ** kwargs ) : <EOL> context = super ( AgendaListView , self ) . get_context ( * args , ** kwargs ) <EOL> agenda_votes_results = Agenda . objects . values ( "<STR_LIT:id>" ) . annotate ( Count ( "<STR_LIT>" ) ) <EOL> agenda_votes = dict ( map ( lambda vote : ( vote [ "<STR_LIT:id>" ] , str ( vote [ "<STR_LIT>" ] ) ) , agenda_votes_results ) ) <EOL> parties_lookup = { party . id : party . name for <EOL> party in Party . current_knesset . all ( ) } <EOL> allAgendaPartyVotes = cache . get ( '<STR_LIT>' ) <EOL> if not allAgendaPartyVotes : <EOL> allAgendaPartyVotes = queries . getAllAgendaPartyVotes ( ) <EOL> for agenda_id , party_votes in allAgendaPartyVotes . iteritems ( ) : <EOL> allAgendaPartyVotes [ agenda_id ] = [ <EOL> x for x in party_votes if x [ <NUM_LIT:0> ] in parties_lookup ] <EOL> cache . set ( '<STR_LIT>' , allAgendaPartyVotes , <NUM_LIT> ) <EOL> if self . request . user . is_authenticated ( ) : <EOL> p = self . request . user . get_profile ( ) <EOL> watched = p . agendas <EOL> else : <EOL> watched = None <EOL> agendaEditorIds = queries . getAgendaEditorIds ( ) <EOL> allEditorIds = list ( set ( chain . from_iterable ( agendaEditorIds . values ( ) ) ) ) <EOL> editors = User . objects . filter ( id__in = allEditorIds ) <EOL> context [ '<STR_LIT>' ] = agendaEditorIds <EOL> context [ '<STR_LIT>' ] = dict ( map ( lambda obj : ( obj . id , obj ) , editors ) ) <EOL> context [ '<STR_LIT>' ] = watched <EOL> context [ '<STR_LIT>' ] = agenda_votes <EOL> context [ '<STR_LIT>' ] = allAgendaPartyVotes <EOL> context [ '<STR_LIT>' ] = parties_lookup <EOL> return context <EOL> class AgendaDetailView ( DetailView ) : <EOL> model = Agenda <EOL> INITIAL = <NUM_LIT:4> <EOL> class ForbiddenAgenda ( Exception ) : <EOL> pass <EOL> @ method_decorator ( ensure_csrf_cookie ) <EOL> def dispatch ( self , * args , ** kwargs ) : <EOL> return super ( AgendaDetailView , self ) . dispatch ( * args , ** kwargs ) <EOL> def get ( self , request , * arg , ** kwargs ) : <EOL> try : <EOL> response = super ( AgendaDetailView , self ) . get ( request , * arg , ** kwargs ) <EOL> except self . ForbiddenAgenda : <EOL> return HttpResponseForbidden ( ) <EOL> return response <EOL> def get_object ( self ) : <EOL> obj = super ( AgendaDetailView , self ) . get_object ( ) <EOL> has_id = Agenda . objects . get_relevant_for_user ( user = self . request . user ) . filter ( pk = obj . id ) . count ( ) > <NUM_LIT:0> <EOL> if has_id : <EOL> return obj <EOL> else : <EOL> raise self . ForbiddenAgenda <EOL> def get_context_data ( self , * args , ** kwargs ) : <EOL> context = super ( AgendaDetailView , self ) . get_context_data ( * args , ** kwargs ) <EOL> agenda = context [ '<STR_LIT:object>' ] <EOL> try : <EOL> context [ '<STR_LIT:title>' ] = "<STR_LIT:%s>" % agenda . name <EOL> except AttributeError : <EOL> context [ '<STR_LIT:title>' ] = _ ( '<STR_LIT:None>' ) <EOL> if self . request . user . is_authenticated ( ) : <EOL> p = self . request . user . get_profile ( ) <EOL> watched = agenda in p . agendas <EOL> watched_members = self . request . user . get_profile ( ) . members <EOL> else : <EOL> watched = False <EOL> watched_members = False <EOL> context . update ( { '<STR_LIT>' : watched } ) <EOL> context [ '<STR_LIT>' ] = watched_members <EOL> all_mks = '<STR_LIT>' in self . request . GET . keys ( ) <EOL> mks_values = agenda . get_mks_values ( ) <EOL> context [ '<STR_LIT>' ] = dict ( mks_values ) <EOL> cmp_rank = lambda x , y : x [ <NUM_LIT:1> ] [ '<STR_LIT>' ] - y [ <NUM_LIT:1> ] [ '<STR_LIT>' ] <EOL> if all_mks : <EOL> context [ '<STR_LIT>' ] = map ( itemgetter ( <NUM_LIT:0> ) , mks_values [ : <NUM_LIT:200> ] ) <EOL> context [ '<STR_LIT>' ] = True <EOL> else : <EOL> context [ '<STR_LIT>' ] = map ( itemgetter ( <NUM_LIT:0> ) , mks_values [ : <NUM_LIT:5> ] ) <EOL> context [ '<STR_LIT>' ] = map ( itemgetter ( <NUM_LIT:0> ) , mks_values [ - <NUM_LIT:5> : ] ) <EOL> allAgendaPartyVotes = agenda . get_all_party_values ( ) <EOL> context [ '<STR_LIT>' ] = dict ( map ( lambda x : ( x [ <NUM_LIT:0> ] , x [ <NUM_LIT:1> ] ) , allAgendaPartyVotes . setdefault ( agenda . id , [ ] ) ) ) <EOL> context [ '<STR_LIT>' ] = map ( itemgetter ( <NUM_LIT:0> ) , sorted ( allAgendaPartyVotes [ agenda . id ] , key = itemgetter ( <NUM_LIT:1> ) , reverse = True ) [ : <NUM_LIT:20> ] ) <EOL> agenda_votes = cache . get ( '<STR_LIT>' % agenda . id ) <EOL> if not agenda_votes : <EOL> agenda_votes = agenda . agendavotes . order_by ( <EOL> '<STR_LIT>' ) . select_related ( '<STR_LIT>' ) <EOL> cache . set ( '<STR_LIT>' % agenda . id , agenda_votes , <NUM_LIT> ) <EOL> try : <EOL> total_votes = agenda_votes . count ( ) <EOL> except TypeError : <EOL> total_votes = len ( agenda_votes ) <EOL> context [ '<STR_LIT>' ] = self . INITIAL <EOL> context [ '<STR_LIT>' ] = total_votes > self . INITIAL <EOL> context [ '<STR_LIT>' ] = agenda_votes [ : self . INITIAL ] <EOL> agenda_bills = agenda . agendabills . all ( ) <EOL> context [ '<STR_LIT>' ] = agenda_bills . count ( ) > self . INITIAL <EOL> context [ '<STR_LIT>' ] = agenda_bills [ : self . INITIAL ] <EOL> agenda_meetings = agenda . agendameetings . all ( ) <EOL> context [ '<STR_LIT>' ] = agenda_meetings . count ( ) > self . INITIAL <EOL> context [ '<STR_LIT>' ] = agenda_meetings [ : self . INITIAL ] <EOL> parties_objects = Party . objects . all ( ) <EOL> partiesDict = dict ( map ( lambda party : ( party . id , party ) , parties_objects ) ) <EOL> context [ '<STR_LIT>' ] = partiesDict <EOL> member_objects = Member . objects . all ( ) <EOL> membersDict = dict ( map ( lambda mk : ( mk . id , mk ) , member_objects ) ) <EOL> context [ '<STR_LIT>' ] = membersDict <EOL> return context <EOL> class AgendaVotesMoreView ( GetMoreView ) : <EOL> paginate_by = <NUM_LIT:10> <EOL> template_name = '<STR_LIT>' <EOL> def get_queryset ( self ) : <EOL> agenda = get_object_or_404 ( Agenda , pk = self . kwargs [ '<STR_LIT>' ] ) <EOL> agenda_votes = cache . get ( '<STR_LIT>' % agenda . id ) <EOL> if not agenda_votes : <EOL> agenda_votes = agenda . agendavotes . order_by ( <EOL> '<STR_LIT>' ) . select_related ( '<STR_LIT>' ) <EOL> cache . set ( '<STR_LIT>' % agenda . id , agenda_votes , <NUM_LIT> ) <EOL> return agenda_votes <EOL> def get_context_data ( self , * args , ** kwargs ) : <EOL> ctx = super ( AgendaVotesMoreView , self ) . get_context_data ( * args , ** kwargs ) <EOL> if self . request . user . is_authenticated ( ) : <EOL> p = self . request . user . get_profile ( ) <EOL> watched_members = p . members <EOL> else : <EOL> watched_members = False <EOL> ctx [ '<STR_LIT>' ] = watched_members <EOL> return ctx <EOL> class AgendaBillsMoreView ( GetMoreView ) : <EOL> paginate_by = <NUM_LIT:10> <EOL> template_name = '<STR_LIT>' <EOL> def get_queryset ( self ) : <EOL> agenda = get_object_or_404 ( Agenda , pk = self . kwargs [ '<STR_LIT>' ] ) <EOL> return agenda . agendabills . all ( ) <EOL> class AgendaMeetingsMoreView ( GetMoreView ) : <EOL> paginate_by = <NUM_LIT:10> <EOL> template_name = '<STR_LIT>' <EOL> def get_queryset ( self ) : <EOL> agenda = get_object_or_404 ( Agenda , pk = self . kwargs [ '<STR_LIT>' ] ) <EOL> return agenda . agendameetings . all ( ) <EOL> class AgendaVoteDetailView ( DetailView ) : <EOL> model = AgendaVote <EOL> template_name = '<STR_LIT>' <EOL> def get_context_data ( self , * args , ** kwargs ) : <EOL> context = super ( AgendaVoteDetailView , self ) . get_context_data ( * args , ** kwargs ) <EOL> agendavote = context [ '<STR_LIT:object>' ] <EOL> vote = agendavote . vote <EOL> agenda = agendavote . agenda <EOL> try : <EOL> context [ '<STR_LIT:title>' ] = _ ( "<STR_LIT>" ) % { <EOL> '<STR_LIT>' : vote . title , <EOL> '<STR_LIT>' : agenda . name } <EOL> except AttributeError : <EOL> context [ '<STR_LIT:title>' ] = _ ( '<STR_LIT:None>' ) <EOL> logger . error ( '<STR_LIT>' % ( agenda . id , vote . id ) ) <EOL> return context <EOL> class AgendaMeetingDetailView ( DetailView ) : <EOL> model = AgendaMeeting <EOL> template_name = '<STR_LIT>' <EOL> def get_context_data ( self , * args , ** kwargs ) : <EOL> context = super ( AgendaMeetingDetailView , self ) . get_context_data ( * args , ** kwargs ) <EOL> agendameeting = context [ '<STR_LIT:object>' ] <EOL> meeting = agendameeting . meeting <EOL> agenda = agendameeting . agenda <EOL> try : <EOL> context [ '<STR_LIT:title>' ] = _ ( "<STR_LIT>" ) % { <EOL> '<STR_LIT>' : meeting , <EOL> '<STR_LIT>' : agenda . name } <EOL> except AttributeError : <EOL> context [ '<STR_LIT:title>' ] = _ ( '<STR_LIT:None>' ) <EOL> logger . error ( '<STR_LIT>' % ( agenda . id , meeting . id ) ) <EOL> return context <EOL> class AgendaBillDetailView ( DetailView ) : <EOL> model = AgendaBill <EOL> template_name = '<STR_LIT>' <EOL> def get_context_data ( self , * args , ** kwargs ) : <EOL> context = super ( AgendaBillDetailView , self ) . get_context_data ( * args , ** kwargs ) <EOL> agendabill = context [ '<STR_LIT:object>' ] <EOL> bill = agendabill . bill <EOL> agenda = agendabill . agenda <EOL> try : <EOL> context [ '<STR_LIT:title>' ] = _ ( "<STR_LIT>" ) % { <EOL> '<STR_LIT>' : bill . full_title , <EOL> '<STR_LIT>' : agenda . name } <EOL> except AttributeError : <EOL> context [ '<STR_LIT:title>' ] = _ ( '<STR_LIT:None>' ) <EOL> logger . error ( '<STR_LIT>' % ( agenda . id , bill . id ) ) <EOL> return context <EOL> class AgendaMkDetailView ( DetailView ) : <EOL> model = Agenda <EOL> template_name = '<STR_LIT>' <EOL> def get_context_data ( self , * args , ** kwargs ) : <EOL> context = super ( AgendaMkDetailView , self ) . get_context_data ( * args , ** kwargs ) <EOL> agenda = context [ '<STR_LIT:object>' ] <EOL> context [ '<STR_LIT>' ] = agenda . get_absolute_url ( ) <EOL> context [ '<STR_LIT>' ] = agenda . name <EOL> member = Member . objects . get ( pk = context [ '<STR_LIT>' ] ) <EOL> context [ '<STR_LIT>' ] = member <EOL> context [ '<STR_LIT>' ] = member . get_absolute_url ( ) <EOL> context [ '<STR_LIT>' ] = agenda . member_score ( member ) <EOL> try : <EOL> context [ '<STR_LIT:title>' ] = _ ( "<STR_LIT>" ) % { '<STR_LIT>' : member . name , '<STR_LIT>' : agenda . name } <EOL> except AttributeError : <EOL> context [ '<STR_LIT:title>' ] = _ ( '<STR_LIT:None>' ) <EOL> logger . error ( '<STR_LIT>' % ( self . object_id , self . member_id ) ) <EOL> related_mk_votes = agenda . related_mk_votes ( member ) <EOL> if self . request . user . is_authenticated ( ) : <EOL> p = self . request . user . get_profile ( ) <EOL> watched = agenda in p . agendas <EOL> else : <EOL> watched = False <EOL> context . update ( { '<STR_LIT>' : watched } ) <EOL> context . update ( { '<STR_LIT>' : related_mk_votes } ) <EOL> return context <EOL> class AgendaDetailEditView ( DetailView ) : <EOL> model = Agenda <EOL> template_name = '<STR_LIT>' <EOL> def get ( self , request , * args , ** kwargs ) : <EOL> object_id = kwargs . get ( '<STR_LIT>' , kwargs . get ( '<STR_LIT>' , None ) ) <EOL> agenda = get_object_or_404 ( Agenda , pk = object_id ) <EOL> if request . user in agenda . editors . all ( ) : <EOL> return super ( AgendaDetailEditView , self ) . get ( request , * args , ** kwargs ) <EOL> else : <EOL> return HttpResponseRedirect ( agenda . get_absolute_url ( ) ) <EOL> def get_context_data ( self , * args , ** kwargs ) : <EOL> context = super ( AgendaDetailEditView , self ) . get_context_data ( * args , ** kwargs ) <EOL> agenda = context [ '<STR_LIT:object>' ] <EOL> form = getattr ( self , '<STR_LIT>' , None ) <EOL> if form is None : <EOL> form = EditAgendaForm ( agenda = agenda if self . request . method == '<STR_LIT:GET>' else None ) <EOL> context [ '<STR_LIT>' ] = form <EOL> return context <EOL> def post ( self , request , * args , ** kwargs ) : <EOL> object_id = kwargs . get ( '<STR_LIT>' , kwargs . get ( '<STR_LIT>' , None ) ) <EOL> agenda = get_object_or_404 ( Agenda , pk = object_id ) <EOL> if request . user not in agenda . editors . all ( ) : <EOL> return HttpResponseForbidden ( ) <EOL> form = EditAgendaForm ( data = self . request . POST ) <EOL> if form . is_valid ( ) : <EOL> agenda . name = form . cleaned_data [ '<STR_LIT:name>' ] <EOL> agenda . public_owner_name = form . cleaned_data [ '<STR_LIT>' ] <EOL> agenda . description = form . cleaned_data [ '<STR_LIT:description>' ] <EOL> agenda . save ( ) <EOL> return HttpResponseRedirect ( agenda . get_absolute_url ( ) ) <EOL> else : <EOL> self . form = form <EOL> return super ( AgendaDetailEditView , self ) . get ( request , * args , ** kwargs ) <EOL> @ login_required <EOL> def agenda_add_view ( request ) : <EOL> allowed_methods = [ '<STR_LIT:GET>' , '<STR_LIT:POST>' ] <EOL> template_name = '<STR_LIT>' <EOL> if not request . user . is_superuser : <EOL> return HttpResponseRedirect ( '<STR_LIT>' ) <EOL> if request . method == '<STR_LIT:POST>' : <EOL> form = AddAgendaForm ( request . POST ) <EOL> if form . is_valid ( ) : <EOL> agenda = Agenda ( ) <EOL> agenda . name = form . cleaned_data [ '<STR_LIT:name>' ] <EOL> agenda . public_owner_name = form . cleaned_data [ '<STR_LIT>' ] <EOL> agenda . description = form . cleaned_data [ '<STR_LIT:description>' ] <EOL> agenda . save ( ) <EOL> agenda . editors . add ( request . user ) <EOL> return HttpResponseRedirect ( agenda . get_absolute_url ( ) ) <EOL> else : <EOL> initial_data = { '<STR_LIT>' : request . user . username } <EOL> form = AddAgendaForm ( initial = initial_data ) <EOL> return render_to_response ( template_name , { '<STR_LIT>' : form } , context_instance = RequestContext ( request ) ) <EOL> object_redirect = { '<STR_LIT>' : ( '<STR_LIT>' , '<STR_LIT>' ) , <EOL> '<STR_LIT>' : ( '<STR_LIT>' , '<STR_LIT>' ) , <EOL> '<STR_LIT>' : ( '<STR_LIT>' , '<STR_LIT>' ) , <EOL> } <EOL> object_formset_classes = { '<STR_LIT>' : VoteLinkingFormSet , <EOL> '<STR_LIT>' : VoteLinkingFormSet , <EOL> '<STR_LIT>' : MeetingLinkingFormSet , <EOL> } <EOL> @ login_required <EOL> def update_editors_agendas ( request ) : <EOL> if request . method == '<STR_LIT:POST>' : <EOL> object_type = request . POST . get ( '<STR_LIT>' , None ) <EOL> object_id = request . POST . get ( '<STR_LIT>' , None ) <EOL> vl_formset = object_formset_classes [ object_type ] ( request . POST ) <EOL> if vl_formset . is_valid ( ) : <EOL> for a in vl_formset . cleaned_data : <EOL> if a : <EOL> try : <EOL> agenda = Agenda . objects . get ( pk = a [ '<STR_LIT>' ] ) <EOL> if request . user not in agenda . editors . all ( ) : <EOL> return HttpResponseForbidden ( ) <EOL> except Agenda . DoesNotExist : <EOL> return HttpResponseForbidden ( ) <EOL> if a [ '<STR_LIT>' ] == '<STR_LIT>' : <EOL> if a [ '<STR_LIT>' ] : <EOL> try : <EOL> object_id = a [ '<STR_LIT>' ] <EOL> av = AgendaVote . objects . get ( <EOL> agenda__id = a [ '<STR_LIT>' ] , <EOL> vote__id = a [ '<STR_LIT>' ] ) <EOL> av . delete ( ) <EOL> except AgendaVote . DoesNotExist : <EOL> pass <EOL> else : <EOL> if ( a [ '<STR_LIT>' ] is not '<STR_LIT>' and <EOL> a [ '<STR_LIT>' ] is not '<STR_LIT>' ) : <EOL> try : <EOL> object_id = a [ '<STR_LIT>' ] <EOL> av = AgendaVote . objects . get ( <EOL> agenda__id = a [ '<STR_LIT>' ] , <EOL> vote__id = a [ '<STR_LIT>' ] ) <EOL> av . score = a [ '<STR_LIT>' ] <EOL> av . importance = a [ '<STR_LIT>' ] <EOL> av . reasoning = a [ '<STR_LIT>' ] <EOL> av . save ( ) <EOL> except AgendaVote . DoesNotExist : <EOL> av = AgendaVote ( <EOL> agenda_id = int ( a [ '<STR_LIT>' ] ) , <EOL> vote_id = int ( a [ '<STR_LIT>' ] ) , <EOL> score = a [ '<STR_LIT>' ] , <EOL> importance = a [ '<STR_LIT>' ] , <EOL> reasoning = a [ '<STR_LIT>' ] ) <EOL> av . save ( ) <EOL> if a [ '<STR_LIT>' ] == '<STR_LIT>' : <EOL> if a [ '<STR_LIT>' ] : <EOL> try : <EOL> object_id = a [ '<STR_LIT>' ] <EOL> av = AgendaBill . objects . get ( <EOL> agenda__id = a [ '<STR_LIT>' ] , <EOL> bill__id = a [ '<STR_LIT>' ] ) <EOL> av . delete ( ) <EOL> except AgendaBill . DoesNotExist : <EOL> pass <EOL> else : <EOL> if ( a [ '<STR_LIT>' ] is not '<STR_LIT>' and <EOL> a [ '<STR_LIT>' ] is not '<STR_LIT>' ) : <EOL> try : <EOL> object_id = a [ '<STR_LIT>' ] <EOL> av = AgendaBill . objects . get ( <EOL> agenda__id = a [ '<STR_LIT>' ] , <EOL> bill__id = a [ '<STR_LIT>' ] ) <EOL> av . score = a [ '<STR_LIT>' ] <EOL> av . importance = a [ '<STR_LIT>' ] <EOL> av . reasoning = a [ '<STR_LIT>' ] <EOL> av . save ( ) <EOL> except AgendaBill . DoesNotExist : <EOL> av = AgendaBill ( <EOL> agenda_id = int ( a [ '<STR_LIT>' ] ) , <EOL> bill_id = int ( a [ '<STR_LIT>' ] ) , <EOL> score = a [ '<STR_LIT>' ] , <EOL> importance = a [ '<STR_LIT>' ] , <EOL> reasoning = a [ '<STR_LIT>' ] ) <EOL> av . save ( ) <EOL> if a [ '<STR_LIT>' ] == '<STR_LIT>' : <EOL> if a [ '<STR_LIT>' ] : <EOL> try : <EOL> object_id = a [ '<STR_LIT>' ] <EOL> av = AgendaMeeting . objects . get ( <EOL> agenda__id = a [ '<STR_LIT>' ] , <EOL> meeting__id = a [ '<STR_LIT>' ] ) <EOL> av . delete ( ) <EOL> except AgendaMeeting . DoesNotExist : <EOL> pass <EOL> else : <EOL> try : <EOL> object_id = a [ '<STR_LIT>' ] <EOL> av = AgendaMeeting . objects . get ( <EOL> agenda__id = a [ '<STR_LIT>' ] , <EOL> meeting__id = a [ '<STR_LIT>' ] ) <EOL> av . score = a [ '<STR_LIT>' ] <EOL> av . reasoning = a [ '<STR_LIT>' ] <EOL> av . save ( ) <EOL> except AgendaMeeting . DoesNotExist : <EOL> av = AgendaMeeting ( <EOL> agenda_id = int ( a [ '<STR_LIT>' ] ) , <EOL> meeting_id = int ( a [ '<STR_LIT>' ] ) , <EOL> score = a [ '<STR_LIT>' ] , <EOL> reasoning = a [ '<STR_LIT>' ] ) <EOL> av . save ( ) <EOL> else : <EOL> logger . info ( "<STR_LIT>" ) <EOL> else : <EOL> logger . info ( "<STR_LIT>" ) <EOL> logger . info ( "<STR_LIT:%s>" % vl_formset . errors ) <EOL> if object_type in object_redirect : <EOL> if object_id : <EOL> return HttpResponseRedirect ( <EOL> reverse ( object_redirect [ object_type ] [ <NUM_LIT:0> ] , <EOL> kwargs = { '<STR_LIT>' : object_id } ) ) <EOL> else : <EOL> return HttpResponseRedirect ( reverse ( object_redirect [ object_type ] [ <NUM_LIT:1> ] ) ) <EOL> else : <EOL> logger . warn ( '<STR_LIT>' ) <EOL> return HttpResponseRedirect ( reverse ( '<STR_LIT>' ) ) <EOL> else : <EOL> return HttpResponseNotAllowed ( [ '<STR_LIT:POST>' ] ) </s>
