flake8 formating

This commit is contained in:
loulous27 2025-11-28 20:59:42 +01:00
parent 4f877dd2f2
commit 1492c803a8
5 changed files with 18 additions and 20 deletions

View file

@ -91,7 +91,7 @@ MIDDLEWARE = [
"django.contrib.sites.middleware.CurrentSiteMiddleware", "django.contrib.sites.middleware.CurrentSiteMiddleware",
"allauth.account.middleware.AccountMiddleware", # For the django =< 5.0 "allauth.account.middleware.AccountMiddleware", # For the django =< 5.0
] ]
if DEBUG : if DEBUG:
MIDDLEWARE += ["debug_toolbar.middleware.DebugToolbarMiddleware",] MIDDLEWARE += ["debug_toolbar.middleware.DebugToolbarMiddleware",]
ROOT_URLCONF = "photo21.urls" ROOT_URLCONF = "photo21.urls"

View file

@ -14,7 +14,7 @@ from django.contrib import admin
from django.urls import include, path, re_path from django.urls import include, path, re_path
from django.views.i18n import JavaScriptCatalog from django.views.i18n import JavaScriptCatalog
if settings.DEBUG : if settings.DEBUG:
from debug_toolbar.toolbar import debug_toolbar_urls from debug_toolbar.toolbar import debug_toolbar_urls
from .views import IndexView, MediaAccess from .views import IndexView, MediaAccess
@ -24,7 +24,7 @@ urlpatterns = [
path("", include("photologue.urls", namespace="photologue")), path("", include("photologue.urls", namespace="photologue")),
path("accounts/", include("allauth.urls")), path("accounts/", include("allauth.urls")),
path("i18n/", include("django.conf.urls.i18n")), path("i18n/", include("django.conf.urls.i18n")),
path('jsi18n/', JavaScriptCatalog.as_view(), name='javascript-catalog'), path("jsi18n/", JavaScriptCatalog.as_view(), name="javascript-catalog"),
path("admin/doc/", include("django.contrib.admindocs.urls")), path("admin/doc/", include("django.contrib.admindocs.urls")),
path("admin/", admin.site.urls), path("admin/", admin.site.urls),
] ]

View file

@ -59,4 +59,4 @@ class TagAdmin(admin.ModelAdmin):
admin.site.register(Gallery, GalleryAdmin) admin.site.register(Gallery, GalleryAdmin)
admin.site.register(Photo, PhotoAdmin) admin.site.register(Photo, PhotoAdmin)
admin.site.register(Tag, TagAdmin) admin.site.register(Tag, TagAdmin)

View file

@ -186,15 +186,15 @@ class Gallery(models.Model):
def sample(self, public=True): def sample(self, public=True):
"""Return a sample of photos, ordered at random.""" """Return a sample of photos, ordered at random."""
count = 1 count = 1
nb = self.photo_count(public) #Optimisation don't do twice the SQL requests nb = self.photo_count(public) # Optimisation don't do twice the SQL requests
if nb < count: if nb < count:
count = nb count = nb
if public: if public:
photo_set = self.photos.filter(is_public=True) photo_set = self.photos.filter(is_public=True)
else: else:
photo_set = self.photos photo_set = self.photos
return photo_set.order_by("?")[:count] # Use native SQL random return photo_set.order_by("?")[:count] # Use native SQL random
def photo_count(self, public=True): def photo_count(self, public=True):
"""Return a count of all the photos in this gallery.""" """Return a count of all the photos in this gallery."""
@ -726,14 +726,14 @@ class PhotoSizeCache:
def __init__(self): def __init__(self):
self.__dict__ = self.__state self.__dict__ = self.__state
cached = caches.get("PhotoSizeCache",None) cached = caches.get("PhotoSizeCache", None)
if cached is None : if cached is None:
if not len(self.sizes): if not len(self.sizes):
sizes = PhotoSize.objects.all() sizes = PhotoSize.objects.all()
for size in sizes: for size in sizes:
self.sizes[size.name] = size self.sizes[size.name] = size
caches.set("PhotoSizeCache",self) caches.set("PhotoSizeCache", self)
else : else:
self = cached self = cached
def reset(self): def reset(self):

View file

@ -23,7 +23,6 @@ from PIL import Image
from django.contrib.auth import get_user_model from django.contrib.auth import get_user_model
from .forms import UploadForm from .forms import UploadForm
from .models import Gallery, Photo, Tag from .models import Gallery, Photo, Tag
@ -143,23 +142,22 @@ class GalleryDetailView(LoginRequiredMixin, DetailView):
# Non-staff members only see public photos + prefetch all owners informations (Optimisation) # Non-staff members only see public photos + prefetch all owners informations (Optimisation)
if self.request.user.is_staff: if self.request.user.is_staff:
context["photos"] = self.object.photos.all().select_related('owner') context["photos"] = self.object.photos.all().select_related("owner")
else: else:
context["photos"] = self.object.photos.filter(is_public=True).select_related('owner') context["photos"] = self.object.photos.filter(
is_public=True
).select_related("owner")
# List owners # List owners
context["owners"] = [] context["owners"] = []
#owners_pk_distinct = context["photos"].order_by('owner__pk').values_list('owner__pk', flat=True).distinct() # owners_pk_distinct = context["photos"].order_by('owner__pk').values_list('owner__pk', flat=True).distinct()
#context["owners"] = User.objects.filter(pk__in=owners_pk_distinct) # context["owners"] = User.objects.filter(pk__in=owners_pk_distinct)
for photo in context["photos"]: for photo in context["photos"]:
if photo.owner not in context["owners"]: if photo.owner not in context["owners"]:
context["owners"].append(photo.owner) context["owners"].append(photo.owner)
# Filter on owner # Filter on owner
if "owner" in self.kwargs: if "owner" in self.kwargs:
context["photos"] = context["photos"].filter(owner__id=self.kwargs["owner"]) context["photos"] = context["photos"].filter(owner__id=self.kwargs["owner"])