Skip to content

Commit

Permalink
Merge pull request #11 from bear-rsg/dev
Browse files Browse the repository at this point in the history
new group model, order field, more translations
  • Loading branch information
mike-allaway authored Jul 31, 2024
2 parents 8486604 + 6243143 commit 59421eb
Show file tree
Hide file tree
Showing 7 changed files with 147 additions and 7 deletions.
13 changes: 12 additions & 1 deletion django/photographs/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,15 @@ class PhotographUserContributionStackedInline(admin.StackedInline):
readonly_fields = ('meta_created_datetime', 'meta_lastupdated_datetime')


@admin.register(models.PhotographGroup)
class PhotographGroupAdminView(admin.ModelAdmin):
"""
Customise the admin interface for PhotographGroup model
"""

list_display = ('id', 'name', 'notes')


@admin.register(models.Photograph)
class PhotographAdminView(admin.ModelAdmin):
"""
Expand All @@ -51,6 +60,8 @@ class PhotographAdminView(admin.ModelAdmin):

list_display = ('id',
'image',
'group',
'order',
'published',
'meta_created_by',
'meta_created_datetime',
Expand All @@ -69,7 +80,7 @@ class PhotographAdminView(admin.ModelAdmin):
'meta_lastupdated_datetime')
actions = (publish, unpublish)
inlines = (PhotographUserContributionStackedInline,)
list_per_page = 100
list_per_page = 50

def save_model(self, request, obj, form, change):
# Meta: created (if not yet set) or last updated by (if created already set)
Expand Down
32 changes: 32 additions & 0 deletions django/photographs/locale/en/LC_MESSAGES/django.po
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# SOME DESCRIPTIVE TITLE.
# Copyright (C) YEAR THE PACKAGE'S COPYRIGHT HOLDER
# This file is distributed under the same license as the PACKAGE package.
# FIRST AUTHOR <EMAIL@ADDRESS>, YEAR.
#
#, fuzzy
msgid ""
msgstr ""
"Project-Id-Version: PACKAGE VERSION\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2024-07-31 11:38+0100\n"
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language-Team: LANGUAGE <[email protected]>\n"
"Language: \n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n"
"Plural-Forms: nplurals=2; plural=(n != 1);\n"

#: photographs/templates/photographs/detail.html:13
#: photographs/templates/photographs/list.html:33
msgid "Photograph"
msgstr ""

#: photographs/templates/photographs/list.html:7
msgid "Photographs"
msgstr ""

#: photographs/templates/photographs/list.html:14
msgid "Search"
msgstr ""
32 changes: 32 additions & 0 deletions django/photographs/locale/es/LC_MESSAGES/django.po
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# SOME DESCRIPTIVE TITLE.
# Copyright (C) YEAR THE PACKAGE'S COPYRIGHT HOLDER
# This file is distributed under the same license as the PACKAGE package.
# FIRST AUTHOR <EMAIL@ADDRESS>, YEAR.
#
#, fuzzy
msgid ""
msgstr ""
"Project-Id-Version: PACKAGE VERSION\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2024-07-31 11:38+0100\n"
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language-Team: LANGUAGE <[email protected]>\n"
"Language: \n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n"
"Plural-Forms: nplurals=2; plural=(n != 1);\n"

#: photographs/templates/photographs/detail.html:13
#: photographs/templates/photographs/list.html:33
msgid "Photograph"
msgstr "Fotografía"

#: photographs/templates/photographs/list.html:7
msgid "Photographs"
msgstr "Fotografías"

#: photographs/templates/photographs/list.html:14
msgid "Search"
msgstr "Buscar"
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
# Generated by Django 4.2.14 on 2024-07-31 10:50

from django.db import migrations, models
import django.db.models.deletion


class Migration(migrations.Migration):

dependencies = [
('photographs', '0002_photograph_image_name'),
]

operations = [
migrations.CreateModel(
name='PhotographGroup',
fields=[
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('name', models.CharField(max_length=255)),
('notes', models.TextField(blank=True, help_text='Notes are for admins only and will not be visible on the public website', null=True)),
],
),
migrations.AlterModelOptions(
name='photograph',
options={'ordering': ('group', 'order', 'meta_created_datetime')},
),
migrations.AddField(
model_name='photograph',
name='order',
field=models.IntegerField(blank=True, help_text='Photographs are ordered by their group, then by this order field (in ascending order), and then by date created.', null=True),
),
migrations.AddField(
model_name='photograph',
name='group',
field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.PROTECT, related_name='photographs', to='photographs.photographgroup'),
),
]
21 changes: 20 additions & 1 deletion django/photographs/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,20 @@
from ckeditor_uploader.fields import RichTextUploadingField


class PhotographGroup(models.Model):
"""
A group of related photographs
"""

related_name = 'photographgroups'

name = models.CharField(max_length=255)
notes = models.TextField(blank=True, null=True, help_text='Notes are for admins only and will not be visible on the public website')

def __str__(self):
return self.name


class Photograph(models.Model):
"""
A photograph and related data
Expand All @@ -14,9 +28,11 @@ class Photograph(models.Model):

