diff --git a/etiquette/constants.py b/etiquette/constants.py index 3a27508..23ea03a 100644 --- a/etiquette/constants.py +++ b/etiquette/constants.py @@ -129,7 +129,6 @@ CREATE INDEX IF NOT EXISTS index_tags_name on tags(name); CREATE INDEX IF NOT EXISTS index_tags_author_id on tags(author_id); ---------------------------------------------------------------------------------------------------- - ---------------------------------------------------------------------------------------------------- CREATE TABLE IF NOT EXISTS album_associated_directories( albumid TEXT NOT NULL, diff --git a/etiquette/decorators.py b/etiquette/decorators.py index 67de674..64ae398 100644 --- a/etiquette/decorators.py +++ b/etiquette/decorators.py @@ -4,7 +4,6 @@ import warnings from . import exceptions - def _get_relevant_photodb(instance): from . import objects if isinstance(instance, objects.ObjectBase): diff --git a/etiquette/exceptions.py b/etiquette/exceptions.py index d83c1dd..dbe28e2 100644 --- a/etiquette/exceptions.py +++ b/etiquette/exceptions.py @@ -44,8 +44,8 @@ class EtiquetteException(Exception, metaclass=ErrorTypeAdder): def __str__(self): return self.error_type + '\n' + self.error_message +# NO SUCH ########################################################################################## -# NO SUCH class NoSuch(EtiquetteException): pass @@ -70,8 +70,8 @@ class NoSuchTag(NoSuch): class NoSuchUser(NoSuch): error_message = 'User "{}" does not exist.' +# EXISTS ########################################################################################### -# EXISTS class Exists(EtiquetteException): pass @@ -106,8 +106,8 @@ class UserExists(Exists): self.user = user EtiquetteException.__init__(self, user) +# TAG ERRORS ####################################################################################### -# TAG ERRORS class CantGroupSelf(EtiquetteException): error_message = 'Cannot group {} into itself.' @@ -126,8 +126,8 @@ class TagTooLong(EtiquetteException): class TagTooShort(EtiquetteException): error_message = 'Tag "{}" has too few valid characters.' +# USER ERRORS ###################################################################################### -# USER ERRORS class AlreadySignedIn(EtiquetteException): error_message = 'You\'re already signed in.' @@ -155,16 +155,16 @@ class DisplayNameTooLong(EtiquetteException): class WrongLogin(EtiquetteException): error_message = 'Wrong username-password combination.' +# SQL ERRORS ####################################################################################### -# SQL ERRORS class BadSQL(EtiquetteException): pass class BadTable(BadSQL): error_message = 'Table "{}" does not exist.' +# GENERAL ERRORS ################################################################################### -# GENERAL ERRORS class BadDataDirectory(EtiquetteException): ''' Raised by PhotoDB __init__ if the requested data_directory is invalid. diff --git a/etiquette/objects.py b/etiquette/objects.py index a0c7ac5..62998ee 100644 --- a/etiquette/objects.py +++ b/etiquette/objects.py @@ -19,7 +19,6 @@ from . import decorators from . import exceptions from . import helpers - BAIL = sentinel.Sentinel('BAIL') def normalize_db_row(db_row, table): @@ -27,7 +26,6 @@ def normalize_db_row(db_row, table): db_row = dict(zip(constants.SQL_COLUMNS[table], db_row)) return db_row - class ObjectBase: def __init__(self, photodb): super().__init__() @@ -71,7 +69,6 @@ class ObjectBase: return None return self.photodb.get_user(id=self.author_id) - class GroupableMixin: group_getter = None group_getter_many = None @@ -227,7 +224,6 @@ class GroupableMixin: more_parents = more_parents.difference(seen) todo.extend(more_parents) - class Album(ObjectBase, GroupableMixin): table = 'albums' group_table = 'album_group_rel' @@ -546,7 +542,6 @@ class Album(ObjectBase, GroupableMixin): for child in children: yield from child.walk_photos() - class Bookmark(ObjectBase): table = 'bookmarks' @@ -1168,7 +1163,6 @@ class Photo(ObjectBase): self.photodb.sql_update(table='photos', pairs=data, where_key='id') self.searchhidden = searchhidden - class Tag(ObjectBase, GroupableMixin): ''' A Tag, which can be applied to Photos for organization. @@ -1465,7 +1459,6 @@ class Tag(ObjectBase, GroupableMixin): self.name = new_name self._uncache() - class User(ObjectBase): ''' A dear friend of ours. @@ -1529,7 +1522,6 @@ class User(ObjectBase): self.photodb.sql_update(table='users', pairs=data, where_key='id') self._display_name = display_name - class WarningBag: def __init__(self): self.warnings = set() diff --git a/etiquette/photodb.py b/etiquette/photodb.py index f9109e7..ffe43fd 100644 --- a/etiquette/photodb.py +++ b/etiquette/photodb.py @@ -24,10 +24,7 @@ from . import objects from . import searchhelpers from . import tag_export - #################################################################################################### -#################################################################################################### - class PDBAlbumMixin: def __init__(self): @@ -143,6 +140,7 @@ class PDBAlbumMixin: to_check.update(album.get_parents()) album.delete() +#################################################################################################### class PDBBookmarkMixin: def __init__(self): @@ -185,6 +183,7 @@ class PDBBookmarkMixin: return bookmark +#################################################################################################### class PDBCacheManagerMixin: _THING_CLASSES = { @@ -380,6 +379,7 @@ class PDBCacheManagerMixin: thing_cache[thing.id] = thing yield thing +#################################################################################################### class PDBPhotoMixin: def __init__(self): @@ -896,6 +896,7 @@ class PDBPhotoMixin: end_time = time.time() print('Search took:', end_time - start_time) +#################################################################################################### class PDBSQLMixin: def __init__(self): @@ -1050,6 +1051,7 @@ class PDBSQLMixin: query = f'UPDATE {table} {qmarks}' self.sql_execute(query, bindings) +#################################################################################################### class PDBTagMixin: def __init__(self): @@ -1196,6 +1198,7 @@ class PDBTagMixin: ) return tagname +#################################################################################################### class PDBUserMixin: def __init__(self): @@ -1359,6 +1362,7 @@ class PDBUserMixin: return self.get_cached_instance('user', data) +#################################################################################################### class PDBUtilMixin: def __init__(self): @@ -1625,6 +1629,7 @@ class PDBUtilMixin: return output_notes +#################################################################################################### class PhotoDB( PDBAlbumMixin, @@ -1820,7 +1825,6 @@ class PhotoDB( with open(self.config_filepath.absolute_path, 'w', encoding='utf-8') as handle: handle.write(json.dumps(self.config, indent=4, sort_keys=True)) - if __name__ == '__main__': p = PhotoDB() print(p) diff --git a/etiquette/searchhelpers.py b/etiquette/searchhelpers.py index e1b79cc..5e4bce1 100644 --- a/etiquette/searchhelpers.py +++ b/etiquette/searchhelpers.py @@ -11,7 +11,6 @@ from . import objects from voussoirkit import expressionmatch from voussoirkit import sqlhelpers - def expand_mmf(tag_musts, tag_mays, tag_forbids): ''' In order to generate SQL queries for `tagid IN (options)`, we need to diff --git a/frontends/etiquette_flask/backend/caching.py b/frontends/etiquette_flask/backend/caching.py index fa66a54..acb032d 100644 --- a/frontends/etiquette_flask/backend/caching.py +++ b/frontends/etiquette_flask/backend/caching.py @@ -6,7 +6,6 @@ from voussoirkit import cacheclass import etiquette - def cached_endpoint(max_age): ''' The cached_endpoint decorator can be used on slow endpoints that don't need @@ -63,7 +62,6 @@ def cached_endpoint(max_age): return wrapped return wrapper - class FileCacheManager: ''' The FileCacheManager serves ETag and Cache-Control headers for disk files. @@ -116,7 +114,6 @@ class FileCacheManager: return server_value.get_headers() - class CacheFile: def __init__(self, filepath, max_age): self.filepath = filepath diff --git a/frontends/etiquette_flask/backend/common.py b/frontends/etiquette_flask/backend/common.py index 607f3dc..076edf6 100644 --- a/frontends/etiquette_flask/backend/common.py +++ b/frontends/etiquette_flask/backend/common.py @@ -15,6 +15,8 @@ from . import jinja_filters from . import jsonify from . import sessions +# Runtime init ##################################################################################### + root_dir = pathclass.Path(__file__).parent.parent TEMPLATE_DIR = root_dir.with_child('templates') @@ -46,6 +48,8 @@ file_cache_manager = caching.FileCacheManager( max_age=BROWSER_CACHE_DURATION, ) +# Response wrappers ################################################################################ + # Flask provides decorators for before_request and after_request, but not for # wrapping the whole request. The decorators I am using need to wrap the whole # request, either to catch exceptions (which don't get passed through @@ -98,6 +102,8 @@ def after_request(response): return response +# P functions ###################################################################################### + def P_wrapper(function): def P_wrapped(thingid, response_type): if response_type not in {'html', 'json'}: @@ -160,6 +166,11 @@ def P_user(username): def P_user_id(user_id): return P.get_user(id=user_id) +# Other functions ################################################################################## + +def back_url(): + return request.args.get('goto') or request.referrer or '/' + def render_template(request, template_name, **kwargs): session = session_manager.get(request) @@ -186,9 +197,6 @@ def render_template(request, template_name, **kwargs): return response -def back_url(): - return request.args.get('goto') or request.referrer or '/' - def send_file(filepath, override_mimetype=None): ''' Range-enabled file sending. diff --git a/frontends/etiquette_flask/backend/decorators.py b/frontends/etiquette_flask/backend/decorators.py index 53902fa..41be014 100644 --- a/frontends/etiquette_flask/backend/decorators.py +++ b/frontends/etiquette_flask/backend/decorators.py @@ -6,7 +6,6 @@ import etiquette from . import jsonify - def catch_etiquette_exception(function): ''' If an EtiquetteException is raised, automatically catch it and convert it diff --git a/frontends/etiquette_flask/backend/endpoints/album_endpoints.py b/frontends/etiquette_flask/backend/endpoints/album_endpoints.py index 56d899e..010f23e 100644 --- a/frontends/etiquette_flask/backend/endpoints/album_endpoints.py +++ b/frontends/etiquette_flask/backend/endpoints/album_endpoints.py @@ -10,7 +10,6 @@ from .. import jsonify site = common.site session_manager = common.session_manager - # Individual albums ################################################################################ @site.route('/album/') diff --git a/frontends/etiquette_flask/backend/endpoints/basic_endpoints.py b/frontends/etiquette_flask/backend/endpoints/basic_endpoints.py index 8543cee..3e1c13c 100644 --- a/frontends/etiquette_flask/backend/endpoints/basic_endpoints.py +++ b/frontends/etiquette_flask/backend/endpoints/basic_endpoints.py @@ -6,7 +6,6 @@ from .. import common site = common.site session_manager = common.session_manager - #################################################################################################### @site.route('/') diff --git a/frontends/etiquette_flask/backend/endpoints/bookmark_endpoints.py b/frontends/etiquette_flask/backend/endpoints/bookmark_endpoints.py index afcc3e3..f6d6b82 100644 --- a/frontends/etiquette_flask/backend/endpoints/bookmark_endpoints.py +++ b/frontends/etiquette_flask/backend/endpoints/bookmark_endpoints.py @@ -9,7 +9,6 @@ from .. import jsonify site = common.site session_manager = common.session_manager - # Individual bookmarks ############################################################################# @site.route('/bookmark/.json') diff --git a/frontends/etiquette_flask/backend/endpoints/photo_endpoints.py b/frontends/etiquette_flask/backend/endpoints/photo_endpoints.py index b319376..f154432 100644 --- a/frontends/etiquette_flask/backend/endpoints/photo_endpoints.py +++ b/frontends/etiquette_flask/backend/endpoints/photo_endpoints.py @@ -15,7 +15,6 @@ site = common.site session_manager = common.session_manager photo_download_zip_tokens = cacheclass.Cache(maxlen=100) - # Individual photos ################################################################################ @site.route('/photo/') diff --git a/frontends/etiquette_flask/backend/endpoints/tag_endpoints.py b/frontends/etiquette_flask/backend/endpoints/tag_endpoints.py index 2b02704..3129981 100644 --- a/frontends/etiquette_flask/backend/endpoints/tag_endpoints.py +++ b/frontends/etiquette_flask/backend/endpoints/tag_endpoints.py @@ -10,7 +10,6 @@ from .. import jsonify site = common.site session_manager = common.session_manager - # Individual tags ################################################################################## @site.route('/tags/') diff --git a/frontends/etiquette_flask/backend/endpoints/user_endpoints.py b/frontends/etiquette_flask/backend/endpoints/user_endpoints.py index 721e890..d8a8c3d 100644 --- a/frontends/etiquette_flask/backend/endpoints/user_endpoints.py +++ b/frontends/etiquette_flask/backend/endpoints/user_endpoints.py @@ -10,7 +10,6 @@ from .. import sessions site = common.site session_manager = common.session_manager - # Individual users ################################################################################# @site.route('/user/') diff --git a/frontends/etiquette_flask/backend/jinja_filters.py b/frontends/etiquette_flask/backend/jinja_filters.py index f0118e8..ce91191 100644 --- a/frontends/etiquette_flask/backend/jinja_filters.py +++ b/frontends/etiquette_flask/backend/jinja_filters.py @@ -21,6 +21,8 @@ def register_all(site): for function in global_functions: site.jinja_env.globals[function.__name__] = function +#################################################################################################### + @filter_function def bytestring(x): try: @@ -41,14 +43,6 @@ def file_link(photo, short=False): basename = jinja2.filters.do_urlencode(photo.basename) return f'/file/{photo.id}/{basename}' -@global_function -def make_attributes(*booleans, **keyvalues): - keyvalues = {key: value for (key, value) in keyvalues.items() if value is not None} - attributes = [f'{key}="{jinja2.filters.escape(value)}"' for (key, value) in keyvalues.items()] - attributes.extend(booleans) - attributes = ' '.join(attributes) - return attributes - @filter_function def sort_tags(tags): tags = sorted(tags, key=lambda x: x.name) @@ -72,3 +66,13 @@ def users_to_usernames(users): if not users: return [] return [user.username for user in users] + +#################################################################################################### + +@global_function +def make_attributes(*booleans, **keyvalues): + keyvalues = {key: value for (key, value) in keyvalues.items() if value is not None} + attributes = [f'{key}="{jinja2.filters.escape(value)}"' for (key, value) in keyvalues.items()] + attributes.extend(booleans) + attributes = ' '.join(attributes) + return attributes diff --git a/frontends/etiquette_flask/backend/jsonify.py b/frontends/etiquette_flask/backend/jsonify.py index 5999d17..6faaaf9 100644 --- a/frontends/etiquette_flask/backend/jsonify.py +++ b/frontends/etiquette_flask/backend/jsonify.py @@ -1,7 +1,6 @@ import flask import json - def make_json_response(j, *args, **kwargs): dumped = json.dumps(j) response = flask.Response(dumped, *args, **kwargs) diff --git a/frontends/etiquette_flask/backend/sessions.py b/frontends/etiquette_flask/backend/sessions.py index 60f90c1..953311a 100644 --- a/frontends/etiquette_flask/backend/sessions.py +++ b/frontends/etiquette_flask/backend/sessions.py @@ -7,7 +7,6 @@ from voussoirkit import cacheclass import etiquette - SESSION_MAX_AGE = 86400 REQUEST_TYPES = (flask.Request, werkzeug.wrappers.Request, werkzeug.local.LocalProxy) RESPONSE_TYPES = (flask.Response, werkzeug.wrappers.Response) @@ -31,7 +30,6 @@ def _normalize_token(token): raise TypeError('Unsupported token normalization', type(token)) return token - class SessionManager: def __init__(self, maxlen=None): self.sessions = cacheclass.Cache(maxlen=maxlen) @@ -106,7 +104,6 @@ class SessionManager: except KeyError: pass - class Session: def __init__(self, request, user): self.token = _normalize_token(request) diff --git a/frontends/etiquette_flask/templates/album.html b/frontends/etiquette_flask/templates/album.html index 9dd1a7a..a6fb535 100644 --- a/frontends/etiquette_flask/templates/album.html +++ b/frontends/etiquette_flask/templates/album.html @@ -90,7 +90,6 @@ h2, h3 {{shared_css()}} - {{header.make_header(session=session)}}
@@ -121,7 +120,6 @@ h2, h3
- @@ -151,7 +149,6 @@ const ALBUM_ID = undefined; {{shared_css()}} - {{header.make_header(session=session)}}
@@ -289,7 +286,6 @@ const ALBUM_ID = undefined;
- diff --git a/frontends/etiquette_flask/templates/search.html b/frontends/etiquette_flask/templates/search.html index 76e29da..3b149ca 100644 --- a/frontends/etiquette_flask/templates/search.html +++ b/frontends/etiquette_flask/templates/search.html @@ -175,7 +175,6 @@ {% endmacro %} - {{header.make_header(session=session)}}
@@ -363,7 +362,6 @@ {{clipboard_tray.clipboard_tray()}} - diff --git a/frontends/etiquette_flask/templates/user.html b/frontends/etiquette_flask/templates/user.html index 6687e45..d68f9b6 100644 --- a/frontends/etiquette_flask/templates/user.html +++ b/frontends/etiquette_flask/templates/user.html @@ -20,7 +20,6 @@ - {{header.make_header(session=session)}}
@@ -31,7 +30,6 @@
- diff --git a/frontends/etiquette_repl/etiquette_repl_launch.py b/frontends/etiquette_repl/etiquette_repl_launch.py index 3604bd9..c1a854f 100644 --- a/frontends/etiquette_repl/etiquette_repl_launch.py +++ b/frontends/etiquette_repl/etiquette_repl_launch.py @@ -36,6 +36,7 @@ def photag(photo_id): get = P.get_tag ################################################################################ + def erepl_argparse(args): if args.exec_statement: exec(args.exec_statement) diff --git a/utilities/database_upgrader/database_upgrader.py b/utilities/database_upgrader/database_upgrader.py index 105b8cc..91a6193 100644 --- a/utilities/database_upgrader/database_upgrader.py +++ b/utilities/database_upgrader/database_upgrader.py @@ -359,7 +359,6 @@ def upgrade_all(data_directory): current_version = version_number print('Upgrades finished.') - def upgrade_all_argparse(args): return upgrade_all(data_directory=args.data_directory) diff --git a/utilities/database_upgrader/old_inits.py b/utilities/database_upgrader/old_inits.py index c5bf7a0..d6e150d 100644 --- a/utilities/database_upgrader/old_inits.py +++ b/utilities/database_upgrader/old_inits.py @@ -73,7 +73,6 @@ CREATE INDEX IF NOT EXISTS index_tags_name on tags(name); CREATE INDEX IF NOT EXISTS index_tags_author_id on tags(author_id); ---------------------------------------------------------------------------------------------------- - ---------------------------------------------------------------------------------------------------- CREATE TABLE IF NOT EXISTS album_associated_directories( albumid TEXT NOT NULL,