22
33# Create your views here.
44from django .http import HttpResponsePermanentRedirect
5- from django import forms
65from django .template import RequestContext
76from django .shortcuts import get_object_or_404 , render_to_response
8- from django .db .models import Q
97from django .views .generic .list_detail import object_detail , object_list
10- from ietf .idtracker .models import InternetDraft , IDInternal , IDState , IDSubState , Rfc , DocumentWrapper
11- from ietf .idtracker .forms import IDSearch
12- from ietf .utils import normalize_draftname
8+ from ietf .idtracker .models import InternetDraft , IDInternal , IDState , IDSubState , BallotInfo , DocumentComment
139import re
1410
15- def search (request ):
16- # for compatability with old tracker form, which has
17- # "all substates" = 6.
18- args = request .GET .copy ()
19- if args .get ('sub_state_id' , '' ) == '6' :
20- args ['sub_state_id' ] = ''
21- # "job_owner" of "0" means "All/Any"
22- if args .get ('search_job_owner' , '' ) == '0' :
23- args ['search_job_owner' ] = ''
24- if args .has_key ('search_filename' ):
25- args ['search_filename' ] = normalize_draftname (args ['search_filename' ])
26- form = IDSearch (args )
27- # if there's a post, do the search and supply results to the template
28- searching = False
29- # filename, rfc_number, group searches are seperate because
30- # they can't be represented as simple searches in the data model.
31- qdict = {
32- 'search_job_owner' : 'job_owner' ,
33- 'search_cur_state' : 'cur_state' ,
34- 'sub_state_id' : 'cur_sub_state' ,
35- 'search_area_acronym' : 'area_acronym' ,
36- }
37- q_objs = []
38- for k in qdict .keys () + ['search_group_acronym' , 'search_rfcnumber' , 'search_filename' , 'search_status_id' ]:
39- if args .has_key (k ):
40- searching = True
41- if args [k ] != '' and qdict .has_key (k ):
42- q_objs .append (Q (** {qdict [k ]: args [k ]}))
43- if form .is_valid () == False :
44- searching = False
45- if searching :
46- # Non-ASCII group/filename doesn't match anything; this check
47- # is currently needed to avoid complaints from MySQL.
48- for k in ['search_group_acronym' ,'search_filename' ]:
49- try :
50- tmp = str (args .get (k , '' ))
51- except :
52- args [k ] = '*NOSUCH*'
53-
54- group = args .get ('search_group_acronym' , '' )
55- if group != '' :
56- rfclist = [rfc ['rfc_number' ] for rfc in Rfc .objects .all ().filter (group_acronym = group ).values ('rfc_number' )]
57- draftlist = [draft ['id_document_tag' ] for draft in InternetDraft .objects .all ().filter (group__acronym = group ).values ('id_document_tag' )]
58- if rfclist or draftlist :
59- q_objs .append (Q (draft__in = draftlist )& Q (rfc_flag = 0 )| Q (draft__in = rfclist )& Q (rfc_flag = 1 ))
60- else :
61- q_objs .append (Q (draft__isnull = True )) # no matches
62- rfc_number = args .get ('search_rfcnumber' , '' )
63- if rfc_number != '' :
64- draftlist = [draft ['id_document_tag' ] for draft in InternetDraft .objects .all ().filter (rfc_number = rfc_number ).values ('id_document_tag' )]
65- q_objs .append (Q (draft__in = draftlist )& Q (rfc_flag = 0 )| Q (draft = rfc_number )& Q (rfc_flag = 1 ))
66- filename = args .get ('search_filename' , '' )
67- if filename != '' :
68- q_objs .append (Q (draft__filename__icontains = filename ,rfc_flag = 0 ))
69- status = args .get ('search_status_id' , '' )
70- if status != '' :
71- q_objs .append (Q (draft__status = status ,rfc_flag = 0 ))
72- matches = IDInternal .objects .all ().exclude (draft = 999999 ).filter (* q_objs )
73- matches = matches .order_by ('cur_state' , 'cur_sub_state' , 'ballot' , '-primary_flag' )
74- # sort by date in reverse
75- # first build docstate groups, within which we sort
76- # in each docstate group, we build ballot id groups, which we sort
77- m1 = [] # list of: docstate, list of: event date; ballot id; list of: ms for the ballot id
78- for m in matches :
79- if m1 and m1 [- 1 ][0 ] == m .docstate ():
80- if m1 [- 1 ][1 ] and m1 [- 1 ][1 ][0 ][1 ] == m .ballot_id :
81- m1 [- 1 ][1 ][0 ][4 ].append (m )
82- else :
83- m1 [- 1 ][1 ].append ((m .event_date , m .ballot_id , m .primary_flag , m .draft_id , [m ]))
84- else :
85- m1 .append ((m .docstate (), [(m .event_date , m .ballot_id , m .primary_flag , m .draft_id , [m ])]))
86- matches = []
87- for ms in m1 : ms [1 ].sort (reverse = True )
88- for ms in m1 :
89- for mt in ms [1 ]:
90- matches .extend (mt [4 ])
91- #
92- # Now search by I-D exists, if there could be any results.
93- # If searching by job owner, current state or substate, there
94- # can't be any "I-D exists" matches.
95- if not (args .get ('search_job_owner' , 0 ) or args .get ('search_cur_state' , 0 ) or args .get ('sub_state_id' , 0 )):
96- if not (args .get ('search_rfcnumber' , 0 )):
97- in_tracker = [i ['draft' ] for i in IDInternal .objects .filter (rfc_flag = 0 ).values ('draft' )]
98- qdict = {
99- 'search_area_acronym' : 'group__ietfwg__areagroup__area' ,
100- 'search_group_acronym' : 'group__acronym' ,
101- 'search_filename' : 'filename__icontains' ,
102- #'search_status_id': 'status',
103- }
104- q_objs = [Q (** {qdict [k ]: args [k ]}) for k in qdict .keys () if args .get (k , '' ) != '' ]
105- idmatches = InternetDraft .objects .filter (* q_objs ).exclude (id_document_tag__in = in_tracker ).filter (status__status = 'Active' ).order_by ('filename' )
106- # resolve the queryset, append wrapper objects.
107- matches = list (matches ) + [DocumentWrapper (id ) for id in idmatches ]
108- if not (args .get ('search_filename' , '' ) or args .get ('search_status_id' , 0 )) and args .get ('search_rfcnumber' , 0 ):
109- # the existing area acronym support in this function
110- # in pidtracker.cgi is broken, since it compares an
111- # area acronym string in the database against an
112- # area acronym number in the form. We just ignore
113- # the area (resulting in a different search, but
114- # given that this search is only performed when there's
115- # an explicit rfc number, it seems more or less silly
116- # to filter it further anyway.)
117- in_tracker = [i ['draft' ] for i in IDInternal .objects .filter (rfc_flag = 1 ).values ('draft' )]
118- qdict = {
119- 'search_group_acronym' : 'group_acronym' ,
120- 'search_rfcnumber' : 'rfc_number' ,
121- 'search_status_id' : 'status' ,
122- }
123- q_objs = [Q (** {qdict [k ]: args [k ]}) for k in qdict .keys () if args .get (k , '' ) != '' ]
124- rfcmatches = Rfc .objects .filter (* q_objs ).exclude (rfc_number__in = in_tracker )
125- matches = list (matches ) + [DocumentWrapper (rfc ) for rfc in rfcmatches ]
126- else :
127- matches = None
128-
129- return render_to_response ('idtracker/idtracker_search.html' , {
130- 'form' : form ,
131- 'matches' : matches ,
132- 'searching' : searching ,
133- 'spacing' : True
134- }, context_instance = RequestContext (request ))
135-
13611def state_desc (request , state , is_substate = 0 ):
13712 if int (state ) == 100 :
13813 object = {
@@ -151,15 +26,6 @@ def state_desc(request, state, is_substate=0):
15126 return render_to_response ('idtracker/state_desc.html' , {'state' : object },
15227 context_instance = RequestContext (request ))
15328
154- def comment (request , slug , object_id , queryset ):
155- rfcnum = re .match (r'^rfc(\d+)$' , slug )
156- if rfcnum :
157- queryset = queryset .filter (document = rfcnum .groups ()[0 ])
158- else :
159- draft = get_object_or_404 (InternetDraft , filename = slug )
160- queryset = queryset .filter (document = draft .id_document_tag )
161- return object_detail (request , queryset = queryset , object_id = object_id )
162-
16329def status (request ):
16430 queryset = IDInternal .objects .filter (primary_flag = 1 ).exclude (cur_state__state__in = ('RFC Ed Queue' , 'RFC Published' , 'AD is watching' , 'Dead' )).order_by ('cur_state' , 'status_date' , 'ballot' )
16531 return object_list (request , template_name = "idtracker/status_of_items.html" , queryset = queryset , extra_context = {'title' : 'IESG Status of Items' })
@@ -173,36 +39,25 @@ def redirect_id(request, object_id):
17339 doc = get_object_or_404 (InternetDraft , id_document_tag = object_id )
17440 return HttpResponsePermanentRedirect ("/doc/" + doc .filename + "/" )
17541
176- # calling sequence similar to object_detail, but we have different
177- # 404 handling: if the draft exists, render a not-found template.
178- def view_id (request , queryset , slug , slug_field ):
179- try :
180- object = IDInternal .objects .get (draft__filename = slug , rfc_flag = 0 )
181- except IDInternal .DoesNotExist :
182- draft = get_object_or_404 (InternetDraft , filename = slug )
183- return HttpResponsePermanentRedirect ("/doc/" + draft .filename + "/" )
184- return render_to_response ('idtracker/idinternal_detail.html' , {'object' : object , 'spacing' : False }, context_instance = RequestContext (request ))
42+ def redirect_rfc (request , rfc_number ):
43+ return HttpResponsePermanentRedirect ("/doc/rfc" + rfc_number + "/" )
18544
186- def view_rfc (request , object_id ):
187- '''A replacement for the object_detail generic view for this
188- specific case to work around the following problem:
189- The object_detail generic view looks up the value of the
190- primary key in order to hand it to populate_xheaders.
191- In the IDInternal table, the primary key is a foreign key
192- to InternetDraft. object_detail assumes that the PK is not
193- an FK so doesn't do the foo_id trick, so the lookup is
194- attempted and an exception raised if there is no match.
195- This view gets the appropriate row from IDInternal and
196- calls the template with the necessary context.'''
197- object = get_object_or_404 (IDInternal , pk = object_id , rfc_flag = 1 )
198- return render_to_response ('idtracker/idinternal_detail.html' , {'object' : object , 'spacing' : False }, context_instance = RequestContext (request ))
45+ def redirect_filename (request , filename ):
46+ return HttpResponsePermanentRedirect ("/doc/" + filename + "/" )
19947
200- # Wrappers around object_detail to give permalink a handle.
201- # The named-URLs feature in django 0.97 will eliminate the
202- # need for these.
203- def view_comment (* args , ** kwargs ):
204- return object_detail (* args , ** kwargs )
48+ def redirect_ballot (request , object_id ):
49+ ballot = get_object_or_404 (BallotInfo , pk = object_id )
50+ id = ballot .drafts .filter (primary_flag = 1 )[0 ]
51+ if id .rfc_flag :
52+ return HttpResponsePermanentRedirect ("/doc/rfc" + str (id .draft_id )+ "/#ballot" )
53+ else :
54+ return HttpResponsePermanentRedirect ("/doc/" + id .draft .filename + "/#ballot" )
20555
206- def view_ballot (* args , ** kwargs ):
207- return object_detail (* args , ** kwargs )
56+ def redirect_comment (request , object_id ):
57+ comment = get_object_or_404 (DocumentComment , pk = object_id )
58+ id = comment .document
59+ if id .rfc_flag :
60+ return HttpResponsePermanentRedirect ("/doc/rfc" + str (id .draft_id )+ "/#history-" + str (object_id ))
61+ else :
62+ return HttpResponsePermanentRedirect ("/doc/" + id .draft .filename + "/#history-" + str (object_id ))
20863
0 commit comments