image = models.ImageField(upload_to='photographs', blank=True, null=True)
image_name = models.CharField(max_length=255, blank=True, null=True, help_text="A brief name/title for the image")
group = models.ForeignKey('PhotographGroup', on_delete=models.PROTECT, blank=True, null=True, related_name=related_name)
description_es = RichTextUploadingField(blank=True, null=True, verbose_name='Description (Spanish)')
description_en = RichTextUploadingField(blank=True, null=True, verbose_name='Description (English)')
acknowledgements = models.TextField(blank=True, null=True)
order = models.IntegerField(blank=True, null=True, help_text='Photographs are ordered by their group, then by this order field (in ascending order), and then by date created.')
published = models.BooleanField(default=False, help_text='Check this box to include this photograph on the public website')
notes = models.TextField(blank=True, null=True, help_text='Notes are for admins only and will not be visible on the public website')

Expand All @@ -31,11 +47,14 @@ def admin_url(self):
return reverse('admin:photographs_photograph_change', args=[self.id])

def __str__(self):
return self.image_name if self.image_name else f'Photograph #{self.id}'
return f'#{self.id}'

def get_absolute_url(self):
return reverse('photographs:detail', args=[self.id])

class Meta:
ordering = ('group', 'order', 'meta_created_datetime')


class PhotographUserContribution(models.Model):
"""
Expand Down
8 changes: 7 additions & 1 deletion django/photographs/templates/photographs/detail.html
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,13 @@

<!-- Photograph -->
<div id="photograph-detail" class="container">
<h2>{{ photograph }}</h2>
<h2>
{% if photograph.image_name %}
{{ photograph.image_name }}
{% else %}
{% translate 'Photograph' %} #{{ photograph.id }}
{% endif %}
</h2>
<div id="photograph-detail-description">
{% if LANGUAGE_CODE == 'es' %}
{{ photograph.description_es | safe }}
Expand Down
12 changes: 8 additions & 4 deletions django/photographs/templates/photographs/list.html
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
{% extends "base.html" %}
{% load static %}
{% load static i18n %}
{% block main %}

<!-- Photograph -->
<div id="photograph-list" class="container">
<h2>Photographs</h2>
<h2>{% translate 'Photographs' %}</h2>

<!-- Search -->
<form method="GET" class="form-group row" id="photograph-list-search-form">
<div class="col-12">
<div class="input-group">
<!-- Search textbox -->
<input type="text" class="form-control" name="search" title="Search" id="photograph-list-search-input" placeholder="Search">
<input type="text" class="form-control" name="search" title="Search" id="photograph-list-search-input" placeholder="{% translate 'Search' %}">
<!-- Search button -->
<div class="input-group-append">
<button type="submit" value="Search" class="btn" title="search-btn" id="photograph-list-search-button">
Expand All @@ -27,7 +27,11 @@ <h2>Photographs</h2>
{% for photograph in photograph_list %}
<a href="{% url 'photographs:detail' photograph.id %}" class="photograph-list-items-item" style="background-image: url({{ photograph.image.url }});">
<div class="photograph-list-items-item-text">
{{ photograph }}
{% if photograph.image_name %}
{{ photograph.image_name }}
{% else %}
{% translate 'Photograph' %} #{{ photograph.id }}
{% endif %}
</div>
</a>
{% endfor %}
Expand Down

0 comments on commit 59421eb

Please sign in to comment.