Don't need both name and preview

This commit is contained in:
Mouse Reeve 2021-05-19 15:17:32 -07:00
parent 515d5bb237
commit 346d718265
5 changed files with 29 additions and 34 deletions

View file

@ -6,5 +6,5 @@ def site_settings(request): # pylint: disable=unused-argument
"""include the custom info about the site"""
return {
"site": models.SiteSettings.objects.get(),
"announcements": models.Announcement.active_announcements(),
"active_announcements": models.Announcement.active_announcements(),
}

View file

@ -1,4 +1,4 @@
# Generated by Django 3.2 on 2021-05-19 20:58
# Generated by Django 3.2 on 2021-05-19 22:16
import bookwyrm.models.fields
from django.conf import settings
@ -35,7 +35,6 @@ class Migration(migrations.Migration):
validators=[bookwyrm.models.fields.validate_remote_id],
),
),
("name", models.CharField(max_length=255)),
("preview", models.CharField(max_length=255)),
("content", models.TextField()),
("event_date", models.DateTimeField(blank=True, null=True)),

View file

@ -1,5 +1,6 @@
""" admin announcements """
from django.db import models
from django.db.models import Q
from django.utils import timezone
from .base_model import BookWyrmModel
@ -9,7 +10,6 @@ class Announcement(BookWyrmModel):
"""The admin has something to say"""
user = models.ForeignKey("User", on_delete=models.PROTECT)
name = models.CharField(max_length=255)
preview = models.CharField(max_length=255)
content = models.TextField()
event_date = models.DateTimeField(blank=True, null=True)
@ -21,4 +21,8 @@ class Announcement(BookWyrmModel):
def active_announcements(cls):
"""announcements that should be displayed"""
now = timezone.now()
return cls.objects.filter(active=True, start_date__lte=now, end_date__gte=now)
return cls.objects.filter(
Q(start_date__isnull=True) | Q(start_date__lte=now),
Q(end_date__isnull=True) | Q(end_date__gte=now),
active=True,
)

View file

@ -10,14 +10,28 @@
<form name="create-announcement" method="post" action="/settings/announcements">
{% csrf_token %}
<input type="hidden" name="user" value="{{ request.user.id }}">
<p>
<label class="label" for="id_name">Name:</label>
{{ form.name }}
{% for error in form.name.errors %}
<label class="label" for="id_preview">Preview:</label>
{{ form.preview }}
{% for error in form.preview.errors %}
<p class="help is-danger">{{ error | escape }}</p>
{% endfor %}
</p>
<p>
<label class="label" for="id_content">Content:</label>
{{ form.content }}
{% for error in form.content.errors %}
<p class="help is-danger">{{ error | escape }}</p>
{% endfor %}
</p>
<p>
<label class="label" for="id_event_date">Event date:</label>
<input type="date" name="event_date" value="{{ form.event_date.value }}" class="input" id="id_event_date">
{% for error in form.event_date.errors %}
<p class="help is-danger">{{ error | escape }}</p>
{% endfor %}
</p>
<hr aria-hidden="true">
<div class="columns">
<div class="column">
<p>
@ -47,28 +61,6 @@
</p>
</div>
</div>
<hr aria-hidden="true">
<p>
<label class="label" for="id_preview">Preview:</label>
{{ form.preview }}
{% for error in form.preview.errors %}
<p class="help is-danger">{{ error | escape }}</p>
{% endfor %}
</p>
<p>
<label class="label" for="id_content">Content:</label>
{{ form.content }}
{% for error in form.content.errors %}
<p class="help is-danger">{{ error | escape }}</p>
{% endfor %}
</p>
<p>
<label class="label" for="id_event_date">Event date:</label>
<input type="date" name="event_date" value="{{ form.event_date.value }}" class="input" id="id_event_date">
{% for error in form.event_date.errors %}
<p class="help is-danger">{{ error | escape }}</p>
{% endfor %}
</p>
<div class="field has-addons">
<div class="control">

View file

@ -19,8 +19,8 @@
<tr>
{% url 'settings-announcements' as url %}
<th>
{% trans "Name" as text %}
{% include 'snippets/table-sort-header.html' with field="name" sort=sort text=text %}
{% trans "Preview" as text %}
{% include 'snippets/table-sort-header.html' with field="preview" sort=sort text=text %}
</th>
<th>
{% trans "Start date" as text %}
@ -37,7 +37,7 @@
</tr>
{% for announcement in announcements %}
<tr>
<td><a href="{% url 'settings-announcements' announcement.id %}">{{ announcement.name }}</a></td>
<td><a href="{% url 'settings-announcements' announcement.id %}">{{ announcement.preview }}</a></td>
<td>{{ announcement.start_date|naturaltime|default:'' }}</td>
<td>{{ announcement.end_date|naturaltime|default:'' }}</td>
<td>{% if announcement.active %}{% trans "active" %}{% else %}{% trans "inactive" %}{% endif %}</td>