11# -*- coding: utf-8 -*-
2+ from datetime import datetime
3+ from datetime import timedelta
24from imio .esign import _
35from imio .esign import ESIGN_CREDENTIALS
46from imio .esign import ESIGN_ROOT_URL
@@ -232,6 +234,7 @@ class DownloadFileView(BrowserView):
232234
233235 shortuid_separator = "-"
234236 named_blob_file_attribute = "file"
237+ download_time_delta = timedelta (days = 120 )
235238
236239 def __init__ (self , context , request ):
237240 super (DownloadFileView , self ).__init__ (context , request )
@@ -250,7 +253,7 @@ def publishTraverse(self, request, name):
250253 return self
251254
252255 def __call__ (self ):
253- """Handle the file download request and return an html response."""
256+ """Handle the file download request and return a html response."""
254257 if self .file_id is None :
255258 message = translate (_ ("A file identifier must be passed in the url !" ), context = self .request )
256259 return self .html_message (message )
@@ -264,7 +267,20 @@ def __call__(self):
264267 mapping = {"uid" : safe_encode (self .file_id )}),
265268 context = self .request )
266269 return self .html_message (message )
267- # TODO Added a date verification
270+ # Verify date - check if file is not too old
271+ if self .download_time_delta is not None :
272+ modification_date = file_obj .modified ()
273+ if hasattr (modification_date , 'asdatetime' ):
274+ modification_date = modification_date .asdatetime ()
275+ modification_date = modification_date .date ()
276+ if datetime .now ().date () - modification_date > self .download_time_delta :
277+ message = translate (
278+ _ ("The download period for this file has expired (was ${valid_date}) !" ,
279+ mapping = {"valid_date" : datetime .strftime (modification_date + self .download_time_delta ,
280+ "%Y-%m-%d" )}),
281+ context = self .request )
282+ return self .html_message (message )
283+ # Get file content
268284 nbf = getattr (file_obj , self .named_blob_file_attribute , None )
269285 if nbf is None :
270286 message = translate (_ ("The corresponding file content cannot be retrieved (${uid}) !" ,
0 commit comments