mirror of
https://github.com/bookwyrm-social/bookwyrm.git
synced 2024-11-23 01:51:08 +00:00
Makes extra content optional
This commit is contained in:
parent
952eceb243
commit
cefc5994a6
5 changed files with 81 additions and 6 deletions
|
@ -1,4 +1,4 @@
|
||||||
# Generated by Django 3.2 on 2021-05-19 22:16
|
# Generated by Django 3.2 on 2021-05-20 19:34
|
||||||
|
|
||||||
import bookwyrm.models.fields
|
import bookwyrm.models.fields
|
||||||
from django.conf import settings
|
from django.conf import settings
|
||||||
|
@ -36,7 +36,7 @@ class Migration(migrations.Migration):
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
("preview", models.CharField(max_length=255)),
|
("preview", models.CharField(max_length=255)),
|
||||||
("content", models.TextField()),
|
("content", models.TextField(blank=True, null=True)),
|
||||||
("event_date", models.DateTimeField(blank=True, null=True)),
|
("event_date", models.DateTimeField(blank=True, null=True)),
|
||||||
("start_date", models.DateTimeField(blank=True, null=True)),
|
("start_date", models.DateTimeField(blank=True, null=True)),
|
||||||
("end_date", models.DateTimeField(blank=True, null=True)),
|
("end_date", models.DateTimeField(blank=True, null=True)),
|
||||||
|
|
|
@ -11,7 +11,7 @@ class Announcement(BookWyrmModel):
|
||||||
|
|
||||||
user = models.ForeignKey("User", on_delete=models.PROTECT)
|
user = models.ForeignKey("User", on_delete=models.PROTECT)
|
||||||
preview = models.CharField(max_length=255)
|
preview = models.CharField(max_length=255)
|
||||||
content = models.TextField()
|
content = models.TextField(null=True, blank=True)
|
||||||
event_date = models.DateTimeField(blank=True, null=True)
|
event_date = models.DateTimeField(blank=True, null=True)
|
||||||
start_date = models.DateTimeField(blank=True, null=True)
|
start_date = models.DateTimeField(blank=True, null=True)
|
||||||
end_date = models.DateTimeField(blank=True, null=True)
|
end_date = models.DateTimeField(blank=True, null=True)
|
||||||
|
|
|
@ -11,18 +11,22 @@
|
||||||
{% endif %}
|
{% endif %}
|
||||||
{{ announcement.preview }}
|
{{ announcement.preview }}
|
||||||
</div>
|
</div>
|
||||||
|
{% if announcement.content %}
|
||||||
<div class="column is-narrow pb-0">
|
<div class="column is-narrow pb-0">
|
||||||
{% trans "Open" as button_text %}
|
{% 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" %}
|
{% 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 %}
|
{% 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" %}
|
{% 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>
|
||||||
|
{% endif %}
|
||||||
</div>
|
</div>
|
||||||
|
{% if announcement.content %}
|
||||||
<div class="mb-2 mt-2 {% if not pressed %}is-hidden{% endif %}" id="announcement-{{ uuid }}">
|
<div class="mb-2 mt-2 {% if not pressed %}is-hidden{% endif %}" id="announcement-{{ uuid }}">
|
||||||
<div class="box is-shadowless mb-0">
|
<div class="box is-shadowless mb-0">
|
||||||
{{ announcement.content|safe }}
|
{{ announcement.content|safe }}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
{% endif %}
|
||||||
<div class="is-flex mt-0 help">
|
<div class="is-flex mt-0 help">
|
||||||
<p>{% blocktrans with user_path=announcement.user.local_path username=announcement.user.display_name %}Posted by <a href="{{ user_path }}">{{ username }}</a>{% endblocktrans %}</p>
|
<p>{% blocktrans with user_path=announcement.user.local_path username=announcement.user.display_name %}Posted by <a href="{{ user_path }}">{{ username }}</a>{% endblocktrans %}</p>
|
||||||
{% if not admin_mode %}
|
{% if not admin_mode %}
|
||||||
|
|
|
@ -51,9 +51,11 @@ class AnnouncementViews(TestCase):
|
||||||
|
|
||||||
def test_announcement_page(self):
|
def test_announcement_page(self):
|
||||||
"""there are so many views, this just makes sure it LOADS"""
|
"""there are so many views, this just makes sure it LOADS"""
|
||||||
announcement = models.Announcement.objects.create(preview="hi", user=self.local_user)
|
announcement = models.Announcement.objects.create(
|
||||||
|
preview="hi", user=self.local_user
|
||||||
|
)
|
||||||
|
|
||||||
view = views.Announcements.as_view()
|
view = views.Announcement.as_view()
|
||||||
request = self.factory.get("")
|
request = self.factory.get("")
|
||||||
request.user = self.local_user
|
request.user = self.local_user
|
||||||
request.user.is_superuser = True
|
request.user.is_superuser = True
|
||||||
|
@ -63,3 +65,72 @@ class AnnouncementViews(TestCase):
|
||||||
self.assertIsInstance(result, TemplateResponse)
|
self.assertIsInstance(result, TemplateResponse)
|
||||||
result.render()
|
result.render()
|
||||||
self.assertEqual(result.status_code, 200)
|
self.assertEqual(result.status_code, 200)
|
||||||
|
|
||||||
|
def test_create_announcement(self):
|
||||||
|
"""create a new announcement"""
|
||||||
|
view = views.Announcements.as_view()
|
||||||
|
form = forms.AnnouncementForm()
|
||||||
|
form.data["preview"] = "hi hi"
|
||||||
|
form.data["start_date"] = "2021-05-20"
|
||||||
|
form.data["user"] = self.local_user.id
|
||||||
|
|
||||||
|
request = self.factory.post("", form.data)
|
||||||
|
request.user = self.local_user
|
||||||
|
request.user.is_superuser = True
|
||||||
|
|
||||||
|
view(request)
|
||||||
|
|
||||||
|
announcement = models.Announcement.objects.get()
|
||||||
|
self.assertEqual(announcement.preview, "hi hi")
|
||||||
|
self.assertEqual(announcement.start_date.year, 2021)
|
||||||
|
self.assertEqual(announcement.start_date.month, 5)
|
||||||
|
self.assertEqual(announcement.start_date.day, 20)
|
||||||
|
|
||||||
|
def test_edit_announcement(self):
|
||||||
|
"""edit an announcement"""
|
||||||
|
announcement = models.Announcement.objects.create(
|
||||||
|
preview="hi", user=self.local_user
|
||||||
|
)
|
||||||
|
view = views.Announcement.as_view()
|
||||||
|
form = forms.AnnouncementForm(instance=announcement)
|
||||||
|
form.data["preview"] = "hi hi"
|
||||||
|
form.data["start_date"] = "2021-05-20"
|
||||||
|
form.data["user"] = self.local_user.id
|
||||||
|
|
||||||
|
request = self.factory.post("", form.data)
|
||||||
|
request.user = self.local_user
|
||||||
|
request.user.is_superuser = True
|
||||||
|
|
||||||
|
view(request, announcement.id)
|
||||||
|
|
||||||
|
announcement.refresh_from_db()
|
||||||
|
self.assertEqual(announcement.preview, "hi hi")
|
||||||
|
self.assertEqual(announcement.start_date.year, 2021)
|
||||||
|
self.assertEqual(announcement.start_date.month, 5)
|
||||||
|
self.assertEqual(announcement.start_date.day, 20)
|
||||||
|
|
||||||
|
def test_delete_announcement(self):
|
||||||
|
"""delete an announcement"""
|
||||||
|
announcement = models.Announcement.objects.create(
|
||||||
|
preview="hi", user=self.local_user
|
||||||
|
)
|
||||||
|
view = views.delete_announcement.as_view()
|
||||||
|
|
||||||
|
request = self.factory.post("")
|
||||||
|
request.user = self.local_user
|
||||||
|
request.user.is_superuser = True
|
||||||
|
|
||||||
|
view(request, announcement.id)
|
||||||
|
|
||||||
|
self.assertFalse(models.Announcement.objects.exists())
|
||||||
|
|
||||||
|
def test_view_announcement(self):
|
||||||
|
"""display announcement on other pages"""
|
||||||
|
view = views.User.as_view()
|
||||||
|
request = self.factory.get("")
|
||||||
|
|
||||||
|
result = view(request)
|
||||||
|
|
||||||
|
self.assertIsInstance(result, TemplateResponse)
|
||||||
|
result.render()
|
||||||
|
self.assertEqual(result.status_code, 200)
|
||||||
|
|
|
@ -51,7 +51,7 @@ class Announcements(View):
|
||||||
form = forms.AnnouncementForm()
|
form = forms.AnnouncementForm()
|
||||||
data = {
|
data = {
|
||||||
"announcements": Paginator(
|
"announcements": Paginator(
|
||||||
models.Announcement.objects, PAGE_LENGTH
|
models.Announcement.objects.all(), PAGE_LENGTH
|
||||||
).get_page(request.GET.get("page")),
|
).get_page(request.GET.get("page")),
|
||||||
"form": form,
|
"form": form,
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue