diff --git a/bookwyrm/admin.py b/bookwyrm/admin.py index efe5e9d7..f028dea0 100644 --- a/bookwyrm/admin.py +++ b/bookwyrm/admin.py @@ -2,7 +2,6 @@ from django.contrib import admin from bookwyrm import models -admin.site.register(models.SiteSettings) admin.site.register(models.User) admin.site.register(models.FederatedServer) admin.site.register(models.Connector) diff --git a/bookwyrm/context_processors.py b/bookwyrm/context_processors.py index f5f25186..b77c62b0 100644 --- a/bookwyrm/context_processors.py +++ b/bookwyrm/context_processors.py @@ -4,4 +4,7 @@ from bookwyrm import models def site_settings(request): # pylint: disable=unused-argument """include the custom info about the site""" - return {"site": models.SiteSettings.objects.get()} + return { + "site": models.SiteSettings.objects.get(), + "active_announcements": models.Announcement.active_announcements(), + } diff --git a/bookwyrm/forms.py b/bookwyrm/forms.py index b6197f33..25b72a11 100644 --- a/bookwyrm/forms.py +++ b/bookwyrm/forms.py @@ -269,6 +269,12 @@ class SiteForm(CustomForm): exclude = [] +class AnnouncementForm(CustomForm): + class Meta: + model = models.Announcement + exclude = ["remote_id"] + + class ListForm(CustomForm): class Meta: model = models.List diff --git a/bookwyrm/migrations/0075_announcement.py b/bookwyrm/migrations/0075_announcement.py new file mode 100644 index 00000000..b667c262 --- /dev/null +++ b/bookwyrm/migrations/0075_announcement.py @@ -0,0 +1,56 @@ +# Generated by Django 3.2 on 2021-05-20 19:34 + +import bookwyrm.models.fields +from django.conf import settings +from django.db import migrations, models +import django.db.models.deletion + + +class Migration(migrations.Migration): + + dependencies = [ + ("bookwyrm", "0074_auto_20210511_1829"), + ] + + operations = [ + migrations.CreateModel( + name="Announcement", + fields=[ + ( + "id", + models.AutoField( + auto_created=True, + primary_key=True, + serialize=False, + verbose_name="ID", + ), + ), + ("created_date", models.DateTimeField(auto_now_add=True)), + ("updated_date", models.DateTimeField(auto_now=True)), + ( + "remote_id", + bookwyrm.models.fields.RemoteIdField( + max_length=255, + null=True, + validators=[bookwyrm.models.fields.validate_remote_id], + ), + ), + ("preview", models.CharField(max_length=255)), + ("content", models.TextField(blank=True, null=True)), + ("event_date", models.DateTimeField(blank=True, null=True)), + ("start_date", models.DateTimeField(blank=True, null=True)), + ("end_date", models.DateTimeField(blank=True, null=True)), + ("active", models.BooleanField(default=True)), + ( + "user", + models.ForeignKey( + on_delete=django.db.models.deletion.PROTECT, + to=settings.AUTH_USER_MODEL, + ), + ), + ], + options={ + "abstract": False, + }, + ), + ] diff --git a/bookwyrm/models/__init__.py b/bookwyrm/models/__init__.py index 2a25a525..6f378e83 100644 --- a/bookwyrm/models/__init__.py +++ b/bookwyrm/models/__init__.py @@ -25,6 +25,7 @@ from .federated_server import FederatedServer from .import_job import ImportJob, ImportItem from .site import SiteSettings, SiteInvite, PasswordReset, InviteRequest +from .announcement import Announcement cls_members = inspect.getmembers(sys.modules[__name__], inspect.isclass) activity_models = { diff --git a/bookwyrm/models/announcement.py b/bookwyrm/models/announcement.py new file mode 100644 index 00000000..498d5041 --- /dev/null +++ b/bookwyrm/models/announcement.py @@ -0,0 +1,28 @@ +""" admin announcements """ +from django.db import models +from django.db.models import Q +from django.utils import timezone + +from .base_model import BookWyrmModel + + +class Announcement(BookWyrmModel): + """The admin has something to say""" + + user = models.ForeignKey("User", on_delete=models.PROTECT) + preview = models.CharField(max_length=255) + content = models.TextField(null=True, blank=True) + event_date = models.DateTimeField(blank=True, null=True) + start_date = models.DateTimeField(blank=True, null=True) + end_date = models.DateTimeField(blank=True, null=True) + active = models.BooleanField(default=True) + + @classmethod + def active_announcements(cls): + """announcements that should be displayed""" + now = timezone.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, + ) diff --git a/bookwyrm/static/css/bookwyrm.css b/bookwyrm/static/css/bookwyrm.css index 8e1aab25..fcb32e21 100644 --- a/bookwyrm/static/css/bookwyrm.css +++ b/bookwyrm/static/css/bookwyrm.css @@ -88,10 +88,11 @@ body { .transition-y.is-hidden { display: block !important; visibility: hidden !important; - height: 0; - width: 0; - margin: 0; - padding: 0; + height: 0 !important; + width: 0 !important; + margin: 0 !important; + padding: 0 !important; + overflow: auto; } .transition-x, diff --git a/bookwyrm/templates/book/book.html b/bookwyrm/templates/book/book.html index ff027a3d..fb0a4510 100644 --- a/bookwyrm/templates/book/book.html +++ b/bookwyrm/templates/book/book.html @@ -1,7 +1,5 @@ {% extends 'layout.html' %} -{% load i18n %} -{% load bookwyrm_tags %} -{% load humanize %} +{% load i18n %}{% load bookwyrm_tags %}{% load humanize %}{% load utilities %} {% block title %}{{ book.title }}{% endblock %} diff --git a/bookwyrm/templates/book/book_identifiers.html b/bookwyrm/templates/book/book_identifiers.html index d71ea409..6021d243 100644 --- a/bookwyrm/templates/book/book_identifiers.html +++ b/bookwyrm/templates/book/book_identifiers.html @@ -1,5 +1,4 @@ {% spaceless %} - {% load i18n %}
+ + {{ form.preview }} + {% for error in form.preview.errors %} +
{{ error | escape }}
+ {% endfor %} + ++ + {{ form.content }} + {% for error in form.content.errors %} +
{{ error | escape }}
+ {% endfor %} + ++ + + {% for error in form.event_date.errors %} +
{{ error | escape }}
+ {% endfor %} + ++ + + {% for error in form.start_date.errors %} +
{{ error | escape }}
+ {% endfor %} + ++ + + {% for error in form.end_date.errors %} +
{{ error | escape }}
+ {% endfor %} + ++ + {{ form.active }} + {% for error in form.active.errors %} +
{{ error | escape }}
+ {% endfor %} + ++ {% url 'settings-announcements' as url %} + {% trans "Date added" as text %} + {% include 'snippets/table-sort-header.html' with field="created_date" sort=sort text=text %} + | ++ {% trans "Preview" as text %} + {% include 'snippets/table-sort-header.html' with field="preview" sort=sort text=text %} + | ++ {% trans "Start date" as text %} + {% include 'snippets/table-sort-header.html' with field="start_date" sort=sort text=text %} + | ++ {% trans "End date" as text %} + {% include 'snippets/table-sort-header.html' with field="end_date" sort=sort text=text %} + | ++ {% trans "Status" as text %} + {% include 'snippets/table-sort-header.html' with field="active" sort=sort text=text %} + | +
---|---|---|---|---|
{{ announcement.created_date|naturalday }} | +{{ announcement.preview }} | +{{ announcement.start_date|naturaltime|default:'' }} | +{{ announcement.end_date|naturaltime|default:'' }} | +{% if announcement.active %}{% trans "active" %}{% else %}{% trans "inactive" %}{% endif %} | +