Remove commit argument from ALL methods. @transaction does it.

master
voussoir 2020-02-19 23:56:09 -08:00
parent 0a984117c5
commit 1fc2ed09f5
2 changed files with 40 additions and 42 deletions

View File

@ -89,7 +89,7 @@ class GroupableMixin:
for parent in parents: for parent in parents:
parent.add_children(children) parent.add_children(children)
def add_child(self, member, *, commit=False): def add_child(self, member):
self.assert_same_type(member) self.assert_same_type(member)
if member == self: if member == self:
@ -112,7 +112,7 @@ class GroupableMixin:
self.photodb._cached_frozen_children = None self.photodb._cached_frozen_children = None
def add_children(self, members, *, commit=False): def add_children(self, members):
for member in members: for member in members:
self.add_child(member) self.add_child(member)
@ -122,7 +122,7 @@ class GroupableMixin:
if self.photodb != other.photodb: if self.photodb != other.photodb:
raise TypeError(f'Objects must belong to the same PhotoDB.') raise TypeError(f'Objects must belong to the same PhotoDB.')
def delete(self, *, delete_children=False, commit=False): def delete(self, *, delete_children=False):
''' '''
Delete this object's relationships to other groupables. Delete this object's relationships to other groupables.
Any unique / specific deletion methods should be written within the Any unique / specific deletion methods should be written within the
@ -184,7 +184,7 @@ class GroupableMixin:
row = self.photodb.sql_select_one(query, [self.id, member.id]) row = self.photodb.sql_select_one(query, [self.id, member.id])
return row is not None return row is not None
def remove_child(self, member, *, commit=False): def remove_child(self, member):
if not self.has_child(member): if not self.has_child(member):
return return
@ -283,7 +283,7 @@ class Album(ObjectBase, GroupableMixin):
@decorators.required_feature('album.edit') @decorators.required_feature('album.edit')
@decorators.transaction @decorators.transaction
def add_associated_directory(self, path, *, commit=False): def add_associated_directory(self, path):
''' '''
Add a directory from which this album will pull files during rescans. Add a directory from which this album will pull files during rescans.
These relationships are not unique and multiple albums These relationships are not unique and multiple albums
@ -308,7 +308,7 @@ class Album(ObjectBase, GroupableMixin):
@decorators.required_feature('album.edit') @decorators.required_feature('album.edit')
@decorators.transaction @decorators.transaction
def add_photo(self, photo, *, commit=False): def add_photo(self, photo):
if self.has_photo(photo): if self.has_photo(photo):
return return
@ -316,7 +316,7 @@ class Album(ObjectBase, GroupableMixin):
@decorators.required_feature('album.edit') @decorators.required_feature('album.edit')
@decorators.transaction @decorators.transaction
def add_photos(self, photos, *, commit=False): def add_photos(self, photos):
existing_photos = set(self.get_photos()) existing_photos = set(self.get_photos())
photos = set(photos) photos = set(photos)
photos = photos.difference(existing_photos) photos = photos.difference(existing_photos)
@ -326,7 +326,7 @@ class Album(ObjectBase, GroupableMixin):
# Photo.add_tag already has @required_feature # Photo.add_tag already has @required_feature
@decorators.transaction @decorators.transaction
def add_tag_to_all(self, tag, *, nested_children=True, commit=False): def add_tag_to_all(self, tag, *, nested_children=True):
''' '''
Add this tag to every photo in the album. Saves you from having to Add this tag to every photo in the album. Saves you from having to
write the for-loop yourself. write the for-loop yourself.
@ -346,7 +346,7 @@ class Album(ObjectBase, GroupableMixin):
@decorators.required_feature('album.edit') @decorators.required_feature('album.edit')
@decorators.transaction @decorators.transaction
def delete(self, *, delete_children=False, commit=False): def delete(self, *, delete_children=False):
self.photodb.log.debug('Deleting %s', self) self.photodb.log.debug('Deleting %s', self)
GroupableMixin.delete(self, delete_children=delete_children) GroupableMixin.delete(self, delete_children=delete_children)
self.photodb.sql_delete(table='album_associated_directories', pairs={'albumid': self.id}) self.photodb.sql_delete(table='album_associated_directories', pairs={'albumid': self.id})
@ -363,7 +363,7 @@ class Album(ObjectBase, GroupableMixin):
@decorators.required_feature('album.edit') @decorators.required_feature('album.edit')
@decorators.transaction @decorators.transaction
def edit(self, title=None, description=None, *, commit=False): def edit(self, title=None, description=None):
''' '''
Change the title or description. Leave None to keep current value. Change the title or description. Leave None to keep current value.
''' '''
@ -465,12 +465,12 @@ class Album(ObjectBase, GroupableMixin):
@decorators.required_feature('album.edit') @decorators.required_feature('album.edit')
@decorators.transaction @decorators.transaction
def remove_photo(self, photo, *, commit=False): def remove_photo(self, photo):
self._remove_photo(photo) self._remove_photo(photo)
@decorators.required_feature('album.edit') @decorators.required_feature('album.edit')
@decorators.transaction @decorators.transaction
def remove_photos(self, photos, *, commit=False): def remove_photos(self, photos):
existing_photos = set(self.get_photos()) existing_photos = set(self.get_photos())
photos = set(photos) photos = set(photos)
photos = photos.intersection(existing_photos) photos = photos.intersection(existing_photos)
@ -575,13 +575,13 @@ class Bookmark(ObjectBase):
@decorators.required_feature('bookmark.edit') @decorators.required_feature('bookmark.edit')
@decorators.transaction @decorators.transaction
def delete(self, *, commit=False): def delete(self):
self.photodb.sql_delete(table='bookmarks', pairs={'id': self.id}) self.photodb.sql_delete(table='bookmarks', pairs={'id': self.id})
self._uncache() self._uncache()
@decorators.required_feature('bookmark.edit') @decorators.required_feature('bookmark.edit')
@decorators.transaction @decorators.transaction
def edit(self, title=None, url=None, *, commit=False): def edit(self, title=None, url=None):
''' '''
Change the title or URL. Leave None to keep current. Change the title or URL. Leave None to keep current.
''' '''
@ -665,7 +665,7 @@ class Photo(ObjectBase):
@decorators.required_feature('photo.add_remove_tag') @decorators.required_feature('photo.add_remove_tag')
@decorators.transaction @decorators.transaction
def add_tag(self, tag, *, commit=False): def add_tag(self, tag):
tag = self.photodb.get_tag(name=tag) tag = self.photodb.get_tag(name=tag)
existing = self.has_tag(tag, check_children=False) existing = self.has_tag(tag, check_children=False)
@ -715,7 +715,7 @@ class Photo(ObjectBase):
# Photo.add_tag already has @required_feature add_remove_tag # Photo.add_tag already has @required_feature add_remove_tag
@decorators.transaction @decorators.transaction
def copy_tags(self, other_photo, *, commit=False): def copy_tags(self, other_photo):
''' '''
Take all of the tags owned by other_photo and apply them to this photo. Take all of the tags owned by other_photo and apply them to this photo.
''' '''
@ -724,7 +724,7 @@ class Photo(ObjectBase):
@decorators.required_feature('photo.edit') @decorators.required_feature('photo.edit')
@decorators.transaction @decorators.transaction
def delete(self, *, delete_file=False, commit=False): def delete(self, *, delete_file=False):
''' '''
Delete the Photo and its relation to any tags and albums. Delete the Photo and its relation to any tags and albums.
''' '''
@ -748,7 +748,7 @@ class Photo(ObjectBase):
#@decorators.time_me #@decorators.time_me
@decorators.required_feature('photo.generate_thumbnail') @decorators.required_feature('photo.generate_thumbnail')
@decorators.transaction @decorators.transaction
def generate_thumbnail(self, *, commit=False, **special): def generate_thumbnail(self, **special):
''' '''
special: special:
For videos, you can provide a `timestamp` to take the thumbnail at. For videos, you can provide a `timestamp` to take the thumbnail at.
@ -867,17 +867,17 @@ class Photo(ObjectBase):
# Photo.rename_file already has @required_feature # Photo.rename_file already has @required_feature
@decorators.transaction @decorators.transaction
def move_file(self, directory, commit=False): def move_file(self, directory):
directory = pathclass.Path(directory) directory = pathclass.Path(directory)
directory.assert_is_directory() directory.assert_is_directory()
new_path = directory.with_child(self.real_path.basename) new_path = directory.with_child(self.real_path.basename)
new_path.assert_not_exists() new_path.assert_not_exists()
self.rename_file(new_path.absolute_path, move=True, commit=commit) self.rename_file(new_path.absolute_path, move=True)
#@decorators.time_me #@decorators.time_me
@decorators.required_feature('photo.reload_metadata') @decorators.required_feature('photo.reload_metadata')
@decorators.transaction @decorators.transaction
def reload_metadata(self, *, commit=False): def reload_metadata(self):
''' '''
Load the file's height, width, etc as appropriate for this type of file. Load the file's height, width, etc as appropriate for this type of file.
''' '''
@ -937,7 +937,7 @@ class Photo(ObjectBase):
@decorators.required_feature('photo.edit') @decorators.required_feature('photo.edit')
@decorators.transaction @decorators.transaction
def relocate(self, new_filepath, *, allow_duplicates=False, commit=False): def relocate(self, new_filepath, *, allow_duplicates=False):
''' '''
Point the Photo object to a different filepath. Point the Photo object to a different filepath.
@ -965,7 +965,7 @@ class Photo(ObjectBase):
@decorators.required_feature('photo.add_remove_tag') @decorators.required_feature('photo.add_remove_tag')
@decorators.transaction @decorators.transaction
def remove_tag(self, tag, *, commit=False): def remove_tag(self, tag):
tag = self.photodb.get_tag(name=tag) tag = self.photodb.get_tag(name=tag)
self.photodb.log.debug('Removing %s from %s', tag, self) self.photodb.log.debug('Removing %s from %s', tag, self)
@ -983,7 +983,7 @@ class Photo(ObjectBase):
@decorators.required_feature('photo.edit') @decorators.required_feature('photo.edit')
@decorators.transaction @decorators.transaction
def rename_file(self, new_filename, *, move=False, commit=False): def rename_file(self, new_filename, *, move=False):
''' '''
Rename the file on the disk as well as in the database. Rename the file on the disk as well as in the database.
@ -1054,7 +1054,7 @@ class Photo(ObjectBase):
@decorators.required_feature('photo.edit') @decorators.required_feature('photo.edit')
@decorators.transaction @decorators.transaction
def set_searchhidden(self, searchhidden, *, commit=False): def set_searchhidden(self, searchhidden):
data = { data = {
'id': self.id, 'id': self.id,
'searchhidden': bool(searchhidden), 'searchhidden': bool(searchhidden),
@ -1065,7 +1065,7 @@ class Photo(ObjectBase):
@decorators.required_feature('photo.edit') @decorators.required_feature('photo.edit')
@decorators.transaction @decorators.transaction
def set_override_filename(self, new_filename, *, commit=False): def set_override_filename(self, new_filename):
if new_filename is not None: if new_filename is not None:
cleaned = helpers.remove_path_badchars(new_filename) cleaned = helpers.remove_path_badchars(new_filename)
cleaned = cleaned.strip() cleaned = cleaned.strip()
@ -1158,7 +1158,7 @@ class Tag(ObjectBase, GroupableMixin):
@decorators.required_feature('tag.edit') @decorators.required_feature('tag.edit')
@decorators.transaction @decorators.transaction
def add_synonym(self, synname, *, commit=False): def add_synonym(self, synname):
synname = self.photodb.normalize_tagname(synname) synname = self.photodb.normalize_tagname(synname)
if synname == self.name: if synname == self.name:
@ -1180,7 +1180,7 @@ class Tag(ObjectBase, GroupableMixin):
@decorators.required_feature('tag.edit') @decorators.required_feature('tag.edit')
@decorators.transaction @decorators.transaction
def convert_to_synonym(self, mastertag, *, commit=False): def convert_to_synonym(self, mastertag):
''' '''
Convert this tag into a synonym for a different tag. Convert this tag into a synonym for a different tag.
All photos which possess the current tag will have it replaced with the All photos which possess the current tag will have it replaced with the
@ -1243,7 +1243,7 @@ class Tag(ObjectBase, GroupableMixin):
@decorators.required_feature('tag.edit') @decorators.required_feature('tag.edit')
@decorators.transaction @decorators.transaction
def delete(self, *, delete_children=False, commit=False): def delete(self, *, delete_children=False):
self.photodb.log.debug('Deleting %s', self) self.photodb.log.debug('Deleting %s', self)
self.photodb._cached_frozen_children = None self.photodb._cached_frozen_children = None
GroupableMixin.delete(self, delete_children=delete_children) GroupableMixin.delete(self, delete_children=delete_children)
@ -1254,7 +1254,7 @@ class Tag(ObjectBase, GroupableMixin):
@decorators.required_feature('tag.edit') @decorators.required_feature('tag.edit')
@decorators.transaction @decorators.transaction
def edit(self, description=None, *, commit=False): def edit(self, description=None):
''' '''
Change the description. Leave None to keep current value. Change the description. Leave None to keep current value.
''' '''
@ -1286,7 +1286,7 @@ class Tag(ObjectBase, GroupableMixin):
@decorators.required_feature('tag.edit') @decorators.required_feature('tag.edit')
@decorators.transaction @decorators.transaction
def remove_synonym(self, synname, *, commit=False): def remove_synonym(self, synname):
''' '''
Delete a synonym. Delete a synonym.
This will have no effect on photos or other synonyms because This will have no effect on photos or other synonyms because
@ -1309,7 +1309,7 @@ class Tag(ObjectBase, GroupableMixin):
@decorators.required_feature('tag.edit') @decorators.required_feature('tag.edit')
@decorators.transaction @decorators.transaction
def rename(self, new_name, *, apply_to_synonyms=True, commit=False): def rename(self, new_name, *, apply_to_synonyms=True):
''' '''
Rename the tag. Does not affect its relation to Photos or tag groups. Rename the tag. Does not affect its relation to Photos or tag groups.
''' '''
@ -1393,7 +1393,7 @@ class User(ObjectBase):
@decorators.required_feature('user.edit') @decorators.required_feature('user.edit')
@decorators.transaction @decorators.transaction
def set_display_name(self, display_name, *, commit=False): def set_display_name(self, display_name):
display_name = self.normalize_display_name( display_name = self.normalize_display_name(
display_name, display_name,
max_length=self.photodb.config['user']['max_display_name_length'], max_length=self.photodb.config['user']['max_display_name_length'],

View File

@ -83,7 +83,6 @@ class PDBAlbumMixin:
*, *,
associated_directory=None, associated_directory=None,
author=None, author=None,
commit=False,
photos=None, photos=None,
): ):
''' '''
@ -134,7 +133,7 @@ class PDBBookmarkMixin:
@decorators.required_feature('bookmark.new') @decorators.required_feature('bookmark.new')
@decorators.transaction @decorators.transaction
def new_bookmark(self, url, title=None, *, author=None, commit=False): def new_bookmark(self, url, title=None, *, author=None):
# These might raise exceptions. # These might raise exceptions.
title = objects.Bookmark.normalize_title(title) title = objects.Bookmark.normalize_title(title)
url = objects.Bookmark.normalize_url(url) url = objects.Bookmark.normalize_url(url)
@ -213,7 +212,6 @@ class PDBPhotoMixin:
*, *,
allow_duplicates=False, allow_duplicates=False,
author=None, author=None,
commit=False,
do_metadata=True, do_metadata=True,
do_thumbnail=True, do_thumbnail=True,
searchhidden=False, searchhidden=False,
@ -277,7 +275,7 @@ class PDBPhotoMixin:
return photo return photo
@decorators.transaction @decorators.transaction
def purge_deleted_files(self, photos=None, *, commit=False): def purge_deleted_files(self, photos=None):
''' '''
Delete Photos whose corresponding file on disk is missing. Delete Photos whose corresponding file on disk is missing.
@ -294,7 +292,7 @@ class PDBPhotoMixin:
photo.delete() photo.delete()
@decorators.transaction @decorators.transaction
def purge_empty_albums(self, albums=None, *, commit=False): def purge_empty_albums(self, albums=None):
if albums is None: if albums is None:
to_check = set(self.get_albums()) to_check = set(self.get_albums())
else: else:
@ -914,7 +912,7 @@ class PDBTagMixin:
@decorators.required_feature('tag.new') @decorators.required_feature('tag.new')
@decorators.transaction @decorators.transaction
def new_tag(self, tagname, description=None, *, author=None, commit=False): def new_tag(self, tagname, description=None, *, author=None):
''' '''
Register a new tag and return the Tag object. Register a new tag and return the Tag object.
''' '''
@ -1074,7 +1072,7 @@ class PDBUserMixin:
@decorators.required_feature('user.new') @decorators.required_feature('user.new')
@decorators.transaction @decorators.transaction
def register_user(self, username, password, *, display_name=None, commit=False): def register_user(self, username, password, *, display_name=None):
# These might raise exceptions. # These might raise exceptions.
self.assert_valid_username(username) self.assert_valid_username(username)
@ -1122,7 +1120,6 @@ class PDBUtilMixin:
new_photo_kwargs={}, new_photo_kwargs={},
new_photo_ratelimit=None, new_photo_ratelimit=None,
recurse=True, recurse=True,
commit=False,
): ):
''' '''
Create an album, and add the directory's contents to it recursively. Create an album, and add the directory's contents to it recursively.
@ -1239,7 +1236,8 @@ class PDBUtilMixin:
else: else:
return None return None
def easybake(self, ebstring, author=None, *, commit=False): @decorators.transaction
def easybake(self, ebstring, author=None):
''' '''
Easily create tags, groups, and synonyms with a string like Easily create tags, groups, and synonyms with a string like
"group1.group2.tag+synonym" "group1.group2.tag+synonym"