55from django import forms
66from django .conf import settings
77from django .template .loader import render_to_string
8+ from django .utils .html import mark_safe
89
9- from ietf .idtracker .models import InternetDraft
10+ from ietf .idtracker .models import InternetDraft , IETFWG
1011from ietf .proceedings .models import Meeting
1112from ietf .submit .models import IdSubmissionDetail , TempIdAuthors
1213from ietf .submit .parsers .pdf_parser import PDFParser
@@ -32,16 +33,19 @@ class Media:
3233 css = {'all' : ("/css/liaisons.css" , )}
3334
3435 def __init__ (self , * args , ** kwargs ):
36+ self .request = kwargs .pop ('request' , None )
37+ self .remote_ip = self .request .META .get ('REMOTE_ADDR' , None )
3538 super (UploadForm , self ).__init__ (* args , ** kwargs )
3639 self .in_first_cut_off = False
3740 self .idnits_message = None
3841 self .shutdown = False
3942 self .draft = None
4043 self .filesize = None
44+ self .group = None
4145 self .read_dates ()
4246
4347 def read_dates (self ):
44- now = datetime .datetime .now ()
48+ now = datetime .datetime .utcnow ()
4549 first_cut_off = Meeting .get_first_cut_off ()
4650 second_cut_off = Meeting .get_second_cut_off ()
4751 ietf_monday = Meeting .get_ietf_monday ()
@@ -120,6 +124,51 @@ def clean_xml(self):
120124 def clean (self ):
121125 if self .shutdown :
122126 raise forms .ValidationError ('The tool is shut down' )
127+ self .check_paths ()
128+ if self .cleaned_data .get ('txt' , None ):
129+ self .get_draft ()
130+ self .group = self .get_working_group ()
131+ self .check_previous_submission ()
132+ self .check_tresholds ()
133+ return super (UploadForm , self ).clean ()
134+
135+ def check_tresholds (self ):
136+ filename = self .draft .filename
137+ revision = self .draft .revision
138+ remote_ip = self .remote_ip
139+ today = datetime .date .today ()
140+
141+ # Same draft by name
142+ same_name = IdSubmissionDetail .objects .filter (filename = filename , revision = revision , submission_date = today )
143+ if same_name .count () > settings .MAX_SAME_DRAFT_NAME :
144+ raise forms .ValidationError ('A same I-D cannot be submitted more than %s times a day' % settings .MAX_SAME_DRAFT_NAME )
145+ if sum ([i .filesize for i in same_name ]) > (settings .MAX_SAME_DRAFT_NAME_SIZE * 1048576 ):
146+ raise forms .ValidationError ('A same I-D submission cannot exceed more than %s MByte a day' % settings .MAX_SAME_DRAFT_NAME_SIZE )
147+
148+ # Total from same ip
149+ same_ip = IdSubmissionDetail .objects .filter (remote_ip = remote_ip , submission_date = today )
150+ if same_ip .count () > settings .MAX_SAME_SUBMITTER :
151+ raise forms .ValidationError ('The same submitter cannot submit more than %s I-Ds a day' % settings .MAX_SAME_SUBMITTER )
152+ if sum ([i .filesize for i in same_ip ]) > (settings .MAX_SAME_SUBMITTER_SIZE * 1048576 ):
153+ raise forms .ValidationError ('The same submitter cannot exceed more than %s MByte a day' % settings .MAX_SAME_SUBMITTER_SIZE )
154+
155+ # Total in same group
156+ if self .group :
157+ same_group = IdSubmissionDetail .objects .filter (group_acronym = self .group , submission_date = today )
158+ if same_group .count () > settings .MAX_SAME_WG_DRAFT :
159+ raise forms .ValidationError ('A same working group I-Ds cannot be submitted more than %s times a day' % settings .MAX_SAME_WG_DRAFT )
160+ if sum ([i .filesize for i in same_group ]) > (settings .MAX_SAME_WG_DRAFT_SIZE * 1048576 ):
161+ raise forms .ValidationError ('Total size of same working group I-Ds cannot exceed %s MByte a day' % settings .MAX_SAME_WG_DRAFT_SIZE )
162+
163+
164+ # Total drafts for today
165+ total_today = IdSubmissionDetail .objects .filter (submission_date = today )
166+ if total_today .count () > settings .MAX_DAILY_SUBMISSION :
167+ raise forms .ValidationError ('The total number of today\' s submission has reached the maximum number of submission per day' )
168+ if sum ([i .filesize for i in total_today ]) > (settings .MAX_DAILY_SUBMISSION_SIZE * 1048576 ):
169+ raise forms .ValidationError ('The total size of today\' s submission has reached the maximum size of submission per day' )
170+
171+ def check_paths (self ):
123172 self .staging_path = getattr (settings , 'STAGING_PATH' , None )
124173 self .idnits = getattr (settings , 'IDNITS_PATH' , None )
125174 if not self .staging_path :
@@ -130,18 +179,14 @@ def clean(self):
130179 raise forms .ValidationError ('IDNITS_PATH not defined on settings.py' )
131180 if not os .path .exists (self .idnits ):
132181 raise forms .ValidationError ('IDNITS_PATH defined on settings.py does not exist' )
133- if self .cleaned_data .get ('txt' , None ):
134- self .get_draft ()
135- self .check_previous_submission ()
136- return super (UploadForm , self ).clean ()
137182
138183 def check_previous_submission (self ):
139184 filename = self .draft .filename
140185 revision = self .draft .revision
141186 existing = IdSubmissionDetail .objects .filter (filename = filename , revision = revision ,
142187 status__pk__gte = 0 , status__pk__lt = 100 )
143188 if existing :
144- raise forms .ValidationError ('Duplicate Internet-Draft submission is currently in process. ' )
189+ raise forms .ValidationError ('Duplicate Internet-Draft submission is currently in process' )
145190
146191 def get_draft (self ):
147192 if self .draft :
@@ -170,6 +215,29 @@ def check_idnits(self):
170215 p = subprocess .Popen ([self .idnits , '--submitcheck' , '--nitcount' , filepath ], stdout = subprocess .PIPE )
171216 self .idnits_message = p .stdout .read ()
172217
218+ def get_working_group (self ):
219+ filename = self .draft .filename
220+ existing_draft = InternetDraft .objects .filter (filename = filename )
221+ if existing_draft :
222+ group = existing_draft [0 ].group and existing_draft [0 ].group .ietfwg or None
223+ if group and group .pk != 1027 :
224+ return group
225+ else :
226+ return None
227+ else :
228+ if filename .startswith ('draft-ietf-' ):
229+ # Extra check for WG that contains dashes
230+ for group in IETFWG .objects .filter (group_acronym__acronym__contains = '-' ):
231+ if filename .startswith ('draft-ietf-%s-' % group .group_acronym .acronym ):
232+ return group
233+ group_acronym = filename .split ('-' )[2 ]
234+ try :
235+ return IETFWG .objects .get (group_acronym__acronym = group_acronym )
236+ except IETFWG .DoesNotExist :
237+ raise forms .ValidationError ('There is no active group with acronym \' %s\' , please rename your draft' % group_acronym )
238+ else :
239+ return None
240+
173241 def save_draft_info (self , draft ):
174242 document_id = 0
175243 existing_draft = InternetDraft .objects .filter (filename = draft .filename )
@@ -185,6 +253,8 @@ def save_draft_info(self, draft):
185253 submission_date = datetime .date .today (),
186254 idnits_message = self .idnits_message ,
187255 temp_id_document_tag = document_id ,
256+ group_acronym = self .group ,
257+ remote_ip = self .remote_ip ,
188258 first_two_pages = '' .join (draft .pages [:2 ]),
189259 status_id = 1 , # Status 1 - upload
190260 )
0 commit comments