mirror of
https://github.com/bookwyrm-social/bookwyrm.git
synced 2024-11-25 19:11:09 +00:00
Adds model for instance admin announcements
This commit is contained in:
parent
3b295a724e
commit
d1f2d9812f
5 changed files with 86 additions and 2 deletions
|
@ -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)
|
||||||
|
|
|
@ -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(),
|
||||||
|
}
|
||||||
|
|
57
bookwyrm/migrations/0075_announcement.py
Normal file
57
bookwyrm/migrations/0075_announcement.py
Normal 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,
|
||||||
|
},
|
||||||
|
),
|
||||||
|
]
|
|
@ -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 = {
|
||||||
|
|
24
bookwyrm/models/announcement.py
Normal file
24
bookwyrm/models/announcement.py
Normal 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)
|
Loading…
Reference in a new issue