@@ -55,6 +55,7 @@ class EditPositionForm(forms.Form):
5555 position = forms .ChoiceField (choices = BALLOT_CHOICES , widget = forms .RadioSelect , required = False )
5656 discuss_text = forms .CharField (required = False , widget = forms .Textarea )
5757 comment_text = forms .CharField (required = False , widget = forms .Textarea )
58+ return_to_url = forms .CharField (required = False , widget = forms .HiddenInput )
5859
5960@group_required ('Area_Director' ,'Secretariat' )
6061def edit_position (request , name ):
@@ -65,6 +66,12 @@ def edit_position(request, name):
6566
6667 ad = login = IESGLogin .objects .get (login_name = request .user .username )
6768
69+ if 'HTTP_REFERER' in request .META :
70+ return_to_url = request .META ['HTTP_REFERER' ]
71+ else :
72+ return_to_url = doc .idinternal .get_absolute_url ()
73+
74+
6875 # if we're in the Secretariat, we can select an AD to act as stand-in for
6976 if not in_group (request .user , "Area_Director" ):
7077 ad_username = request .GET .get ('ad' )
@@ -77,8 +84,13 @@ def edit_position(request, name):
7784 if request .method == 'POST' :
7885 form = EditPositionForm (request .POST )
7986 if form .is_valid ():
87+
8088 # save the vote
8189 clean = form .cleaned_data
90+
91+ if clean ['return_to_url' ]:
92+ return_to_url = clean ['return_to_url' ]
93+
8294 vote = clean ['position' ]
8395 if pos :
8496 # mark discuss as cleared (quirk from old system)
@@ -142,13 +154,14 @@ def edit_position(request, name):
142154
143155 doc .idinternal .event_date = date .today ()
144156 doc .idinternal .save ()
157+
145158 if request .POST .get ("send_mail" ):
146- qstr = ""
159+ qstr = "?return_to_url=%s" % return_to_url
147160 if request .GET .get ('ad' ):
148- qstr = "? ad=%s" % request .GET .get ('ad' )
161+ qstr + = "& ad=%s" % request .GET .get ('ad' )
149162 return HttpResponseRedirect (urlreverse ("doc_send_ballot_comment" , kwargs = dict (name = doc .filename )) + qstr )
150163 else :
151- return HttpResponseRedirect (doc . idinternal . get_absolute_url () )
164+ return HttpResponseRedirect (return_to_url )
152165 else :
153166 initial = {}
154167 if pos :
@@ -159,15 +172,21 @@ def edit_position(request, name):
159172
160173 if comment :
161174 initial ['comment_text' ] = comment .text
175+
176+ if return_to_url :
177+ initial ['return_to_url' ] = return_to_url
162178
163179 form = EditPositionForm (initial = initial )
164180
181+
165182 return render_to_response ('idrfc/edit_position.html' ,
166183 dict (doc = doc ,
167184 form = form ,
168185 discuss = discuss ,
169186 comment = comment ,
170- ad = ad ),
187+ ad = ad ,
188+ return_to_url = return_to_url ,
189+ ),
171190 context_instance = RequestContext (request ))
172191
173192@group_required ('Area_Director' ,'Secretariat' )
@@ -178,6 +197,18 @@ def send_ballot_comment(request, name):
178197 raise Http404 ()
179198
180199 ad = login = IESGLogin .objects .get (login_name = request .user .username )
200+
201+ return_to_url = request .GET .get ('return_to_url' )
202+ if not return_to_url :
203+ return_to_url = doc .idinternal .get_absolute_url ()
204+
205+ if 'HTTP_REFERER' in request .META :
206+ back_url = request .META ['HTTP_REFERER' ]
207+ else :
208+ back_url = doc .idinternal .get_absolute_url ()
209+
210+
211+
181212 # if we're in the Secretariat, we can select an AD to act as stand-in for
182213 if not in_group (request .user , "Area_Director" ):
183214 ad_username = request .GET .get ('ad' )
@@ -210,7 +241,7 @@ def send_ballot_comment(request, name):
210241
211242 send_mail_text (request , to , frm , subject , body , cc = ", " .join (cc ))
212243
213- return HttpResponseRedirect (doc . idinternal . get_absolute_url () )
244+ return HttpResponseRedirect (return_to_url )
214245
215246 return render_to_response ('idrfc/send_ballot_comment.html' ,
216247 dict (doc = doc ,
@@ -219,7 +250,9 @@ def send_ballot_comment(request, name):
219250 frm = frm ,
220251 to = to ,
221252 ad = ad ,
222- can_send = d or c ),
253+ can_send = d or c ,
254+ back_url = back_url ,
255+ ),
223256 context_instance = RequestContext (request ))
224257
225258
0 commit comments