Compare commits
17 commits
Author | SHA1 | Date | |
---|---|---|---|
|
812fc0f2a4 | ||
|
8dc69f2a9e | ||
|
cda4b61b4b | ||
|
56094b9e7e | ||
|
507d6d3508 | ||
|
5ce0a679fb | ||
|
e814c9f981 | ||
|
da58002f2f | ||
|
60451f565a | ||
|
2e0bcb1c01 | ||
|
16561eba6f | ||
|
9a355ff2a0 | ||
|
1864761a47 | ||
|
cd42612596 | ||
|
c8fc3b4c45 | ||
|
e8bebca7b4 | ||
![]() |
d57c44cc85 |
|
@ -131,6 +131,7 @@ class Blog(admin.ModelAdmin):
|
|||
"active",
|
||||
)
|
||||
ordering = ["approved", "-suspended", "-failing"]
|
||||
search_fields = ["title", "author_name", "url"]
|
||||
actions = [approve, unapprove, suspend, unsuspend, activate, disable]
|
||||
|
||||
|
||||
|
@ -140,6 +141,7 @@ class Article(admin.ModelAdmin):
|
|||
|
||||
date_hierarchy = "pubdate"
|
||||
list_display = ("title", "blog_title", "pubdate")
|
||||
search_fields = ["title", "author_name", "blog_title", "url"]
|
||||
|
||||
def blog_title(self, obj): # pylint: disable=no-self-use
|
||||
"""get the title of the parent blog"""
|
||||
|
@ -151,6 +153,7 @@ class Tag(admin.ModelAdmin):
|
|||
"""display settings for tags"""
|
||||
|
||||
list_display = ("name",)
|
||||
search_fields = ["name"]
|
||||
|
||||
|
||||
@admin.register(models.Event)
|
||||
|
@ -166,6 +169,7 @@ class Event(admin.ModelAdmin):
|
|||
"start_date",
|
||||
)
|
||||
ordering = ["approved", "announcements"]
|
||||
search_fields = ["name", "description", "url"]
|
||||
actions = [approve, unapprove]
|
||||
|
||||
|
||||
|
@ -176,6 +180,7 @@ class CallForPapers(admin.ModelAdmin):
|
|||
list_display = ("name", "event", "approved", "closing_date")
|
||||
list_select_related = ("event",)
|
||||
ordering = ["approved", "closing_date"]
|
||||
search_fields = ["event__name", "event__url", "details"]
|
||||
actions = [approve, unapprove]
|
||||
|
||||
|
||||
|
@ -185,6 +190,7 @@ class Group(admin.ModelAdmin):
|
|||
|
||||
list_display = ("name", "approved", "category", "description")
|
||||
ordering = ["approved", "name"]
|
||||
search_fields = ["name", "description", "url"]
|
||||
actions = [approve, unapprove]
|
||||
|
||||
|
||||
|
@ -200,6 +206,7 @@ class Newsletter(admin.ModelAdmin):
|
|||
"active",
|
||||
)
|
||||
ordering = ["approved", "-failing"]
|
||||
search_fields = ["name", "description", "url", "author_name"]
|
||||
actions = [approve, unapprove, suspend, activate, disable]
|
||||
|
||||
|
||||
|
@ -209,6 +216,7 @@ class Edition(admin.ModelAdmin):
|
|||
|
||||
date_hierarchy = "pubdate"
|
||||
list_display = ("title", "newsletter_name", "pubdate")
|
||||
search_fields = ["title", "description", "url", "newsletter__name", "author_name"]
|
||||
|
||||
def newsletter_name(self, obj): # pylint: disable=no-self-use
|
||||
"""get the title of the parent newsletter"""
|
||||
|
|
|
@ -132,13 +132,9 @@ class Command(BaseCommand):
|
|||
open_cfps = ""
|
||||
for instance in cfps:
|
||||
c_date = instance.closing_date
|
||||
title_string = (
|
||||
f"<h4><a href='{instance.event.url}'>{instance.name}</a></h4>"
|
||||
)
|
||||
title_string = f"<h4><a href='{instance.event.url}'>{instance.event.name} - {instance.name}</a></h4>"
|
||||
dates_string = f"<p><strong>Closes:</strong><em>{c_date:%a} {c_date.day} {c_date:%B}</em></p>"
|
||||
description_string = (
|
||||
f"<p style='margin-bottom:24px;'>{instance.details}</p>"
|
||||
)
|
||||
description_string = f"<p>{instance.details}</p><p style='margin-bottom:24px;'>{instance.event.description}</p>"
|
||||
|
||||
string_list = [title_string, dates_string, description_string]
|
||||
string = "".join(string_list)
|
||||
|
|
|
@ -79,8 +79,7 @@ class Blog(BlogData):
|
|||
author = ""
|
||||
|
||||
category = Category(self.category).label
|
||||
status = f"{self.title}{author} has been added to Aus GLAMR! \
|
||||
\n\nIt's about {category}\n\n{self.url}"
|
||||
status = f"{self.title}{author} has been added to Aus GLAMR! \n\nIt's about {category}\n\n{self.url}"
|
||||
|
||||
Announcement.objects.create(status=status)
|
||||
self.announced = True
|
||||
|
|
|
@ -15,10 +15,19 @@ class BlogTestCase(TestCase):
|
|||
def setUp(self):
|
||||
"""set up test blog"""
|
||||
self.blog = models.Blog.objects.create(
|
||||
title="mya awesome blog",
|
||||
title="my awesome blog",
|
||||
url="https://test.com",
|
||||
feed="https://test.com/feed.xml",
|
||||
category="LIB",
|
||||
author_name="Hugh",
|
||||
)
|
||||
|
||||
self.blog_no_author = models.Blog.objects.create(
|
||||
title="my awesome archives",
|
||||
url="https://test2.com",
|
||||
feed="https://test2.com/feed.xml",
|
||||
category="ARC",
|
||||
author_name="",
|
||||
)
|
||||
|
||||
def test_get_absolute_url(self):
|
||||
|
@ -46,6 +55,22 @@ class BlogTestCase(TestCase):
|
|||
self.blog.set_failing()
|
||||
self.assertEqual(self.blog.failing, True)
|
||||
|
||||
def test_announce_blog(self):
|
||||
"""test announcing the blog"""
|
||||
|
||||
self.blog.announce()
|
||||
status = f"my awesome blog by Hugh has been added to Aus GLAMR! \n\nIt's about Libraries\n\nhttps://test.com"
|
||||
announcement = models.Announcement.objects.first()
|
||||
self.assertEqual(status, announcement.status)
|
||||
|
||||
def test_announce_blog_no_author(self):
|
||||
"""test announcing the blog with a blank blog author name"""
|
||||
|
||||
self.blog_no_author.announce()
|
||||
status = f"my awesome archives has been added to Aus GLAMR! \n\nIt's about Archives\n\nhttps://test2.com"
|
||||
announcement = models.Announcement.objects.first()
|
||||
self.assertEqual(status, announcement.status)
|
||||
|
||||
def test_announce_article(self):
|
||||
"""announcing a blog article"""
|
||||
|
||||
|
@ -59,7 +84,7 @@ class BlogTestCase(TestCase):
|
|||
)
|
||||
|
||||
article.announce()
|
||||
status = f"My article (Hugh on mya awesome blog)\n\nhttps://example.blog/1"
|
||||
status = f"My article (Hugh on my awesome blog)\n\nhttps://example.blog/1"
|
||||
self.assertTrue(models.Announcement.objects.filter(status=status).exists())
|
||||
|
||||
|
||||
|
|
|
@ -70,7 +70,10 @@ class UtilityTests(TestCase):
|
|||
self.assertEqual(data["description"], "A short summary of my blog")
|
||||
|
||||
def test_get_blog_info_no_feed(self):
|
||||
"""test get blog info"""
|
||||
"""
|
||||
test get blog info
|
||||
note get_blog_info only checks <head>, not rss feed
|
||||
"""
|
||||
|
||||
with open(
|
||||
pathlib.Path(__file__).parent.joinpath("data/example.html"),
|
||||
|
@ -152,7 +155,7 @@ class UtilityTests(TestCase):
|
|||
data = utilities.get_blog_info("http://test.test")
|
||||
|
||||
self.assertEqual(data["title"], "My test website with an RSS feed")
|
||||
self.assertEqual(data["author_name"], "Hugh Rundle")
|
||||
self.assertEqual(data["author_name"], "")
|
||||
self.assertEqual(data["description"], "A short summary of my blog")
|
||||
|
||||
def test_get_blog_info_with_incomplete_head_and_partial_feed(self):
|
||||
|
@ -171,7 +174,7 @@ class UtilityTests(TestCase):
|
|||
data = utilities.get_blog_info("http://test.test")
|
||||
|
||||
self.assertEqual(data["title"], "My test website with an RSS feed")
|
||||
self.assertEqual(data["author_name"], None)
|
||||
self.assertEqual(data["author_name"], "")
|
||||
self.assertEqual(data["description"], None)
|
||||
|
||||
def test_get_webfinger_subscribe_uri(self):
|
||||
|
|
|
@ -222,6 +222,7 @@ class PublicTests(TestCase):
|
|||
form.data["from_email"] = "example@example.mail"
|
||||
form.data["subject"] = "Hello"
|
||||
form.data["message"] = "Hi there"
|
||||
form.data["bot_check"] = "books"
|
||||
|
||||
request = self.factory.post("contact/", form.data)
|
||||
request.user = AnonymousUser()
|
||||
|
@ -234,6 +235,24 @@ class PublicTests(TestCase):
|
|||
# Verify that the subject of the first message is correct.
|
||||
self.assertEqual(mail.outbox[0].subject, "Message via Aus GLAMR: Hello")
|
||||
|
||||
def test_contact_from_bot(self):
|
||||
"""post message"""
|
||||
|
||||
view = views.Contact.as_view()
|
||||
form = forms.ContactForm()
|
||||
form.data["from_email"] = "example@example.mail"
|
||||
form.data["subject"] = "Hello"
|
||||
form.data["message"] = "Hi there"
|
||||
form.data["bot_check"] = "i am a stupid bot"
|
||||
|
||||
request = self.factory.post("contact/", form.data)
|
||||
request.user = AnonymousUser()
|
||||
|
||||
view(request)
|
||||
|
||||
# Test that one message has been sent.
|
||||
self.assertEqual(len(mail.outbox), 0)
|
||||
|
||||
def test_search(self):
|
||||
"""post search query"""
|
||||
|
||||
|
|
|
@ -4,6 +4,7 @@ import re
|
|||
|
||||
from bs4 import BeautifulSoup
|
||||
import feedparser
|
||||
import logging
|
||||
import requests
|
||||
|
||||
from django.conf import settings
|
||||
|
@ -65,17 +66,21 @@ def get_blog_info(url):
|
|||
) # use the title from the feed
|
||||
|
||||
blog_info["description"] = description or blog_info.get("description", "")
|
||||
blog_info["author_name"] = blog_info.get("author", author)
|
||||
|
||||
else:
|
||||
return False # if there is no feed info we need to put the onus back on the user to fill in the data
|
||||
|
||||
normalised_author = ""
|
||||
if author:
|
||||
normalised_author = author.replace("(noreply@blogger.com)", "")
|
||||
normalised_author = blog_info["author_name"] or None
|
||||
if normalised_author:
|
||||
normalised_author = normalised_author.replace("(noreply@blogger.com)", "")
|
||||
if normalised_author.strip() == "Unknown":
|
||||
normalised_author = ""
|
||||
|
||||
blog_info["author_name"] = normalised_author
|
||||
else:
|
||||
normalised_author = ""
|
||||
|
||||
blog_info["author_name"] = normalised_author
|
||||
|
||||
return blog_info
|
||||
|
||||
|
|
|
@ -77,7 +77,7 @@ case "$CMD" in
|
|||
runweb python manage.py send_weekly_email
|
||||
;;
|
||||
test)
|
||||
runweb python manage.py test "$@"
|
||||
runweb python manage.py test blogs/tests "$@"
|
||||
;;
|
||||
*)
|
||||
set +x
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
beautifulsoup4==4.12.2
|
||||
gunicorn==22.0.0
|
||||
Django==4.2.11
|
||||
Django==4.2.14
|
||||
environs==9.5.0
|
||||
feedparser==6.0.10
|
||||
psycopg2==2.9.5
|
||||
|
|
Loading…
Reference in a new issue