Simple code cleanups.

This commit is contained in:
Miguel Astor
2025-01-15 15:14:40 -04:00
parent bcefd5fdd1
commit 964fee5ddf
4 changed files with 11 additions and 13 deletions

View File

@@ -1,9 +1,5 @@
# Standard library imports.
from pathlib import Path
# External library imports. # External library imports.
import filetype import filetype
from PIL import Image
# Django imports. # Django imports.
from django.core.management.base import BaseCommand from django.core.management.base import BaseCommand
@@ -16,6 +12,7 @@ from viewer.utils import make_thumbnail
# Command subclass. # # Command subclass. #
########################################################################################### ###########################################################################################
class Command(BaseCommand): class Command(BaseCommand):
""" """
Assorted data fix and clean up commands for the Meters module. Assorted data fix and clean up commands for the Meters module.
@@ -40,5 +37,5 @@ class Command(BaseCommand):
try: try:
self._make_missing_thumbnails(settings.GALLERY_ROOT) self._make_missing_thumbnails(settings.GALLERY_ROOT)
except KeyboardInterrupt as e: except KeyboardInterrupt:
self.stderr.write(self.style.ERROR('\nInterrupted')) self.stderr.write(self.style.ERROR('\nInterrupted'))

View File

@@ -1,6 +1,5 @@
# Django imports # Django imports
from django.urls import path from django.urls import path
from django.contrib.auth.decorators import login_required
# Module imports # Module imports
from .views import ( from .views import (
@@ -11,6 +10,7 @@ from .views import (
# URL Patterns. # # URL Patterns. #
########################################################################################### ###########################################################################################
urlpatterns = [ urlpatterns = [
# Views. # Views.
path('', gallery_view, name = 'gallery_view_root'), path('', gallery_view, name = 'gallery_view_root'),

View File

@@ -17,6 +17,7 @@ THUMB_SIZE = (128, 128)
# Helper functions. # # Helper functions. #
########################################################################################### ###########################################################################################
def make_thumbnail(image): def make_thumbnail(image):
""" """
Creates a thumbnail in the corresponding THUMBNAILS_ROOT directory for the given image. Creates a thumbnail in the corresponding THUMBNAILS_ROOT directory for the given image.
@@ -34,5 +35,5 @@ def make_thumbnail(image):
with Image.open(str(image)) as pilimg: with Image.open(str(image)) as pilimg:
pilimg.thumbnail(THUMB_SIZE) pilimg.thumbnail(THUMB_SIZE)
pilimg.save(str(thumb_path)) pilimg.save(str(thumb_path))
except: except Exception:
pass pass

View File

@@ -10,9 +10,6 @@ from django.http import HttpResponseNotFound
from django.conf import settings from django.conf import settings
from django.utils.http import urlencode from django.utils.http import urlencode
from django.contrib.auth.decorators import login_required from django.contrib.auth.decorators import login_required
from django.contrib.auth import (authenticate,
login,
logout)
from django.shortcuts import (render, from django.shortcuts import (render,
redirect) redirect)
@@ -31,6 +28,7 @@ IMAGES_PER_PAGE = CELLS_PER_ROW * ROWS_PER_PAGE
# Helper functions. # # Helper functions. #
########################################################################################### ###########################################################################################
def do_recursive_search(start_path, query): def do_recursive_search(start_path, query):
""" """
Gets all images and sub-directories inside the start_path whose name matches the given query, Gets all images and sub-directories inside the start_path whose name matches the given query,
@@ -57,10 +55,12 @@ def do_recursive_search(start_path, query):
# View functions. # # View functions. #
########################################################################################### ###########################################################################################
@login_required @login_required
def index(request): def index(request):
return redirect('gallery_view_root') return redirect('gallery_view_root')
@login_required @login_required
def gallery_view(request, path = None): def gallery_view(request, path = None):
""" """
@@ -80,7 +80,7 @@ def gallery_view(request, path = None):
for c in range(cells): for c in range(cells):
try: try:
row.append(lst[i + c]) row.append(lst[i + c])
except: except Exception:
pass pass
rows.append(row) rows.append(row)
i += cells i += cells