Simple code cleanups.
This commit is contained in:
@@ -1,9 +1,5 @@
|
||||
# Standard library imports.
|
||||
from pathlib import Path
|
||||
|
||||
# External library imports.
|
||||
import filetype
|
||||
from PIL import Image
|
||||
|
||||
# Django imports.
|
||||
from django.core.management.base import BaseCommand
|
||||
@@ -16,6 +12,7 @@ from viewer.utils import make_thumbnail
|
||||
# Command subclass. #
|
||||
###########################################################################################
|
||||
|
||||
|
||||
class Command(BaseCommand):
|
||||
"""
|
||||
Assorted data fix and clean up commands for the Meters module.
|
||||
@@ -25,7 +22,7 @@ class Command(BaseCommand):
|
||||
"""
|
||||
Goes through the GALLERY_ROOT directory recursively and creates a new thumbnail
|
||||
for each image that does not have a corresponding file (same name) in the THUMBNAILS_ROOT
|
||||
directory.
|
||||
directory.
|
||||
"""
|
||||
|
||||
# Make a thumbnail for each file in the current directory.
|
||||
@@ -40,5 +37,5 @@ class Command(BaseCommand):
|
||||
try:
|
||||
self._make_missing_thumbnails(settings.GALLERY_ROOT)
|
||||
|
||||
except KeyboardInterrupt as e:
|
||||
except KeyboardInterrupt:
|
||||
self.stderr.write(self.style.ERROR('\nInterrupted'))
|
||||
|
@@ -1,6 +1,5 @@
|
||||
# Django imports
|
||||
from django.urls import path
|
||||
from django.contrib.auth.decorators import login_required
|
||||
from django.urls import path
|
||||
|
||||
# Module imports
|
||||
from .views import (
|
||||
@@ -11,6 +10,7 @@ from .views import (
|
||||
# URL Patterns. #
|
||||
###########################################################################################
|
||||
|
||||
|
||||
urlpatterns = [
|
||||
# Views.
|
||||
path('', gallery_view, name = 'gallery_view_root'),
|
||||
|
@@ -17,6 +17,7 @@ THUMB_SIZE = (128, 128)
|
||||
# Helper functions. #
|
||||
###########################################################################################
|
||||
|
||||
|
||||
def make_thumbnail(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:
|
||||
pilimg.thumbnail(THUMB_SIZE)
|
||||
pilimg.save(str(thumb_path))
|
||||
except:
|
||||
except Exception:
|
||||
pass
|
||||
|
@@ -10,9 +10,6 @@ from django.http import HttpResponseNotFound
|
||||
from django.conf import settings
|
||||
from django.utils.http import urlencode
|
||||
from django.contrib.auth.decorators import login_required
|
||||
from django.contrib.auth import (authenticate,
|
||||
login,
|
||||
logout)
|
||||
from django.shortcuts import (render,
|
||||
redirect)
|
||||
|
||||
@@ -31,6 +28,7 @@ IMAGES_PER_PAGE = CELLS_PER_ROW * ROWS_PER_PAGE
|
||||
# Helper functions. #
|
||||
###########################################################################################
|
||||
|
||||
|
||||
def do_recursive_search(start_path, 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. #
|
||||
###########################################################################################
|
||||
|
||||
|
||||
@login_required
|
||||
def index(request):
|
||||
return redirect('gallery_view_root')
|
||||
|
||||
|
||||
@login_required
|
||||
def gallery_view(request, path = None):
|
||||
"""
|
||||
@@ -80,7 +80,7 @@ def gallery_view(request, path = None):
|
||||
for c in range(cells):
|
||||
try:
|
||||
row.append(lst[i + c])
|
||||
except:
|
||||
except Exception:
|
||||
pass
|
||||
rows.append(row)
|
||||
i += cells
|
||||
|
Reference in New Issue
Block a user