Adds model for instance admin announcements

This commit is contained in:
Mouse Reeve 2021-05-19 13:56:00 -07:00
parent 3b295a724e
commit d1f2d9812f
5 changed files with 86 additions and 2 deletions

View file

@ -2,7 +2,6 @@
from django.contrib import admin from django.contrib import admin
from bookwyrm import models from bookwyrm import models
admin.site.register(models.SiteSettings)
admin.site.register(models.User) admin.site.register(models.User)
admin.site.register(models.FederatedServer) admin.site.register(models.FederatedServer)
admin.site.register(models.Connector) admin.site.register(models.Connector)

View file

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

View file

@ -0,0 +1,57 @@
# Generated by Django 3.2 on 2021-05-19 20:58
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],
),
),
("name", models.CharField(max_length=255)),
("preview", models.CharField(max_length=255)),
("content", models.TextField()),
("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,
},
),
]

View file

@ -25,6 +25,7 @@ from .federated_server import FederatedServer
from .import_job import ImportJob, ImportItem from .import_job import ImportJob, ImportItem
from .site import SiteSettings, SiteInvite, PasswordReset, InviteRequest from .site import SiteSettings, SiteInvite, PasswordReset, InviteRequest
from .announcement import Announcement
cls_members = inspect.getmembers(sys.modules[__name__], inspect.isclass) cls_members = inspect.getmembers(sys.modules[__name__], inspect.isclass)
activity_models = { activity_models = {

View file

@ -0,0 +1,24 @@
""" admin announcements """
from django.db import models
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)
name = models.CharField(max_length=255)
preview = models.CharField(max_length=255)
content = models.TextField()
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(active=True, start_date__lte=now, end_date__gte=now)