Exemple #1
0
 def extension(self):
     if self.__extension is None:
         match = url_pattern.match(self.__name)
         if match is not None:
             self.__extension = match.groupdict()['extension']
         else:
             raise ResourceNameError()
     return self.__extension
Exemple #2
0
 def code(self):
     if self.__code is None:
         match = code_pattern.match(self.__name)
         if match is not None:
             self.__code = match.groupdict()['code']
         else:
             raise ResourceNameError()
     return self.__code
Exemple #3
0
 def size(self):
     if self.__size is None:
         match = url_pattern.match(self.__name)
         if match is not None:
             self.__size = match.groupdict()['size']
         else:
             raise ResourceNameError()
         # At this moment self.__size is a str object, (Ex. "100x100")
         # we need something like (100, 100)
         self.__size = [int(elem) for elem in self.__size.split('x')]
     return self.__size
Exemple #4
0
    def __compute_url(self, access_level=PRIVATE):
        match = url_pattern.match(self.__name)
        if match is not None:

            BASE_URL = django_s3_settings.S3_AWS_BASE_URL \
                if access_level == Resource.PRIVATE else django_s3_settings.S3_AWS_BASE_PUBLIC_URL
            BASE_URL = BASE_URL[:-1] if BASE_URL.endswith('/') else BASE_URL

            folder = settings.S3_CATEGORY_MAP[self.category_code]

            return "{}/{}/{}/{}/{}".format(BASE_URL,
                                           django_s3_settings.S3_BUCKET_NAME,
                                           folder, self.folder_name, self.name)
        else:
            raise ResourceNameError()
Exemple #5
0
    def __compute_url(self):
        match = url_pattern.match(self.__name)
        if match is not None:

            BASE_URL = django_s3_settings.S3_AWS_BASE_URL
            BASE_URL = BASE_URL[:-1] if BASE_URL.endswith('/') else BASE_URL

            folder = settings.S3_CATEGORY_MAP[self.category_code]

            return "{}/{}/{}/{}/{}".format(BASE_URL,
                                           django_s3_settings.S3_BUCKET_NAME,
                                           folder,
                                           match.groupdict()['folder_name'],
                                           self.__name)
        else:
            raise ResourceNameError()