mirror of
https://github.com/bookwyrm-social/bookwyrm.git
synced 2024-11-26 19:41:11 +00:00
Create announcements admin view
This commit is contained in:
parent
d1f2d9812f
commit
515d5bb237
7 changed files with 186 additions and 0 deletions
|
@ -269,6 +269,12 @@ class SiteForm(CustomForm):
|
||||||
exclude = []
|
exclude = []
|
||||||
|
|
||||||
|
|
||||||
|
class AnnouncementForm(CustomForm):
|
||||||
|
class Meta:
|
||||||
|
model = models.Announcement
|
||||||
|
exclude = ["remote_id"]
|
||||||
|
|
||||||
|
|
||||||
class ListForm(CustomForm):
|
class ListForm(CustomForm):
|
||||||
class Meta:
|
class Meta:
|
||||||
model = models.List
|
model = models.List
|
||||||
|
|
|
@ -43,6 +43,10 @@
|
||||||
{% if perms.bookwyrm.edit_instance_settings %}
|
{% if perms.bookwyrm.edit_instance_settings %}
|
||||||
<h2 class="menu-label">{% trans "Instance Settings" %}</h2>
|
<h2 class="menu-label">{% trans "Instance Settings" %}</h2>
|
||||||
<ul class="menu-list">
|
<ul class="menu-list">
|
||||||
|
<li>
|
||||||
|
{% url 'settings-announcements' as url %}
|
||||||
|
<a href="{{ url }}"{% if url in request.path %} class="is-active" aria-selected="true"{% endif %}>{% trans "Announcements" %}</a>
|
||||||
|
</li>
|
||||||
<li>
|
<li>
|
||||||
{% url 'settings-site' as url %}
|
{% url 'settings-site' as url %}
|
||||||
<a href="{{ url }}"{% if url in request.path %} class="is-active" aria-selected="true"{% endif %}>{% trans "Site Settings" %}</a>
|
<a href="{{ url }}"{% if url in request.path %} class="is-active" aria-selected="true"{% endif %}>{% trans "Site Settings" %}</a>
|
||||||
|
|
80
bookwyrm/templates/settings/announcement_form.html
Normal file
80
bookwyrm/templates/settings/announcement_form.html
Normal file
|
@ -0,0 +1,80 @@
|
||||||
|
{% extends 'components/inline_form.html' %}
|
||||||
|
{% load i18n %}
|
||||||
|
|
||||||
|
{% block header %}
|
||||||
|
{% trans "Create Announcement" %}
|
||||||
|
{% endblock %}
|
||||||
|
|
||||||
|
{% block form %}
|
||||||
|
<form name="create-announcement" method="post" action="{% url 'settings-announcements' %}">
|
||||||
|
<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 %}
|
||||||
|
<p class="help is-danger">{{ error | escape }}</p>
|
||||||
|
{% endfor %}
|
||||||
|
</p>
|
||||||
|
<div class="columns">
|
||||||
|
<div class="column">
|
||||||
|
<p>
|
||||||
|
<label class="label" for="id_start_date">Start date:</label>
|
||||||
|
<input type="date" name="start_date" class="input" id="id_start_date">
|
||||||
|
{% for error in form.start_date.errors %}
|
||||||
|
<p class="help is-danger">{{ error | escape }}</p>
|
||||||
|
{% endfor %}
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
<div class="column">
|
||||||
|
<p>
|
||||||
|
<label class="label" for="id_end_date">End date:</label>
|
||||||
|
<input type="date" name="end_date" class="input" id="id_end_date">
|
||||||
|
{% for error in form.end_date.errors %}
|
||||||
|
<p class="help is-danger">{{ error | escape }}</p>
|
||||||
|
{% endfor %}
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
<div class="column is-narrow">
|
||||||
|
<p>
|
||||||
|
<label class="label" for="id_active">Active:</label>
|
||||||
|
{{ form.active }}
|
||||||
|
{% for error in form.active.errors %}
|
||||||
|
<p class="help is-danger">{{ error | escape }}</p>
|
||||||
|
{% endfor %}
|
||||||
|
</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">
|
||||||
|
<button type="submit" class="button is-primary">{% trans "Save" %}</button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</form>
|
||||||
|
{% endblock %}
|
||||||
|
|
49
bookwyrm/templates/settings/announcements.html
Normal file
49
bookwyrm/templates/settings/announcements.html
Normal file
|
@ -0,0 +1,49 @@
|
||||||
|
{% extends 'settings/admin_layout.html' %}
|
||||||
|
{% load i18n %}{% load humanize %}
|
||||||
|
{% block title %}{% trans "Announcements" %}{% endblock %}
|
||||||
|
|
||||||
|
{% block header %}{% trans "Announcements" %}{% endblock %}
|
||||||
|
|
||||||
|
{% block edit-button %}
|
||||||
|
{% trans "Create Announcement" as button_text %}
|
||||||
|
{% include 'snippets/toggle/open_button.html' with controls_text="create-announcement" icon_with_text="plus" text=button_text focus="create-announcement-header" %}
|
||||||
|
</a>
|
||||||
|
{% endblock %}
|
||||||
|
|
||||||
|
{% block panel %}
|
||||||
|
<div class="block">
|
||||||
|
{% include 'settings/announcement_form.html' with controls_text="create-announcement" %}
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<table class="table is-striped">
|
||||||
|
<tr>
|
||||||
|
{% url 'settings-announcements' as url %}
|
||||||
|
<th>
|
||||||
|
{% trans "Name" as text %}
|
||||||
|
{% include 'snippets/table-sort-header.html' with field="name" sort=sort text=text %}
|
||||||
|
</th>
|
||||||
|
<th>
|
||||||
|
{% trans "Start date" as text %}
|
||||||
|
{% include 'snippets/table-sort-header.html' with field="start_date" sort=sort text=text %}
|
||||||
|
</th>
|
||||||
|
<th>
|
||||||
|
{% trans "End date" as text %}
|
||||||
|
{% include 'snippets/table-sort-header.html' with field="end_date" sort=sort text=text %}
|
||||||
|
</th>
|
||||||
|
<th>
|
||||||
|
{% trans "Status" as text %}
|
||||||
|
{% include 'snippets/table-sort-header.html' with field="active" sort=sort text=text %}
|
||||||
|
</th>
|
||||||
|
</tr>
|
||||||
|
{% for announcement in announcements %}
|
||||||
|
<tr>
|
||||||
|
<td><a href="{% url 'settings-announcements' announcement.id %}">{{ announcement.name }}</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>
|
||||||
|
</tr>
|
||||||
|
{% endfor %}
|
||||||
|
</table>
|
||||||
|
|
||||||
|
{% include 'snippets/pagination.html' with page=servers path=request.path %}
|
||||||
|
{% endblock %}
|
|
@ -56,6 +56,16 @@ urlpatterns = [
|
||||||
),
|
),
|
||||||
# admin
|
# admin
|
||||||
re_path(r"^settings/site-settings/?$", views.Site.as_view(), name="settings-site"),
|
re_path(r"^settings/site-settings/?$", views.Site.as_view(), name="settings-site"),
|
||||||
|
re_path(
|
||||||
|
r"^settings/announcements/?$",
|
||||||
|
views.Announcements.as_view(),
|
||||||
|
name="settings-announcements",
|
||||||
|
),
|
||||||
|
re_path(
|
||||||
|
r"^settings/announcements/(?P<announcement_id>\d+)/??$",
|
||||||
|
views.Announcements.as_view(),
|
||||||
|
name="settings-announcements",
|
||||||
|
),
|
||||||
re_path(
|
re_path(
|
||||||
r"^settings/email-preview/?$",
|
r"^settings/email-preview/?$",
|
||||||
views.site.email_preview,
|
views.site.email_preview,
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
""" make sure all our nice views are available """
|
""" make sure all our nice views are available """
|
||||||
|
from .announcements import Announcements
|
||||||
from .authentication import Login, Register, Logout
|
from .authentication import Login, Register, Logout
|
||||||
from .author import Author, EditAuthor
|
from .author import Author, EditAuthor
|
||||||
from .block import Block, unblock
|
from .block import Block, unblock
|
||||||
|
|
36
bookwyrm/views/announcements.py
Normal file
36
bookwyrm/views/announcements.py
Normal file
|
@ -0,0 +1,36 @@
|
||||||
|
""" make announcements """
|
||||||
|
from django.contrib.auth.decorators import login_required, permission_required
|
||||||
|
from django.template.response import TemplateResponse
|
||||||
|
from django.utils.decorators import method_decorator
|
||||||
|
from django.views import View
|
||||||
|
|
||||||
|
from bookwyrm import forms, models
|
||||||
|
|
||||||
|
|
||||||
|
# pylint: disable= no-self-use
|
||||||
|
@method_decorator(login_required, name="dispatch")
|
||||||
|
@method_decorator(
|
||||||
|
permission_required("bookwyrm.edit_instance_settings", raise_exception=True),
|
||||||
|
name="dispatch",
|
||||||
|
)
|
||||||
|
class Announcements(View):
|
||||||
|
"""tell everyone"""
|
||||||
|
|
||||||
|
def get(self, request):
|
||||||
|
"""view and create announcements"""
|
||||||
|
data = {
|
||||||
|
"announcements": models.Announcement.objects.all(),
|
||||||
|
"form": forms.AnnouncementForm(),
|
||||||
|
}
|
||||||
|
return TemplateResponse(request, "settings/announcements.html", data)
|
||||||
|
|
||||||
|
def post(self, request):
|
||||||
|
"""edit the site settings"""
|
||||||
|
form = forms.AnnouncementForm(request.POST)
|
||||||
|
if form.is_valid():
|
||||||
|
form.save()
|
||||||
|
data = {
|
||||||
|
"announcements": models.Announcement.objects.all(),
|
||||||
|
"form": forms.AnnouncementForm(),
|
||||||
|
}
|
||||||
|
return TemplateResponse(request, "settings/announcements.html", data)
|
Loading…
Reference in a new issue