1313from os .path import splitext
1414
1515# ---------------------------------------------
16- # Select Choices
16+ # Select Choices
1717# ---------------------------------------------
1818WITHDRAW_CHOICES = (('ietf' ,'Withdraw by IETF' ),('author' ,'Withdraw by Author' ))
1919
2020# ---------------------------------------------
21- # Custom Fields
21+ # Custom Fields
2222# ---------------------------------------------
2323class DocumentField (forms .FileField ):
2424 '''A validating document upload field'''
25-
25+
2626 def __init__ (self , unique = False , * args , ** kwargs ):
2727 self .extension = kwargs .pop ('extension' )
2828 self .filename = kwargs .pop ('filename' )
@@ -36,7 +36,7 @@ def clean(self, data, initial=None):
3636 m = re .search (r'.*-\d{2}\.(txt|pdf|ps|xml)' , file .name )
3737 if not m :
3838 raise forms .ValidationError ('File name must be in the form base-NN.[txt|pdf|ps|xml]' )
39-
39+
4040 # ensure file extension is correct
4141 base ,ext = os .path .splitext (file .name )
4242 if ext != self .extension :
@@ -51,44 +51,44 @@ def clean(self, data, initial=None):
5151 next_revision = str (int (self .rev )+ 1 ).zfill (2 )
5252 if base [- 2 :] != next_revision :
5353 raise forms .ValidationError , "Expected revision # %s" % (next_revision )
54-
54+
5555 return file
5656
5757class GroupModelChoiceField (forms .ModelChoiceField ):
5858 '''
59- Custom ModelChoiceField sets queryset to include all active workgroups and the
59+ Custom ModelChoiceField sets queryset to include all active workgroups and the
6060 individual submission group, none. Displays group acronyms as choices. Call it without the
6161 queryset argument, for example:
62-
62+
6363 group = GroupModelChoiceField(required=True)
6464 '''
6565 def __init__ (self , * args , ** kwargs ):
6666 kwargs ['queryset' ] = Group .objects .filter (type__in = ('wg' ,'individ' ),state__in = ('bof' ,'proposed' ,'active' )).order_by ('acronym' )
6767 super (GroupModelChoiceField , self ).__init__ (* args , ** kwargs )
68-
68+
6969 def label_from_instance (self , obj ):
7070 return obj .acronym
7171
7272class AliasModelChoiceField (forms .ModelChoiceField ):
7373 '''
74- Custom ModelChoiceField, just uses Alias name in the select choices as opposed to the
74+ Custom ModelChoiceField, just uses Alias name in the select choices as opposed to the
7575 more confusing alias -> doc format used by DocAlias.__unicode__
76- '''
76+ '''
7777 def label_from_instance (self , obj ):
7878 return obj .name
79-
79+
8080# ---------------------------------------------
81- # Forms
81+ # Forms
8282# ---------------------------------------------
8383class AddModelForm (forms .ModelForm ):
8484 start_date = forms .DateField ()
8585 group = GroupModelChoiceField (required = True ,help_text = 'Use group "none" for Individual Submissions' )
86-
86+
8787 class Meta :
8888 model = Document
8989 fields = ('title' ,'group' ,'stream' ,'start_date' ,'pages' ,'abstract' ,'internal_comments' )
90-
91- # use this method to set attrs which keeps other meta info from model.
90+
91+ # use this method to set attrs which keeps other meta info from model.
9292 def __init__ (self , * args , ** kwargs ):
9393 super (AddModelForm , self ).__init__ (* args , ** kwargs )
9494 self .fields ['title' ].label = 'Document Name'
@@ -104,25 +104,25 @@ class AuthorForm(forms.Form):
104104 '''
105105 person = forms .CharField (max_length = 50 ,widget = forms .TextInput (attrs = {'class' :'name-autocomplete' }),help_text = "To see a list of people type the first name, or last name, or both." )
106106 email = forms .CharField (widget = forms .Select (),help_text = "Select an email" )
107-
108- # check for id within parenthesis to ensure name was selected from the list
107+
108+ # check for id within parenthesis to ensure name was selected from the list
109109 def clean_person (self ):
110110 person = self .cleaned_data .get ('person' , '' )
111111 m = re .search (r'(\d+)' , person )
112112 if person and not m :
113- raise forms .ValidationError ("You must select an entry from the list!" )
114-
113+ raise forms .ValidationError ("You must select an entry from the list!" )
114+
115115 # return person object
116116 return get_person (person )
117-
117+
118118 # check that email exists and return the Email object
119119 def clean_email (self ):
120120 email = self .cleaned_data ['email' ]
121121 try :
122122 obj = Email .objects .get (address = email )
123123 except Email .ObjectDoesNoExist :
124124 raise forms .ValidationError ("Email address not found!" )
125-
125+
126126 # return email object
127127 return obj
128128
@@ -133,12 +133,12 @@ class EditModelForm(forms.ModelForm):
133133 group = GroupModelChoiceField (required = True )
134134 review_by_rfc_editor = forms .BooleanField (required = False )
135135 shepherd = forms .CharField (max_length = 100 ,widget = forms .TextInput (attrs = {'class' :'name-autocomplete' }),help_text = "To see a list of people type the first name, or last name, or both." ,required = False )
136-
136+
137137 class Meta :
138138 model = Document
139- fields = ('title' ,'group' ,'ad' ,'shepherd' ,'notify' ,'stream' ,'review_by_rfc_editor' ,'name' ,'rev' ,'pages' ,'intended_std_level' ,'abstract' ,'internal_comments' )
140-
141- # use this method to set attrs which keeps other meta info from model.
139+ fields = ('title' ,'group' ,'ad' ,'shepherd' ,'notify' ,'stream' ,'review_by_rfc_editor' ,'name' ,'rev' ,'pages' ,'intended_std_level' ,'std_level' , ' abstract' ,'internal_comments' )
140+
141+ # use this method to set attrs which keeps other meta info from model.
142142 def __init__ (self , * args , ** kwargs ):
143143 super (EditModelForm , self ).__init__ (* args , ** kwargs )
144144 self .fields ['ad' ].queryset = Person .objects .filter (role__name = 'ad' )
@@ -151,36 +151,36 @@ def __init__(self, *args, **kwargs):
151151 self .initial ['iesg_state' ] = self .instance .get_state ('draft-iesg' ).pk
152152 if self .instance .shepherd :
153153 self .initial ['shepherd' ] = "%s - (%s)" % (self .instance .shepherd .name , self .instance .shepherd .id )
154-
154+
155155 # setup special fields
156156 if self .instance :
157157 # setup replaced
158158 self .fields ['review_by_rfc_editor' ].initial = bool (self .instance .tags .filter (slug = 'rfc-rev' ))
159-
159+
160160 def save (self , force_insert = False , force_update = False , commit = True ):
161161 m = super (EditModelForm , self ).save (commit = False )
162162 state = self .cleaned_data ['state' ]
163163 iesg_state = self .cleaned_data ['iesg_state' ]
164-
164+
165165 if 'state' in self .changed_data :
166166 m .set_state (state )
167-
167+
168168 # note we're not sending notices here, is this desired
169169 if 'iesg_state' in self .changed_data :
170170 if iesg_state == None :
171171 m .unset_state ('draft-iesg' )
172172 else :
173173 m .set_state (iesg_state )
174-
174+
175175 if 'review_by_rfc_editor' in self .changed_data :
176176 if self .cleaned_data .get ('review_by_rfc_editor' ,'' ):
177177 m .tags .add ('rfc-rev' )
178178 else :
179179 m .tags .remove ('rfc-rev' )
180-
180+
181181 m .time = datetime .datetime .now ()
182182 # handle replaced by
183-
183+
184184 if commit :
185185 m .save ()
186186 return m
@@ -189,19 +189,19 @@ def save(self, force_insert=False, force_update=False, commit=True):
189189 def clean_replaced_by (self ):
190190 name = self .cleaned_data .get ('replaced_by' , '' )
191191 if name and not InternetDraft .objects .filter (filename = name ):
192- raise forms .ValidationError ("ERROR: Draft does not exist" )
192+ raise forms .ValidationError ("ERROR: Draft does not exist" )
193193 return name
194-
195- # check for id within parenthesis to ensure name was selected from the list
194+
195+ # check for id within parenthesis to ensure name was selected from the list
196196 def clean_shepherd (self ):
197197 person = self .cleaned_data .get ('shepherd' , '' )
198198 m = re .search (r'(\d+)' , person )
199199 if person and not m :
200- raise forms .ValidationError ("You must select an entry from the list!" )
201-
200+ raise forms .ValidationError ("You must select an entry from the list!" )
201+
202202 # return person object
203203 return get_person (person )
204-
204+
205205 def clean (self ):
206206 super (EditModelForm , self ).clean ()
207207 cleaned_data = self .cleaned_data
@@ -233,7 +233,7 @@ class EmailForm(forms.Form):
233233
234234class ExtendForm (forms .Form ):
235235 expiration_date = forms .DateField ()
236-
236+
237237class ReplaceForm (forms .Form ):
238238 replaced = AliasModelChoiceField (DocAlias .objects .none (),empty_label = None ,help_text = 'This document may have more than one alias. Be sure to select the correct alias to replace.' )
239239 replaced_by = forms .CharField (max_length = 100 ,help_text = 'Enter the filename of the Draft which replaces this one.' )
@@ -242,7 +242,7 @@ def __init__(self, *args, **kwargs):
242242 self .draft = kwargs .pop ('draft' )
243243 super (ReplaceForm , self ).__init__ (* args , ** kwargs )
244244 self .fields ['replaced' ].queryset = DocAlias .objects .filter (document = self .draft )
245-
245+
246246 # field must contain filename of existing draft
247247 def clean_replaced_by (self ):
248248 name = self .cleaned_data .get ('replaced_by' , '' )
@@ -263,57 +263,57 @@ class RevisionModelForm(forms.ModelForm):
263263 class Meta :
264264 model = Document
265265 fields = ('title' ,'pages' ,'abstract' )
266-
267- # use this method to set attrs which keeps other meta info from model.
266+
267+ # use this method to set attrs which keeps other meta info from model.
268268 def __init__ (self , * args , ** kwargs ):
269269 super (RevisionModelForm , self ).__init__ (* args , ** kwargs )
270270 self .fields ['title' ].label = 'Document Name'
271271 self .fields ['title' ].widget = forms .Textarea ()
272272 self .fields ['pages' ].label = 'Number of Pages'
273-
273+
274274class RfcModelForm (forms .ModelForm ):
275275 rfc_number = forms .IntegerField ()
276276 rfc_published_date = forms .DateField (initial = datetime .datetime .now )
277277 group = GroupModelChoiceField (required = True )
278-
278+
279279 class Meta :
280280 model = Document
281281 fields = ('title' ,'group' ,'pages' ,'std_level' ,'internal_comments' )
282-
283- # use this method to set attrs which keeps other meta info from model.
282+
283+ # use this method to set attrs which keeps other meta info from model.
284284 def __init__ (self , * args , ** kwargs ):
285285 super (RfcModelForm , self ).__init__ (* args , ** kwargs )
286286 self .fields ['title' ].widget = forms .Textarea ()
287287 self .fields ['std_level' ].required = True
288-
288+
289289 def save (self , force_insert = False , force_update = False , commit = True ):
290290 obj = super (RfcModelForm , self ).save (commit = False )
291-
291+
292292 # create DocAlias
293293 DocAlias .objects .create (document = self .instance ,name = "rfc%d" % self .cleaned_data ['rfc_number' ])
294-
294+
295295 if commit :
296296 obj .save ()
297297 return obj
298-
298+
299299 def clean_rfc_number (self ):
300300 rfc_number = self .cleaned_data ['rfc_number' ]
301301 if DocAlias .objects .filter (name = 'rfc' + str (rfc_number )):
302302 raise forms .ValidationError ("RFC %d already exists" % rfc_number )
303303 return rfc_number
304-
304+
305305class RfcObsoletesForm (forms .Form ):
306306 relation = forms .ModelChoiceField (queryset = DocRelationshipName .objects .filter (slug__in = ('updates' ,'obs' )),required = False )
307307 rfc = forms .IntegerField (required = False )
308-
308+
309309 # ensure that RFC exists
310310 def clean_rfc (self ):
311311 rfc = self .cleaned_data .get ('rfc' ,'' )
312312 if rfc :
313313 if not Document .objects .filter (docalias__name = "rfc%s" % rfc ):
314314 raise forms .ValidationError ("RFC does not exist" )
315315 return rfc
316-
316+
317317 def clean (self ):
318318 super (RfcObsoletesForm , self ).clean ()
319319 cleaned_data = self .cleaned_data
@@ -348,8 +348,8 @@ def __init__(self, *args, **kwargs):
348348 for field in self .fields .itervalues ():
349349 field .filename = self .draft .name
350350 field .rev = self .draft .rev
351-
352-
351+
352+
353353 def clean (self ):
354354 # Checks that all files have the same base
355355 if any (self .errors ):
@@ -359,7 +359,7 @@ def clean(self):
359359 xml = self .cleaned_data ['xml' ]
360360 pdf = self .cleaned_data ['pdf' ]
361361 ps = self .cleaned_data ['ps' ]
362-
362+
363363 # we only need to do these validations for new drafts
364364 if not self .draft :
365365 names = []
@@ -368,19 +368,19 @@ def clean(self):
368368 base = splitext (file .name )[0 ]
369369 if base not in names :
370370 names .append (base )
371-
371+
372372 if len (names ) > 1 :
373373 raise forms .ValidationError , "All files must have the same base name"
374-
374+
375375 # ensure that the basename is unique
376376 base = splitext (txt .name )[0 ]
377377 if Document .objects .filter (name = base [:- 3 ]):
378378 raise forms .ValidationError , "This doucment filename already exists: %s" % base [:- 3 ]
379-
379+
380380 # ensure that rev is 00
381381 if base [- 2 :] != '00' :
382382 raise forms .ValidationError , "New Drafts must start with 00 revision number."
383-
383+
384384 return self .cleaned_data
385385
386386class WithdrawForm (forms .Form ):
0 commit comments