From 06522ee37247261914fb6a98c4cf7cfc7658e8bf Mon Sep 17 00:00:00 2001 From: Ethan Dalool Date: Mon, 1 May 2017 20:49:59 -0700 Subject: [PATCH] Minor cleanup --- etiquette/objects.py | 2 -- etiquette/photodb.py | 20 +++++++++++++------- templates/tags.html | 6 +++--- 3 files changed, 16 insertions(+), 12 deletions(-) diff --git a/etiquette/objects.py b/etiquette/objects.py index e7a16e5..3d7da4e 100644 --- a/etiquette/objects.py +++ b/etiquette/objects.py @@ -175,8 +175,6 @@ class GroupableMixin: ''' Leave the current group, then call `group.add(self)`. ''' - if isinstance(group, str): - group = self.photodb.get_tag(group) if not isinstance(group, type(self)): raise TypeError('Group must also be %s' % type(self)) diff --git a/etiquette/photodb.py b/etiquette/photodb.py index bb69299..26f40b4 100644 --- a/etiquette/photodb.py +++ b/etiquette/photodb.py @@ -263,13 +263,16 @@ class PDBAlbumMixin: Return the album with the `associated_directory` of this value, NOT case-sensitive. ''' - filepath = os.path.abspath(filepath) + filepath = pathclass.Path(filepath).absolute_path cur = self.sql.cursor() - cur.execute('SELECT * FROM album_associated_directories WHERE directory == ?', [filepath]) + cur.execute( + 'SELECT albumid FROM album_associated_directories WHERE directory == ?', + [filepath] + ) fetch = cur.fetchone() if fetch is None: raise exceptions.NoSuchAlbum(filepath) - album_id = fetch[constants.SQL_ALBUM_DIRECTORY['albumid']] + album_id = fetch[0] return self.get_album(album_id) def get_albums(self): @@ -336,7 +339,7 @@ class PDBAlbumMixin: query = 'INSERT INTO album_associated_directories VALUES(%s)' % qmarks cur.execute(query, bindings) - if photos: + if photos is not None: for photo in photos: photo = self.get_photo(photo) album.add_photo(photo, commit=False) @@ -666,7 +669,7 @@ class PDBPhotoMixin: _helper = lambda tagset: searchhelpers.normalize_tag_mmf( photodb=self, tags=tagset, - warning_bag=warning_bag + warning_bag=warning_bag, ) tag_musts = _helper(tag_musts) tag_mays = _helper(tag_mays) @@ -765,6 +768,8 @@ class PDBPhotoMixin: else: frozen_children = self.export_tags(tag_export_totally_flat) self._cached_frozen_children = frozen_children + else: + frozen_children = None if tag_expression: tag_expression_tree = searchhelpers.tag_expression_tree_builder( @@ -1230,14 +1235,15 @@ class PhotoDB(PDBAlbumMixin, PDBBookmarkMixin, PDBPhotoMixin, PDBTagMixin, PDBUs If a Photo object already exists for a file, it will be added to the correct album. ''' - if not os.path.isdir(directory): + directory = pathclass.Path(directory) + if not directory.is_dir: raise ValueError('Not a directory: %s' % directory) + if exclude_directories is None: exclude_directories = self.config['digest_exclude_dirs'] if exclude_filenames is None: exclude_filenames = self.config['digest_exclude_files'] - directory = spinal.str_to_fp(directory) directory.correct_case() generator = spinal.walk_generator( directory, diff --git a/templates/tags.html b/templates/tags.html index c7c55dd..93d152e 100644 --- a/templates/tags.html +++ b/templates/tags.html @@ -69,15 +69,15 @@ body