From 4b3cf831813ac01f6fdd12b6f738d643ac875682 Mon Sep 17 00:00:00 2001 From: Alexandre Iooss Date: Sun, 30 Jan 2022 13:13:53 +0100 Subject: [PATCH] Make all galleries public --- photo21/views.py | 2 +- photologue/admin.py | 4 ++-- .../0003_remove_gallery_is_public.py | 17 +++++++++++++++ photologue/models.py | 7 +------ .../templates/photologue/gallery_detail.html | 1 - .../photologue/includes/gallery_sample.html | 3 +-- photologue/views.py | 21 ++----------------- 7 files changed, 24 insertions(+), 31 deletions(-) create mode 100644 photologue/migrations/0003_remove_gallery_is_public.py diff --git a/photo21/views.py b/photo21/views.py index 5429901..90d71d5 100644 --- a/photo21/views.py +++ b/photo21/views.py @@ -17,6 +17,6 @@ class MediaAccess(LoginRequiredMixin, View): class IndexView(LoginRequiredMixin, ListView): - queryset = Gallery.objects.filter(is_public=True) + queryset = Gallery.objects.all() paginate_by = 4 template_name = "index.html" diff --git a/photologue/admin.py b/photologue/admin.py index 774ed8e..e58d1c1 100644 --- a/photologue/admin.py +++ b/photologue/admin.py @@ -5,8 +5,8 @@ from .models import Gallery, Photo, Tag class GalleryAdmin(admin.ModelAdmin): - list_display = ('title', 'date_start', 'photo_count', 'is_public') - list_filter = ['date_start', 'is_public'] + list_display = ('title', 'date_start', 'photo_count') + list_filter = ['date_start'] date_hierarchy = 'date_start' prepopulated_fields = {'slug': ('title',)} model = Gallery diff --git a/photologue/migrations/0003_remove_gallery_is_public.py b/photologue/migrations/0003_remove_gallery_is_public.py new file mode 100644 index 0000000..8092038 --- /dev/null +++ b/photologue/migrations/0003_remove_gallery_is_public.py @@ -0,0 +1,17 @@ +# Generated by Django 3.2.11 on 2022-01-30 12:14 + +from django.db import migrations + + +class Migration(migrations.Migration): + + dependencies = [ + ('photologue', '0002_auto_20220130_1020'), + ] + + operations = [ + migrations.RemoveField( + model_name='gallery', + name='is_public', + ), + ] diff --git a/photologue/models.py b/photologue/models.py index 889be06..ede27c3 100644 --- a/photologue/models.py +++ b/photologue/models.py @@ -15,7 +15,6 @@ import exifread from django.conf import settings from django.core.exceptions import ValidationError from django.core.files.base import ContentFile -from django.core.files.storage import default_storage from django.core.validators import RegexValidator from django.db import models from django.template.defaultfilters import slugify @@ -153,10 +152,6 @@ class Gallery(models.Model): verbose_name=_('tags'), blank=True, ) - is_public = models.BooleanField(_('is public'), - default=True, - help_text=_('Public galleries will be displayed ' - 'in the default views.')) photos = models.ManyToManyField('photologue.Photo', related_name='galleries', verbose_name=_('photos'), @@ -500,7 +495,7 @@ class Photo(ImageModel): def public_galleries(self): """Return the public galleries to which this photo belongs.""" - return self.galleries.filter(is_public=True) + return self.galleries def get_previous_in_gallery(self, gallery): """Find the neighbour of this photo in the supplied gallery. diff --git a/photologue/templates/photologue/gallery_detail.html b/photologue/templates/photologue/gallery_detail.html index 88d2cf4..4975d54 100644 --- a/photologue/templates/photologue/gallery_detail.html +++ b/photologue/templates/photologue/gallery_detail.html @@ -39,7 +39,6 @@ SPDX-License-Identifier: GPL-3.0-or-later {% endif %} {% if gallery.date_start %}

{{ gallery.date_start }}{% if gallery.date_end and gallery.date_end != gallery.date_start %} {% trans "to" %} {{ gallery.date_end }}{% endif %}

{% endif %} -{% if not gallery.is_public %}

PRIVATE

{% endif %} {% if gallery.tags.all %}

Tags : {% for tag in gallery.tags.all %} diff --git a/photologue/templates/photologue/includes/gallery_sample.html b/photologue/templates/photologue/includes/gallery_sample.html index 694fda4..8282074 100644 --- a/photologue/templates/photologue/includes/gallery_sample.html +++ b/photologue/templates/photologue/includes/gallery_sample.html @@ -1,13 +1,12 @@ {% load i18n %} -

+
{% for photo in gallery.sample %} {{ photo.title }} {% endfor %}
{{ gallery.title }}
{% if gallery.date_start %}

{{ gallery.date_start }}{% if gallery.date_end and gallery.date_end != gallery.date_start %} - {{ gallery.date_end }}{% endif %}

{% endif %} - {% if not gallery.is_public %}

(private)

{% endif %}
diff --git a/photologue/views.py b/photologue/views.py index cf10e0b..01c2abd 100644 --- a/photologue/views.py +++ b/photologue/views.py @@ -29,14 +29,6 @@ class GalleryDateView(LoginRequiredMixin): uses_datetime_field = False # Fix related object access allow_empty = True - def get_queryset(self): - """Non-staff members only see public galleries""" - qs = super().get_queryset() - if self.request.user.is_staff: - return qs - else: - return qs.filter(is_public=True) - class GalleryArchiveIndexView(GalleryDateView, ArchiveIndexView): pass @@ -67,8 +59,7 @@ class TagDetail(LoginRequiredMixin, DetailView): """ current_tag = self.get_object().slug context = super().get_context_data(**kwargs) - context['galleries'] = Gallery.objects.filter(is_public=True) \ - .filter(tags__slug=current_tag) \ + context['galleries'] = Gallery.objects.filter(tags__slug=current_tag) \ .order_by('-date_start') return context @@ -79,14 +70,6 @@ class GalleryDetailView(LoginRequiredMixin, DetailView): """ model = Gallery - def get_queryset(self): - """Non-staff members only see public galleries""" - qs = super().get_queryset() - if self.request.user.is_staff: - return qs - else: - return qs.filter(is_public=True) - def get_context_data(self, **kwargs): context = super().get_context_data(**kwargs) @@ -110,7 +93,7 @@ class GalleryDetailView(LoginRequiredMixin, DetailView): class GalleryDownload(LoginRequiredMixin, DetailView): - queryset = Gallery.objects.filter(is_public=True) + model = Gallery def get(self, request, *args, **kwargs): """