Fix summaries #14

Merged
hughrun merged 2 commits from fix-summaries into main 2024-06-24 12:26:24 +10:00
6 changed files with 52 additions and 38 deletions

View file

@ -1,6 +1,7 @@
""" """
URL configuration for ausglamr project. URL configuration for ausglamr project.
""" """
from django.contrib import admin from django.contrib import admin
from django.urls import path, re_path from django.urls import path, re_path
from django.views.generic import TemplateView from django.views.generic import TemplateView
@ -65,6 +66,8 @@ urlpatterns = [
views.UnsubscribeEmail.as_view(), views.UnsubscribeEmail.as_view(),
name="unsubscribe-email", name="unsubscribe-email",
), ),
path('robots.txt', TemplateView.as_view(template_name='robots.txt', path(
content_type='text/plain')), "robots.txt",
TemplateView.as_view(template_name="robots.txt", content_type="text/plain"),
),
] ]

View file

@ -1,4 +1,5 @@
"""django apps""" """django apps"""
from django.apps import AppConfig from django.apps import AppConfig

View file

@ -141,8 +141,8 @@ class ContactForm(forms.Form):
bot_check = forms.CharField( bot_check = forms.CharField(
label="What is usually stored in a library?", label="What is usually stored in a library?",
max_length=10, max_length=10,
help_text="Checking that you are human" help_text="Checking that you are human",
) )
def clean_bot_check(self): def clean_bot_check(self):
"""validate the bot check""" """validate the bot check"""

View file

@ -117,7 +117,7 @@ class Command(BaseCommand):
if not opt_out: if not opt_out:
author_name = getattr( author_name = getattr(
article, "author", None article, "author", None
) or getattr(blog, "author", None) ) or getattr(blog, "author", "")
description = ( description = (
html.strip_tags(article.summary) html.strip_tags(article.summary)
@ -125,20 +125,26 @@ class Command(BaseCommand):
hasattr(article, "summary") hasattr(article, "summary")
and len(article.summary) > 0 and len(article.summary) > 0
) )
else html.strip_tags(article.description) else (
if ( html.strip_tags(article.description)
hasattr(article, "description") if (
and len(article.summary) hasattr(article, "description")
and len(article.summary)
)
else (
html.strip_tags(article.content[0].value)
if (
hasattr(article, "content")
and len(article.content)
)
else None
)
) )
else html.strip_tags(article.content[0].value)[:200]
if (
hasattr(article, "content")
and len(article.content)
)
else ""
) )
if description: if description:
description += "..." description[:200] += "..."
else:
description = ""
instance = models.Article.objects.create( instance = models.Article.objects.create(
title=article.title, title=article.title,
@ -168,7 +174,9 @@ class Command(BaseCommand):
if newish: if newish:
instance.announce() instance.announce()
blog.set_success( blog.set_success(
updateddate=date_to_tz_aware(article.updated_parsed) updateddate=date_to_tz_aware(
article.updated_parsed
)
) )
except Exception as e: except Exception as e:
@ -191,7 +199,7 @@ class Command(BaseCommand):
| Q(guid=getattr(edition, "id", edition.link)) | Q(guid=getattr(edition, "id", edition.link))
).exists(): ).exists():
author_name = getattr(edition, "author", None) or getattr( author_name = getattr(edition, "author", None) or getattr(
edition, "author", None edition, "author", ""
) )
description = ( description = (
@ -199,20 +207,26 @@ class Command(BaseCommand):
if ( if (
hasattr(edition, "summary") and len(edition.summary) hasattr(edition, "summary") and len(edition.summary)
) )
else html.strip_tags(edition.description) else (
if ( html.strip_tags(edition.description)
hasattr(edition, "description") if (
and len(edition.description) hasattr(edition, "description")
and len(edition.description)
)
else (
html.strip_tags(edition.content[0].value)
if (
hasattr(article, "content")
and len(article.content)
)
else None
)
) )
else html.strip_tags(edition.content[0].value)[:200] + "..."
if (
hasattr(article, "content")
and len(article.content)
)
else ""
) )
if description: if description:
description += "..." description[:200] += "..."
else:
description = ""
instance = models.Edition.objects.create( instance = models.Edition.objects.create(
title=edition.title, title=edition.title,

View file

@ -94,9 +94,7 @@ class EventFeed(Feed):
return ( return (
item.description item.description
if hasattr(item, "description") if hasattr(item, "description")
else item.details else item.details if hasattr(item, "details") else None
if hasattr(item, "details")
else None
) )
def item_link(self, item): def item_link(self, item):
@ -215,9 +213,7 @@ class CombinedFeed(Feed):
return ( return (
item.description item.description
if hasattr(item, "description") if hasattr(item, "description")
else item.details else item.details if hasattr(item, "details") else None
if hasattr(item, "details")
else None
) )
def item_link(self, item): def item_link(self, item):

View file

@ -194,9 +194,9 @@ class RegisterBlog(View):
data["blog_info"] = blog_info data["blog_info"] = blog_info
else: else:
data[ data["error"] = (
"error" "Could not auto-discover your feed info, please enter manually"
] = "Could not auto-discover your feed info, please enter manually" )
return render(request, "blogs/confirm-register.html", data) return render(request, "blogs/confirm-register.html", data)