-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
0def888
commit d427ff9
Showing
29 changed files
with
1,454 additions
and
64 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -19,3 +19,5 @@ | |
|
||
if sys.argv[1:2] != ["test"]: | ||
MIDDLEWARE += ("fredagscafeen.autologin.AutologinMiddleware",) | ||
|
||
YEAR = 2024 |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
from django import forms | ||
from django.contrib import admin | ||
from django.db import models | ||
from django.urls import reverse | ||
from django.utils.html import format_html | ||
|
||
from gallery.models import Album, BaseMedia | ||
|
||
|
||
class InlineBaseMediaAdmin(admin.TabularInline): | ||
model = BaseMedia | ||
extra = 0 | ||
fields = ( | ||
"admin_thumbnail", | ||
"date", | ||
"caption", | ||
"visibility", | ||
"slug", | ||
"forcedOrder", | ||
"isCoverFile", | ||
) | ||
readonly_fields = ( | ||
"admin_thumbnail", | ||
"slug", | ||
"isCoverFile", | ||
) | ||
|
||
def has_add_permission(self, request, obj=None): | ||
return False | ||
|
||
|
||
class AlbumAdminForm(forms.ModelForm): | ||
class Meta: | ||
model = Album | ||
fields = [ | ||
"title", | ||
"publish_date", | ||
"gfyear", | ||
"eventalbum", | ||
"description", | ||
"slug", | ||
] | ||
|
||
|
||
class AlbumAdmin(admin.ModelAdmin): | ||
# List display of multiple albums | ||
list_display = ("title", "gfyear", "publish_date", "get_visibility_link") | ||
ordering = [ | ||
"-gfyear", | ||
"eventalbum", | ||
"-oldFolder", | ||
"-publish_date", | ||
] # Reverse of models.Album.ordering | ||
list_filter = ("gfyear", "eventalbum") | ||
|
||
# Form display of single album | ||
inlines = [InlineBaseMediaAdmin] | ||
form = AlbumAdminForm | ||
prepopulated_fields = { | ||
"slug": ("title",), | ||
} | ||
formfield_overrides = { | ||
models.SlugField: {"widget": forms.TextInput(attrs={"readOnly": "True"})} | ||
} | ||
|
||
add_form_template = "admin/gallery/add_form.html" | ||
|
||
def get_inline_instances(self, request, obj=None): | ||
if obj is None: | ||
# When creating Album, don't display the BaseMedia inlines | ||
return [] | ||
return super(AlbumAdmin, self).get_inline_instances(request, obj) | ||
|
||
def get_visibility_link(self, album): | ||
file = album.basemedia.first() | ||
if file: | ||
kwargs = dict( | ||
gfyear=album.gfyear, album_slug=album.slug, image_slug=file.slug | ||
) | ||
return format_html( | ||
'<a href="{}?v=1">Udvælg billeder</a>', reverse("image", kwargs=kwargs) | ||
) | ||
|
||
get_visibility_link.short_description = "Udvælg billeder" | ||
|
||
def save_related(self, request, form, formsets, change): | ||
super().save_related(request, form, formsets, change) | ||
# Update isCoverFile on all images in album | ||
# now that images have been saved to the database. | ||
form.instance.clean() | ||
|
||
|
||
admin.site.register(Album, AlbumAdmin) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
import re | ||
|
||
from django import forms | ||
|
||
from gallery.models import BaseMedia | ||
|
||
|
||
class EditVisibilityForm(forms.Form): | ||
class Missing(Exception): | ||
pass | ||
|
||
def __init__(self, file_visibility, **kwargs): | ||
super(EditVisibilityForm, self).__init__(**kwargs) | ||
self.basemedias = [] | ||
self.album_pks = set() | ||
for file in file_visibility: | ||
if isinstance(file, BaseMedia): | ||
pk = file.pk | ||
visibility = file.visibility | ||
album = file.album_id | ||
elif isinstance(file, tuple): | ||
pk, visibility, album = file | ||
else: | ||
raise TypeError(type(file)) | ||
k = "i%s" % pk | ||
self.album_pks.add(album) | ||
self.fields[k] = forms.ChoiceField( | ||
choices=BaseMedia.VISIBILITY, | ||
initial=visibility, | ||
widget=forms.RadioSelect, | ||
) | ||
self.basemedias.append((pk, k)) | ||
|
||
@classmethod | ||
def from_POST(cls, post_data): | ||
pattern = r"^i(\d+)$" | ||
pks = [] | ||
for k, v in post_data.items(): | ||
mo = re.match(pattern, k) | ||
if mo: | ||
pks.append(int(mo.group(1))) | ||
files = BaseMedia.objects.filter(pk__in=pks) | ||
files = list(files.values_list("pk", "visibility", "album_id")) | ||
found_pks = [f[0] for f in files] | ||
missing = set(pks) - set(found_pks) | ||
if missing: | ||
raise cls.Missing("Not found: %r" % (sorted(missing),)) | ||
return cls(files, data=post_data) |
Empty file.
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import logging | ||
|
||
from django.core.management.base import BaseCommand | ||
|
||
from gallery.models import BaseMedia | ||
|
||
logger = logging.getLogger(__name__) | ||
|
||
|
||
class Command(BaseCommand): | ||
help = 'Slet billeder som er markeret "Slet"' | ||
|
||
def handle(self, *args, **options): | ||
qs = BaseMedia.objects.filter(visibility=BaseMedia.DELETE) | ||
n = qs.count() | ||
if n: | ||
ids = sorted(qs.values_list("id", flat=True)) | ||
logger.info("Deleting %s BaseMedia objects with IDs %s", n, ids) | ||
BaseMedia.objects.filter(id__in=ids).delete() |
Oops, something went wrong.