Example #1
0
 def __init__(self, path):
     self.path = path
     self.url_rel = path.replace("\\", "/")
     self.head = os.path.split(path)[0]
     self.filename = os.path.split(path)[1]
     self.filename_lower = self.filename.lower()  # important for sorting
     self.filetype = get_file_type(self.filename)
Example #2
0
 def __init__(self, path):
     self.path = path
     self.url_rel = path.replace("\\","/")
     self.head = os.path.split(path)[0]
     self.filename = os.path.split(path)[1]
     self.filename_lower = self.filename.lower() # important for sorting
     self.filetype = get_file_type(self.filename)
 def clean_file(self):
     if self.cleaned_data['file']:
         filename = convert_filename(self.cleaned_data['file'].name)
         
         # CHECK IF FILE EXISTS
         dir_list = os.listdir(self.path)
         if filename in dir_list:
             raise forms.ValidationError(_(u'File already exists.'))
             
         # TODO: CHECK IF VERSIONS_PATH EXISTS (IF USE_IMAGE_GENERATOR IS TRUE)
         
         # CHECK FILENAME
         if not alnum_name_re.search(filename):
             raise forms.ValidationError(_(u'Filename is not allowed.'))
             
         # CHECK EXTENSION / FILE_TYPE
         file_type = get_file_type(filename)
         if not file_type:
             raise forms.ValidationError(_(u'File extension is not allowed.'))
             
         # CHECK FILESIZE
         filesize = self.cleaned_data['file'].size
         if filesize > MAX_UPLOAD_SIZE:
             raise forms.ValidationError(_(u'Filesize exceeds allowed Upload Size.'))
     return self.cleaned_data['file']
 def clean_file(self):
     if self.cleaned_data['file']:
         filename = convert_filename(self.cleaned_data['file'].name)
         
         # CHECK IF FILE EXISTS
         dir_list = os.listdir(self.path)
         if filename in dir_list:
             raise forms.ValidationError(_(u'File already exists.'))
             
         # TODO: CHECK IF VERSIONS_PATH EXISTS (IF USE_IMAGE_GENERATOR IS TRUE)
         
         # CHECK FILENAME
         if not alnum_name_re.search(filename):
             raise forms.ValidationError(_(u'Filename is not allowed.'))
             
         # CHECK EXTENSION / FILE_TYPE
         file_type = get_file_type(filename)
         if not file_type:
             raise forms.ValidationError(_(u'File extension is not allowed.'))
             
         # CHECK FILESIZE
         filesize = self.cleaned_data['file'].size
         if filesize > MAX_UPLOAD_SIZE:
             raise forms.ValidationError(_(u'Filesize exceeds allowed Upload Size.'))
     return self.cleaned_data['file']
Example #5
0
 def _filetype(self):
     if self._filetype_stored != None:
         return self._filetype_stored
     if self.site.storage.isdir(self.path):
         self._filetype_stored = 'Folder'
     else:
         self._filetype_stored = get_file_type(self.filename)
     return self._filetype_stored
Example #6
0
 def _filetype(self):
     if self._filetype_stored != None:
         return self._filetype_stored
     if self.is_folder:
         self._filetype_stored = 'Folder'
     else:
         self._filetype_stored = get_file_type(self.filename)
     return self._filetype_stored
Example #7
0
 def _filetype(self):
     if self._filetype_stored != None:
         return self._filetype_stored
     if self.is_folder:
         self._filetype_stored = 'Folder'
     else:
         self._filetype_stored = get_file_type(self.filename)
     return self._filetype_stored
 def __init__(self, path, root_directory):
     self.path = force_unicode(path)
     self.root_directory = root_directory
     self.url_rel = path.replace("\\","/")
     self.head = os.path.split(path)[0]
     self.filename = os.path.split(path)[1]
     self.filename_lower = self.filename.lower() # important for sorting
     self.filetype = get_file_type(self.filename)
Example #9
0
 def _filetype(self):
     if self._filetype_stored != None:
         return self._filetype_stored
     if self.site.storage.isdir(self.path):
         self._filetype_stored = 'Folder'
     else:
         self._filetype_stored = get_file_type(self.filename)
     return self._filetype_stored
Example #10
0
 def __init__(self, path):
     '''
     `os.path.split` Split the pathname path into a pair, (head, tail) where tail is the last pathname component and head is everything leading up to that. The tail part will never contain a slash; if path ends in a slash, tail will be empty. If there is no slash in path, head will be empty. If path is empty, both head and tail are empty.
     '''
     self.path = path
     self.url_rel = path.replace("\\","/")
     self.head, self.filename = os.path.split(path)
     self.filename_lower = self.filename.lower() # important for sorting
     self.filetype = get_file_type(self.filename) # strange if file no extension then this folder
Example #11
0
File: base.py Project: TJBANEY/WFF
 def __init__(self, path):
     '''
     `os.path.split` Split the pathname path into a pair, (head, tail) where tail is the last pathname component and head is everything leading up to that. The tail part will never contain a slash; if path ends in a slash, tail will be empty. If there is no slash in path, head will be empty. If path is empty, both head and tail are empty.
     '''
     self.path = path
     self.url_rel = path.replace("\\", "/")
     self.head, self.filename = os.path.split(path)
     self.filename_lower = self.filename.lower()  # important for sorting
     self.filetype = get_file_type(
         self.filename)  # strange if file no extension then this folder
Example #12
0
 def __init__(self, path):
     self.path = path
     self.url_rel = path.replace("\\","/")
     self.head = os.path.split(path)[0]
     self.filename = os.path.split(path)[1]
     self.filename_lower = self.filename.lower() # important for sorting
     # ABP: fix for dotted folder names
     if os.path.isdir(self.path_full):
        self.filetype = 'Folder'
     else:
         self.filetype = get_file_type(self.filename)
Example #13
0
 def __init__(self, path):
     self.path = path
     self.url_rel = path.replace("\\", "/")
     self.head = os.path.split(path)[0]
     self.filename = os.path.split(path)[1]
     self.filename_lower = self.filename.lower()  # important for sorting
     # ABP: fix for dotted folder names
     if os.path.isdir(self.path_full):
         self.filetype = 'Folder'
     else:
         self.filetype = get_file_type(self.filename)
Example #14
0
 def __init__(self, path, relative=False):
     if relative:
         self.path = os.path.join(MEDIA_ROOT, path)
     else:
         self.path = path
     self.head = os.path.dirname(path)
     self.filename = os.path.basename(path)
     self.filename_lower = self.filename.lower()
     self.filename_root = os.path.splitext(self.filename)[0]
     self.extension = os.path.splitext(self.filename)[1]
     if os.path.isdir(self.path):
         self.filetype = 'Folder'
     else:
         self.filetype = get_file_type(self.filename)
     self.mimetype = mimetypes.guess_type(self.filename)