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 %}
diff --git a/bookwyrm/templates/book/editions.html b/bookwyrm/templates/book/editions.html index 17d5474c..0d5c1044 100644 --- a/bookwyrm/templates/book/editions.html +++ b/bookwyrm/templates/book/editions.html @@ -1,11 +1,11 @@ {% extends 'layout.html' %} -{% load i18n %} +{% load i18n %}{% load utilities %} -{% block title %}{% blocktrans with book_title=work.title %}Editions of {{ book_title }}{% endblocktrans %}{% endblock %} +{% block title %}{% blocktrans with book_title=work|book_title %}Editions of {{ book_title }}{% endblocktrans %}{% endblock %} {% block content %}
-

{% blocktrans with work_path=work.local_path work_title=work.title %}Editions of "{{ work_title }}"{% endblocktrans %}

+

{% blocktrans with work_path=work.local_path work_title=work|book_title %}Editions of "{{ work_title }}"{% endblocktrans %}

{% include 'book/edition_filters.html' %} @@ -22,7 +22,7 @@

- {{ book.title }} + {{ book|book_title }}

diff --git a/bookwyrm/templates/book/format_filter.html b/bookwyrm/templates/book/format_filter.html index c722b24f..f8636522 100644 --- a/bookwyrm/templates/book/format_filter.html +++ b/bookwyrm/templates/book/format_filter.html @@ -1,5 +1,5 @@ {% extends 'snippets/filters_panel/filter_field.html' %} -{% load i18n %} +{% load i18n %}{% load utilities %} {% block filter %} @@ -8,7 +8,7 @@ {% for format in formats %}{% if format %} {% endif %}{% endfor %} diff --git a/bookwyrm/templates/directory/directory.html b/bookwyrm/templates/directory/directory.html index f97a8481..88a7b15c 100644 --- a/bookwyrm/templates/directory/directory.html +++ b/bookwyrm/templates/directory/directory.html @@ -49,7 +49,3 @@
{% endblock %} - -{% block scripts %} - -{% endblock %} diff --git a/bookwyrm/templates/layout.html b/bookwyrm/templates/layout.html index 3a4fd6c8..2f8001dd 100644 --- a/bookwyrm/templates/layout.html +++ b/bookwyrm/templates/layout.html @@ -1,5 +1,4 @@ -{% load layout %} -{% load i18n %} +{% load layout %}{% load i18n %} @@ -182,6 +181,15 @@ +{% if active_announcements.exists %} +
+
+ {% for announcement in active_announcements %} + {% include 'snippets/announcement.html' with announcement=announcement %} + {% endfor %} +
+
+{% endif %}
@@ -230,6 +238,7 @@ var csrf_token = '{{ csrf_token }}'; + {% block scripts %}{% endblock %} diff --git a/bookwyrm/templates/search/book.html b/bookwyrm/templates/search/book.html index 08e1dad2..ce907219 100644 --- a/bookwyrm/templates/search/book.html +++ b/bookwyrm/templates/search/book.html @@ -28,9 +28,9 @@
{% trans "Open" as button_text %} - {% include 'snippets/toggle/open_button.html' with text=button_text small=True controls_text="more-results-panel" controls_uid=result_set.connector.identifier class="is-small" icon_with_text="arrow-down" pressed=forloop.first %} + {% include 'snippets/toggle/open_button.html' with text=button_text controls_text="more-results-panel" controls_uid=result_set.connector.identifier class="is-small" icon_with_text="arrow-down" pressed=forloop.first %} {% trans "Close" as button_text %} - {% include 'snippets/toggle/close_button.html' with text=button_text small=True controls_text="more-results-panel" controls_uid=result_set.connector.identifier class="is-small" icon_with_text="arrow-up" pressed=forloop.first %} + {% include 'snippets/toggle/close_button.html' with text=button_text controls_text="more-results-panel" controls_uid=result_set.connector.identifier class="is-small" icon_with_text="arrow-up" pressed=forloop.first %}
{% endif %} diff --git a/bookwyrm/templates/settings/admin_layout.html b/bookwyrm/templates/settings/admin_layout.html index 4f71a228..635e8607 100644 --- a/bookwyrm/templates/settings/admin_layout.html +++ b/bookwyrm/templates/settings/admin_layout.html @@ -43,6 +43,10 @@ {% if perms.bookwyrm.edit_instance_settings %}