forked from mirrors/bookwyrm
Adds admin view for individual announcement
This commit is contained in:
parent
c73c063949
commit
d64e0c4aa8
11 changed files with 92 additions and 32 deletions
|
@ -8,7 +8,7 @@
|
||||||
<option value="">{% trans "Any" %}</option>
|
<option value="">{% trans "Any" %}</option>
|
||||||
{% for format in formats %}{% if format %}
|
{% for format in formats %}{% if format %}
|
||||||
<option value="{{ format }}" {% if request.GET.format == format %}selected{% endif %}>
|
<option value="{{ format }}" {% if request.GET.format == format %}selected{% endif %}>
|
||||||
{{ format|title }}
|
{{ format|book_title }}
|
||||||
</option>
|
</option>
|
||||||
{% endif %}{% endfor %}
|
{% endif %}{% endfor %}
|
||||||
</select>
|
</select>
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
{% load layout %}{% load i18n %}{% load humanize %}
|
{% load layout %}{% load i18n %}
|
||||||
<!DOCTYPE html>
|
<!DOCTYPE html>
|
||||||
<html lang="{% get_lang %}">
|
<html lang="{% get_lang %}">
|
||||||
<head>
|
<head>
|
||||||
|
@ -185,25 +185,7 @@
|
||||||
<div class="block is-flex-grow-1">
|
<div class="block is-flex-grow-1">
|
||||||
<div class="container">
|
<div class="container">
|
||||||
{% for announcement in active_announcements %}
|
{% for announcement in active_announcements %}
|
||||||
<div class="notification p-3">
|
{% include 'snippets/announcement.html' with announcement=announcement %}
|
||||||
<div class="columns mb-0">
|
|
||||||
<div class="column">
|
|
||||||
{% if announcement.event_date %}
|
|
||||||
<strong>{{ announcement.event_date|naturalday|title }}:</strong>
|
|
||||||
{% endif %}
|
|
||||||
{{ announcement.preview }}
|
|
||||||
</div>
|
|
||||||
<div class="column is-narrow">
|
|
||||||
{% trans "Open" as button_text %}
|
|
||||||
{% include 'snippets/toggle/open_button.html' with text=button_text controls_text="announcement" class="is-small" controls_uid=announcement.id icon_with_text="arrow-down" %}
|
|
||||||
{% trans "Close" as button_text %}
|
|
||||||
{% include 'snippets/toggle/close_button.html' with text=button_text controls_text="announcement" class="is-small" controls_uid=announcement.id icon_with_text="arrow-up" %}
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
<div class="box is-shadowless m-0 is-hidden" id="announcement-{{ announcement.id }}">
|
|
||||||
{{ announcement.content|safe }}
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
23
bookwyrm/templates/settings/announcement.html
Normal file
23
bookwyrm/templates/settings/announcement.html
Normal file
|
@ -0,0 +1,23 @@
|
||||||
|
{% extends 'settings/admin_layout.html' %}
|
||||||
|
{% load i18n %}
|
||||||
|
{% block title %}{% trans "Announcement" %} - {{ announcement.preview }}{% endblock %}
|
||||||
|
|
||||||
|
{% block header %}{% trans "Announcement" %}{% endblock %}
|
||||||
|
|
||||||
|
{% block edit-button %}
|
||||||
|
{% trans "Edit 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>
|
||||||
|
|
||||||
|
<div class="block content">
|
||||||
|
{% include 'snippets/announcement.html' with announcement=announcement pressed=True %}
|
||||||
|
</div>
|
||||||
|
|
||||||
|
{% endblock %}
|
|
@ -45,5 +45,5 @@
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
</table>
|
</table>
|
||||||
|
|
||||||
{% include 'snippets/pagination.html' with page=servers path=request.path %}
|
{% include 'snippets/pagination.html' with page=announcements path=request.path %}
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
|
22
bookwyrm/templates/snippets/announcement.html
Normal file
22
bookwyrm/templates/snippets/announcement.html
Normal file
|
@ -0,0 +1,22 @@
|
||||||
|
{% load humanize %}{% load i18n %}{% load utilities %}
|
||||||
|
{% with announcement.id|uuid as uuid %}
|
||||||
|
<aside class="notification p-3">
|
||||||
|
<div class="columns mb-0">
|
||||||
|
<div class="column">
|
||||||
|
{% if announcement.event_date %}
|
||||||
|
<strong>{{ announcement.event_date|naturalday|title }}:</strong>
|
||||||
|
{% endif %}
|
||||||
|
{{ announcement.preview }}
|
||||||
|
</div>
|
||||||
|
<div class="column is-narrow">
|
||||||
|
{% trans "Open" as button_text %}
|
||||||
|
{% include 'snippets/toggle/open_button.html' with text=button_text controls_text="announcement" class="is-small" controls_uid=uuid icon_with_text="arrow-down" %}
|
||||||
|
{% trans "Close" as button_text %}
|
||||||
|
{% include 'snippets/toggle/close_button.html' with text=button_text controls_text="announcement" class="is-small" controls_uid=uuid icon_with_text="arrow-up" %}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="box is-shadowless m-0{% if not pressed %} is-hidden{% endif %}" id="announcement-{{ uuid }}">
|
||||||
|
{{ announcement.content|safe }}
|
||||||
|
</div>
|
||||||
|
</aside>
|
||||||
|
{% endwith %}
|
|
@ -1,8 +1,8 @@
|
||||||
{% load i18n %}
|
{% load i18n %}
|
||||||
{% load utilities %}
|
{% load utilities %}
|
||||||
{% if book.authors %}
|
{% if book.authors %}
|
||||||
{% blocktrans with path=book.local_path title=book|title %}<a href="{{ path }}">{{ title }}</a> by {% endblocktrans %}{% include 'snippets/authors.html' with book=book %}
|
{% blocktrans with path=book.local_path title=book|book_title %}<a href="{{ path }}">{{ title }}</a> by {% endblocktrans %}{% include 'snippets/authors.html' with book=book %}
|
||||||
{% else %}
|
{% else %}
|
||||||
<a href="{{ book.local_path }}">{{ book|title }}</a>
|
<a href="{{ book.local_path }}">{{ book|book_title }}</a>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
|
||||||
|
|
|
@ -48,7 +48,7 @@
|
||||||
|
|
||||||
{% if status.book %}
|
{% if status.book %}
|
||||||
{% if status.status_type == 'GeneratedNote' or status.status_type == 'Rating' %}
|
{% if status.status_type == 'GeneratedNote' or status.status_type == 'Rating' %}
|
||||||
<a href="{{ status.book.local_path }}">{{ status.book|title }}</a>{% if status.status_type == 'Rating' %}: {% include 'snippets/stars.html' with rating=status.rating %}
|
<a href="{{ status.book.local_path }}">{{ status.book|book_title }}</a>{% if status.status_type == 'Rating' %}: {% include 'snippets/stars.html' with rating=status.rating %}
|
||||||
<span
|
<span
|
||||||
itemprop="reviewRating"
|
itemprop="reviewRating"
|
||||||
itemscope
|
itemscope
|
||||||
|
@ -59,7 +59,7 @@
|
||||||
|
|
||||||
{% if status.book %}
|
{% if status.book %}
|
||||||
{% if status.status_type == 'GeneratedNote' or status.status_type == 'Rating' %}
|
{% if status.status_type == 'GeneratedNote' or status.status_type == 'Rating' %}
|
||||||
<a href="{{ status.book.local_path }}">{{ status.book|title }}</a>{% if status.status_type == 'Rating' %}:
|
<a href="{{ status.book.local_path }}">{{ status.book|book_title }}</a>{% if status.status_type == 'Rating' %}:
|
||||||
<span
|
<span
|
||||||
itemprop="reviewRating"
|
itemprop="reviewRating"
|
||||||
itemscope
|
itemscope
|
||||||
|
@ -78,7 +78,7 @@
|
||||||
{% endif %}
|
{% endif %}
|
||||||
{% elif status.mention_books %}
|
{% elif status.mention_books %}
|
||||||
<a href="{{ status.mention_books.first.local_path }}">
|
<a href="{{ status.mention_books.first.local_path }}">
|
||||||
{{ status.mention_books.first.title }}
|
{{ status.mention_books.first|book_title }}
|
||||||
</a>
|
</a>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
{% include 'snippets/stars.html' with rating=status.rating %}
|
{% include 'snippets/stars.html' with rating=status.rating %}
|
||||||
|
@ -87,7 +87,7 @@
|
||||||
{% include 'snippets/book_titleby.html' with book=status.book %}
|
{% include 'snippets/book_titleby.html' with book=status.book %}
|
||||||
{% endif %}
|
{% endif %}
|
||||||
{% elif status.mention_books %}
|
{% elif status.mention_books %}
|
||||||
<a href="{{ status.mention_books.first.local_path }}">{{ status.mention_books.first|title }}</a>
|
<a href="{{ status.mention_books.first.local_path }}">{{ status.mention_books.first|book_title }}</a>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
|
||||||
</h3>
|
</h3>
|
||||||
|
|
|
@ -18,7 +18,7 @@ def get_user_identifier(user):
|
||||||
return user.localname if user.localname else user.username
|
return user.localname if user.localname else user.username
|
||||||
|
|
||||||
|
|
||||||
@register.filter(name="title")
|
@register.filter(name="book_title")
|
||||||
def get_title(book):
|
def get_title(book):
|
||||||
"""display the subtitle if the title is short"""
|
"""display the subtitle if the title is short"""
|
||||||
if not book:
|
if not book:
|
||||||
|
|
|
@ -63,7 +63,7 @@ urlpatterns = [
|
||||||
),
|
),
|
||||||
re_path(
|
re_path(
|
||||||
r"^settings/announcements/(?P<announcement_id>\d+)/??$",
|
r"^settings/announcements/(?P<announcement_id>\d+)/??$",
|
||||||
views.Announcements.as_view(),
|
views.Announcement.as_view(),
|
||||||
name="settings-announcements",
|
name="settings-announcements",
|
||||||
),
|
),
|
||||||
re_path(
|
re_path(
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
""" make sure all our nice views are available """
|
""" make sure all our nice views are available """
|
||||||
from .announcements import Announcements
|
from .announcements import Announcements, Announcement
|
||||||
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
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
""" make announcements """
|
""" make announcements """
|
||||||
from django.contrib.auth.decorators import login_required, permission_required
|
from django.contrib.auth.decorators import login_required, permission_required
|
||||||
|
from django.shortcuts import get_object_or_404
|
||||||
from django.template.response import TemplateResponse
|
from django.template.response import TemplateResponse
|
||||||
from django.utils.decorators import method_decorator
|
from django.utils.decorators import method_decorator
|
||||||
from django.views import View
|
from django.views import View
|
||||||
|
@ -29,8 +30,40 @@ class Announcements(View):
|
||||||
form = forms.AnnouncementForm(request.POST)
|
form = forms.AnnouncementForm(request.POST)
|
||||||
if form.is_valid():
|
if form.is_valid():
|
||||||
form.save()
|
form.save()
|
||||||
|
# reset the create form
|
||||||
|
form = forms.AnnouncementForm()
|
||||||
data = {
|
data = {
|
||||||
"announcements": models.Announcement.objects.all(),
|
"announcements": models.Announcement.objects.all(),
|
||||||
"form": forms.AnnouncementForm(),
|
"form": form,
|
||||||
}
|
}
|
||||||
return TemplateResponse(request, "settings/announcements.html", data)
|
return TemplateResponse(request, "settings/announcements.html", data)
|
||||||
|
|
||||||
|
|
||||||
|
@method_decorator(login_required, name="dispatch")
|
||||||
|
@method_decorator(
|
||||||
|
permission_required("bookwyrm.edit_instance_settings", raise_exception=True),
|
||||||
|
name="dispatch",
|
||||||
|
)
|
||||||
|
class Announcement(View):
|
||||||
|
"""delete or edit an announcement"""
|
||||||
|
|
||||||
|
def get(self, request, announcement_id):
|
||||||
|
"""view announcement"""
|
||||||
|
announcement = get_object_or_404(models.Announcement, id=announcement_id)
|
||||||
|
data = {
|
||||||
|
"announcement": announcement,
|
||||||
|
"form": forms.AnnouncementForm(instance=announcement),
|
||||||
|
}
|
||||||
|
return TemplateResponse(request, "settings/announcement.html", data)
|
||||||
|
|
||||||
|
def post(self, request, announcement_id):
|
||||||
|
"""edit the site settings"""
|
||||||
|
announcement = get_object_or_404(models.Announcement, id=announcement_id)
|
||||||
|
form = forms.AnnouncementForm(request.POST, instance=announcement)
|
||||||
|
if form.is_valid():
|
||||||
|
form.save()
|
||||||
|
data = {
|
||||||
|
"announcements": models.Announcement.objects.all(),
|
||||||
|
"form": form,
|
||||||
|
}
|
||||||
|
return TemplateResponse(request, "settings/announcement.html", data)
|
||||||
|
|
Loading…
Reference in a new issue