Merge branch 'main' into wip-edit-post-and-save

This commit is contained in:
Hugh Rundle 2023-07-31 16:25:04 +10:00 committed by GitHub
commit 390f61ff3b
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
10 changed files with 53 additions and 8 deletions

View file

@ -343,6 +343,10 @@ def add_status_on_create(sender, instance, created, *args, **kwargs):
def add_status_on_create_command(sender, instance, created):
"""runs this code only after the database commit completes"""
# boosts trigger 'saves" twice, so don't bother duplicating the task
if sender == models.Boost and not created:
return
priority = STREAMS
# check if this is an old status, de-prioritize if so
# (this will happen if federation is very slow, or, more expectedly, on csv import)

View file

@ -368,10 +368,16 @@ class TagField(ManyToManyField):
activity_type = item.__class__.__name__
if activity_type == "User":
activity_type = "Mention"
if activity_type == "Hashtag":
name = item.name
else:
name = f"@{getattr(item, item.name_field)}"
tags.append(
activitypub.Link(
href=item.remote_id,
name=f"@{getattr(item, item.name_field)}",
name=name,
type=activity_type,
)
)

View file

@ -4,7 +4,7 @@
{% block filter %}
<div class="control">
<label class="label" for="id_search">{% trans "Search editions" %}</label>
<input type="text" class="input" name="q" value="{{ request.GET.q|default:'' }}" id="id_search">
<input type="text" class="input" name="q" value="{{ request.GET.q|default:'' }}" id="id_search" spellcheck="false">
</div>
{% endblock %}

View file

@ -6,7 +6,7 @@
<h2 class="title is-4">{% trans "What are you reading?" %}</h2>
<form class="field has-addons" method="get" action="{% url 'get-started-books' %}">
<div class="control">
<input type="text" name="query" value="{{ request.GET.query }}" class="input" placeholder="{% trans 'Search for a book' %}" aria-label="{% trans 'Search for a book' %}">
<input type="text" name="query" value="{{ request.GET.query }}" class="input" placeholder="{% trans 'Search for a book' %}" aria-label="{% trans 'Search for a book' %}" spellcheck="false">
{% if request.GET.query and not book_results %}
<p class="help">{% blocktrans with query=request.GET.query %}No books found for "{{ query }}"{% endblocktrans %}. {% blocktrans %}You can add books when you start using {{ site_name }}.{% endblocktrans %}</p>
{% endif %}

View file

@ -8,7 +8,7 @@
<p class="subtitle is-6">{% trans "You can follow users on other BookWyrm instances and federated services like Mastodon." %}</p>
<form class="field has-addons" method="get" action="{% url 'get-started-users' %}">
<div class="control">
<input type="text" name="query" value="{{ request.GET.query }}" class="input" placeholder="{% trans 'Search for a user' %}" aria-label="{% trans 'Search for a user' %}">
<input type="text" name="query" value="{{ request.GET.query }}" class="input" placeholder="{% trans 'Search for a user' %}" aria-label="{% trans 'Search for a user' %}" spellcheck="false">
{% if request.GET.query and no_results %}
<p class="help">{% blocktrans with query=request.GET.query %}No users found for "{{ query }}"{% endblocktrans %}</p>
{% endif %}

View file

@ -8,7 +8,7 @@
<div class="block">
<form class="field has-addons" method="get" action="{% url 'group-find-users' group.id %}">
<div class="control">
<input type="text" name="user_query" value="{{ request.GET.user_query }}" class="input" placeholder="{% trans 'Search to add a user' %}" aria-label="{% trans 'Search to add a user' %}">
<input type="text" name="user_query" value="{{ request.GET.user_query }}" class="input" placeholder="{% trans 'Search to add a user' %}" aria-label="{% trans 'Search to add a user' %}" spellcheck="false">
</div>
<div class="control" id="tour-group-member-search">
<button class="button" type="submit">

View file

@ -38,7 +38,7 @@
{% else %}
{% trans "Search for a book" as search_placeholder %}
{% endif %}
<input aria-label="{{ search_placeholder }}" id="tour-search" class="input" type="text" name="q" placeholder="{{ search_placeholder }}" value="{{ query }}">
<input aria-label="{{ search_placeholder }}" id="tour-search" class="input" type="text" name="q" placeholder="{{ search_placeholder }}" value="{{ query }}" spellcheck="false">
</div>
<div class="control">
<button class="button" type="submit">

View file

@ -210,7 +210,7 @@
<form name="search" action="{% url 'list' list_id=list.id slug=list.name|slugify %}" method="GET" class="block">
<div class="field has-addons">
<div class="control">
<input aria-label="{% trans 'Search for a book' %}" class="input" type="text" name="q" placeholder="{% trans 'Search for a book' %}" value="{{ query }}">
<input aria-label="{% trans 'Search for a book' %}" class="input" type="text" name="q" placeholder="{% trans 'Search for a book' %}" value="{{ query }}" spellcheck="false">
</div>
<div class="control">
<button class="button" type="submit">

View file

@ -14,7 +14,7 @@
<form class="block" action="{% url 'search' %}" method="GET">
<div class="field has-addons">
<div class="control">
<input type="text" class="input" name="q" value="{{ query }}" aria-label="{% trans 'Search query' %}" id="tour-search-page-input">
<input type="text" class="input" name="q" value="{{ query }}" aria-label="{% trans 'Search query' %}" id="tour-search-page-input" spellcheck="false">
</div>
<div class="control">
<div class="select" aria-label="{% trans 'Search type' %}">

View file

@ -135,6 +135,41 @@ class Status(TestCase):
self.assertEqual(activity["content"], "<p>test content</p>")
self.assertEqual(activity["sensitive"], False)
def test_status_with_hashtag_to_activity(self, *_):
"""status with hashtag with a "pure" serializer"""
tag = models.Hashtag.objects.create(name="#content")
status = models.Status.objects.create(
content="test #content", user=self.local_user
)
status.mention_hashtags.add(tag)
activity = status.to_activity(pure=True)
self.assertEqual(activity["id"], status.remote_id)
self.assertEqual(activity["type"], "Note")
self.assertEqual(activity["content"], "<p>test #content</p>")
self.assertEqual(activity["sensitive"], False)
self.assertEqual(activity["tag"][0]["type"], "Hashtag")
self.assertEqual(activity["tag"][0]["name"], "#content")
self.assertEqual(
activity["tag"][0]["href"], f"https://{settings.DOMAIN}/hashtag/{tag.id}"
)
def test_status_with_mention_to_activity(self, *_):
"""status with mention with a "pure" serializer"""
status = models.Status.objects.create(
content="test @rat@rat.com", user=self.local_user
)
status.mention_users.add(self.remote_user)
activity = status.to_activity(pure=True)
self.assertEqual(activity["id"], status.remote_id)
self.assertEqual(activity["type"], "Note")
self.assertEqual(activity["content"], "<p>test @rat@rat.com</p>")
self.assertEqual(activity["sensitive"], False)
self.assertEqual(activity["tag"][0]["type"], "Mention")
self.assertEqual(activity["tag"][0]["name"], f"@{self.remote_user.username}")
self.assertEqual(activity["tag"][0]["href"], self.remote_user.remote_id)
def test_status_to_activity_tombstone(self, *_):
"""subclass of the base model version with a "pure" serializer"""
status = models.Status.objects.create(