replace status strings to constants

This commit is contained in:
2022-01-07 10:53:51 +00:00
parent 38630da901
commit 04b688aa06
4 changed files with 10 additions and 8 deletions

View File

@@ -20,11 +20,13 @@ class Album(models.Model):
)
description = models.TextField(null=True, blank=True)
DRAFT = "10"
PUBLIC = "20"
STATUS = (
("10", "DRAFT"),
("20", "PUBLIC"),
(DRAFT, "DRAFT"),
(PUBLIC, "PUBLIC"),
)
status = models.CharField(max_length=2, choices=STATUS, default="10")
status = models.CharField(max_length=2, choices=STATUS, default=DRAFT)
event_date = models.DateField(
verbose_name="Event Datum", null=True, blank=True, default=timezone.now

View File

@@ -16,8 +16,8 @@ def index(request):
if request.user.is_authenticated:
albums = deque(Album.objects.all().order_by("-event_date"))
else:
# show only PUBLIC albums ("20" -> PUBLIC).
albums = deque(Album.objects.filter(status="20").order_by("-event_date"))
# show only PUBLIC albums.
albums = deque(Album.objects.filter(status=Album.PUBLIC).order_by("-event_date"))
for album in list(albums):
img_list = get_image_list(album.folder_name)
@@ -35,7 +35,7 @@ def index(request):
album.thumbnail = img_list[value]["thumb_url"]
else:
# empty album is set to DRAFT.
album.status = "10"
album.status = Album.DRAFT
if request.user.is_authenticated:
for folder in get_folder_list():

View File

@@ -35,7 +35,7 @@
{% if album.event_date %}
Datum: {{ album.event_date }}<br>
{% endif %}
{% if album.status == "10" %}
{% if album.status == album.DRAFT %}
DRAFT<br>
{% endif %}
{% if album.description %}

View File

@@ -14,7 +14,7 @@
<div class="grid-x">
{% for album in albums %}
<div class="cell large-2 medium-3 small-12" {% if album.status == "10" %}style="background-color:red;"{% endif %}>
<div class="cell large-2 medium-3 small-12" {% if album.status == album.DRAFT %}style="background-color:red;"{% endif %}>
{% if album.status == "10" %}
<a href="{% url 'draft-album' album.slug %}">