Example #1
0
 def get_cover(self):
     config = self.config()
     # get from config
     if 'cover' in config:
         return Photo(self._root_folder, self._path, config['cover'])
     # get default
     picture_names = self.get_all_pictures_name()
     if picture_names is None or len(picture_names) == 0:
         return None
     cover = Photo(self._root_folder, self._path, picture_names[0])
     return cover
Example #2
0
    def test_create_photo(self):
        root_folder = getattr(settings, 'PHOTOS_ROOT_DIR', '/')
        photo = Photo(root_folder, "album2", 'photo_first.JPG')

        self.assertEquals(photo.filename, 'photo_first.JPG')

        photo.load_name()
        self.assertEquals(photo.name, 'photo first')

        self.assertTrue(photo.exists())

        self.assertEquals(photo.relative_url(), 'album2/photo_first.JPG')
Example #3
0
 def get_object(self):
     photo_path = self.kwargs['photo']
     photo = None
     if photo_path:
         parts = photo_path.split('/')
         if len(parts) == 1:
             album = ''
             filename = parts[0]
         else:
             album = '/'.join(parts[:-1])
             filename = parts[-1]
         photo = Photo(self.get_photo_base(), album, filename)
     if not photo or not photo.exists():
         raise Http404
     return photo
Example #4
0
 def get_object(self):
     photo_path = self.kwargs['photo']
     photo = None
     if photo_path:
         parts = photo_path.split('/')
         if len(parts) == 1:
             album = ''
             filename = parts[0]
         else:
             album = '/'.join(parts[:-1])
             filename = parts[-1]
         photo = Photo(self.get_photo_base(), album, filename)
     if not photo or not photo.exists():
         raise Http404
     return photo
Example #5
0
 def get_pictures(self):
     pictures_name = self.get_all_pictures_name()
     pictures = [
         Photo(self._root_folder, self._path, f) for f in pictures_name
     ]
     #         pictures = self._sort_by_date(pictures)
     pictures = self._sort_by_name(pictures)
     return pictures
Example #6
0
    def test_cache_folder(self):
        root_folder = getattr(settings, 'PHOTOS_ROOT_DIR', '/')
        album_name = "album2"
        photo_name = 'photo_1_portrait.JPG'
        photo = Photo(root_folder, album_name, photo_name)
        cache = PhotoCache(photo)
        cache_file = cache.get_file()

        self.assertTrue(cache_file.find(album_name) >= 0)
Example #7
0
    def test_create_cache_and_check_if_exists(self):
        root_folder = getattr(settings, 'PHOTOS_ROOT_DIR', '/')
        photo = Photo(root_folder, "album2", 'photo_first.JPG')
        cache = PhotoCache(photo)

        self._remove_cache(cache.get_filename())

        self.assertFalse(cache.is_in_cache())
        cache.create_cache()
        self.assertTrue(cache.is_in_cache())
Example #8
0
    def test_load_rotated_image(self):
        root_folder = getattr(settings, 'PHOTOS_ROOT_DIR', '/')
        photo = Photo(root_folder, "album2", 'photo_1_portrait.JPG')
        img = Image.open(photo.real_filename)
        self.assertTrue(img.size[0] > img.size[1])

        cache = PhotoCache(photo)

        self._remove_cache(cache.get_filename())
        self.assertFalse(cache.is_in_cache())

        cache.rotate_based_on_orientation()
        cache_file = cache.get_file()

        img = Image.open(cache_file)
        self.assertTrue(img.size[0] < img.size[1])
Example #9
0
    def test_load_from_cache(self):
        root_folder = getattr(settings, 'PHOTOS_ROOT_DIR', '/')
        photo = Photo(root_folder, "album2", 'photo_first.JPG')
        cache = PhotoCache(photo)

        self._remove_cache(cache.get_filename())
        self.assertFalse(cache.is_in_cache())
        cache.create_cache()
        self.assertTrue(cache.is_in_cache())

        cache_file = cache.get_file()
        assert cache_file

        BASE_CACHE_DIR = getattr(settings, 'BASE_CACHE_DIR', '/')
        photos_cache_dir = os.path.join(BASE_CACHE_DIR, "photo")
        self.assertTrue(cache_file.startswith(photos_cache_dir))
Example #10
0
    def test_load_resized_image(self):
        root_folder = getattr(settings, 'PHOTOS_ROOT_DIR', '/')
        photo = Photo(root_folder, "album2", 'photo_first.JPG')
        img = Image.open(photo.real_filename)
        self.assertEquals(img.size[0], 3008)

        cache = PhotoCache(photo)

        self._remove_cache(cache.get_filename())
        self.assertFalse(cache.is_in_cache())

        cache.set_max_dimension(800)
        cache_file = cache.get_file()

        img = Image.open(cache_file)
        size = img.size
        self.assertEquals(size[0], 800)
Example #11
0
    def test_create_photo(self):
        root_folder = getattr(settings, 'PHOTOS_ROOT_DIR', '/')
        photo = Photo(root_folder, "album2", 'photo_first.JPG')

        self.assertEquals(photo.filename, 'photo_first.JPG')

        photo.load_name()
        self.assertEquals(photo.name, 'photo first')

        self.assertTrue(photo.exists())

        self.assertEquals(photo.relative_url(), 'album2/photo_first.JPG')