Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

changes: consolidate action names #10135

Merged
merged 2 commits into from
Oct 12, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions docs/changes.rst
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ Not yet released.
* Highlight whitespace in :ref:`machine-translation`.
* Faster comment and component removal.
* Show disabled save button reason more prominently.
* New string notification can now be triggered for each string.

**Bug fixes**

Expand Down
28 changes: 28 additions & 0 deletions weblate/accounts/migrations/0002_new_string_notification.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# Copyright © Michal Čihař <[email protected]>
#
# SPDX-License-Identifier: GPL-3.0-or-later

# Generated by Django 4.2.5 on 2023-10-12 08:25

from django.db import migrations


def migrate_subscription(apps, schema_editor):
Subscription = apps.get_model("accounts", "Subscription")
# Change instant to daily, because this now has string granularity
Subscription.objects.filter(
notification="NewStringNotificaton", frequency=1
).update(frequency=2)


class Migration(migrations.Migration):
dependencies = [
("accounts", "0001_squashed_weblate_5"),
("trans", "0006_alter_change_action"),
]

operations = [
migrations.RunPython(
migrate_subscription, migrations.RunPython.noop, elidable=True
),
]
7 changes: 5 additions & 2 deletions weblate/accounts/notifications.py
Original file line number Diff line number Diff line change
Expand Up @@ -265,7 +265,9 @@ def get_context(
result["changes"] = changes
if subscription is not None:
result["unsubscribe_nonce"] = TimestampSigner().sign(subscription.pk)
result["user"] = subscription.user
result["subscription_user"] = subscription.user
else:
result["subscription_user"] = None
if extracontext:
result.update(extracontext)
if change:
Expand Down Expand Up @@ -489,12 +491,13 @@ def get_context(

@register_notification
class NewStringNotificaton(Notification):
actions = (Change.ACTION_NEW_STRING,)
actions = (Change.ACTION_NEW_UNIT,)
verbose = pgettext_lazy(
"Notification name", "New string is available for translation"
)
template_name = "new_string"
filter_languages = True
required_attr = "unit"


@register_notification
Expand Down
16 changes: 1 addition & 15 deletions weblate/accounts/tests/test_notifications.py
Original file line number Diff line number Diff line change
Expand Up @@ -195,27 +195,13 @@ def test_notify_parse_error(self):
self.validate_notifications(3, "[Weblate] Parse error in Test/Test")

def test_notify_new_string(self):
Change.objects.create(
translation=self.get_translation(), action=Change.ACTION_NEW_STRING
)
Change.objects.create(unit=self.get_unit(), action=Change.ACTION_NEW_UNIT)

# Check mail
self.validate_notifications(
1, "[Weblate] New string to translate in Test/Test — Czech"
)

def test_notify_new_strings(self):
Change.objects.create(
translation=self.get_translation(),
action=Change.ACTION_NEW_STRING,
details={"count": 10},
)

# Check mail
self.validate_notifications(
1, "[Weblate] New strings to translate in Test/Test — Czech"
)

def test_notify_new_translation(self):
Change.objects.create(
unit=self.get_unit(),
Expand Down
10 changes: 5 additions & 5 deletions weblate/api/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -968,7 +968,7 @@ def test_components(self):

def test_changes(self):
request = self.do_request("api:project-changes", self.project_kwargs)
self.assertEqual(request.data["count"], 33)
self.assertEqual(request.data["count"], 30)

def test_statistics(self):
request = self.do_request("api:project-statistics", self.project_kwargs)
Expand Down Expand Up @@ -1904,7 +1904,7 @@ def test_translations(self):

def test_changes(self):
request = self.do_request("api:component-changes", self.component_kwargs)
self.assertEqual(request.data["count"], 25)
self.assertEqual(request.data["count"], 22)

def test_screenshots(self):
request = self.do_request("api:component-screenshots", self.component_kwargs)
Expand Down Expand Up @@ -2648,7 +2648,7 @@ def test_statistics(self):

def test_changes(self):
request = self.do_request("api:translation-changes", self.translation_kwargs)
self.assertEqual(request.data["count"], 6)
self.assertEqual(request.data["count"], 5)

def test_units(self):
request = self.do_request("api:translation-units", self.translation_kwargs)
Expand Down Expand Up @@ -3576,15 +3576,15 @@ def test_units_delete(self):
class ChangeAPITest(APIBaseTest):
def test_list_changes(self):
response = self.client.get(reverse("api:change-list"))
self.assertEqual(response.data["count"], 33)
self.assertEqual(response.data["count"], 30)

def test_filter_changes_after(self):
"""Filter changes since timestamp."""
start = Change.objects.order().last().timestamp
response = self.client.get(
reverse("api:change-list"), {"timestamp_after": start.isoformat()}
)
self.assertEqual(response.data["count"], 33)
self.assertEqual(response.data["count"], 30)

def test_filter_changes_before(self):
"""Filter changes prior to timestamp."""
Expand Down
6 changes: 5 additions & 1 deletion weblate/templates/mail/new_string.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,11 @@
{% load i18n %}{% load translations %}

{% block content %}
{% include "mail/snippets/source-string.html" %}

<div class="line buttons">
<a class="button" href="{{ change.get_absolute_url }}">{% trans "View" %}</a>
<a class="button" href="{{ unit.get_absolute_url }}">{% trans "Edit this string" %}</a>
</div>

{% include "mail/snippets/unit-screenshots.html" %}
{% endblock %}
2 changes: 1 addition & 1 deletion weblate/templates/mail/new_string_subject.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{% load i18n %}
{% autoescape off %}
{% blocktrans count count=change.plural_count %}New string to translate in {{ translation }}{% plural %}New strings to translate in {{ translation }}{% endblocktrans %}
{% blocktrans %}New string to translate in {{ translation }}{% endblocktrans %}
{% endautoescape %}
2 changes: 1 addition & 1 deletion weblate/templates/mail/snippets/unit-screenshots.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<h2>{% trans "Source string location" %}</h2>

<p>
{% get_location_links user.profile unit %}
{% get_location_links subscription_user unit %}
</p>
{% endif %}

Expand Down
2 changes: 1 addition & 1 deletion weblate/templates/translate.html
Original file line number Diff line number Diff line change
Expand Up @@ -679,7 +679,7 @@ <h5>
<h5>
{% trans "Source string location" %}
</h5>
{% get_location_links user.profile unit %}
{% get_location_links user unit %}
</div>
{% endif %}
<div class="list-group-item">
Expand Down
2 changes: 1 addition & 1 deletion weblate/templates/zen-units.html
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
<a class="btn btn-link btn-xs" href="{{ site_url }}{{ item.unit.get_absolute_url }}" data-clipboard-text="{{ site_url }}{{ item.unit.get_absolute_url }}" data-clipboard-message="{% trans "Permalink copied to clipboard." %}" title="{% trans "Copy permalink" %}">{% icon "link.svg" %}</a>
<a class="btn btn-link btn-xs" href="{% url 'translate' path=object.get_url_path %}?{{ search_url }}&amp;offset={{ item.offset }}" title="{% trans "Open in full editor" %}">{% icon "pencil-mini.svg" %}</a>
</div>
{% get_location_links user.profile item.unit %}
{% get_location_links user item.unit %}
</td>
</tr>

Expand Down
98 changes: 98 additions & 0 deletions weblate/trans/migrations/0006_alter_change_action.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
# Copyright © Michal Čihař <[email protected]>
#
# SPDX-License-Identifier: GPL-3.0-or-later

# Generated by Django 4.2.5 on 2023-10-12 08:25

from django.db import migrations, models

ACTION_NEW_STRING = 44


def migrate_changes(apps, schema_editor):
Change = apps.get_model("trans", "Change")
Change.objects.filter(action=ACTION_NEW_STRING).delete()


class Migration(migrations.Migration):
dependencies = [
("trans", "0005_alter_change_alert_alter_change_announcement_and_more"),
]

operations = [
migrations.AlterField(
model_name="change",
name="action",
field=models.IntegerField(
choices=[
(0, "Resource update"),
(1, "Translation completed"),
(2, "Translation changed"),
(5, "New translation"),
(3, "Comment added"),
(4, "Suggestion added"),
(6, "Automatic translation"),
(7, "Suggestion accepted"),
(8, "Translation reverted"),
(9, "Translation uploaded"),
(13, "New source string"),
(14, "Component locked"),
(15, "Component unlocked"),
(17, "Committed changes"),
(18, "Pushed changes"),
(19, "Reset repository"),
(20, "Merged repository"),
(21, "Rebased repository"),
(22, "Failed merge on repository"),
(23, "Failed rebase on repository"),
(28, "Failed push on repository"),
(24, "Parse error"),
(25, "Removed translation"),
(26, "Suggestion removed"),
(27, "Search and replace"),
(29, "Suggestion removed during cleanup"),
(30, "Source string changed"),
(31, "New string added"),
(32, "Bulk status change"),
(33, "Changed visibility"),
(34, "Added user"),
(35, "Removed user"),
(36, "Translation approved"),
(37, "Marked for edit"),
(38, "Removed component"),
(39, "Removed project"),
(41, "Renamed project"),
(42, "Renamed component"),
(43, "Moved component"),
(45, "New contributor"),
(46, "New announcement"),
(47, "New alert"),
(48, "Added new language"),
(49, "Requested new language"),
(50, "Created project"),
(51, "Created component"),
(52, "Invited user"),
(53, "Received repository notification"),
(54, "Replaced file by upload"),
(55, "License changed"),
(56, "Contributor agreement changed"),
(57, "Screnshot added"),
(58, "Screnshot uploaded"),
(59, "String updated in the repository"),
(60, "Add-on installed"),
(61, "Add-on configuration changed"),
(62, "Add-on uninstalled"),
(63, "Removed string"),
(64, "Removed comment"),
(65, "Resolved comment"),
(66, "Explanation updated"),
(67, "Removed category"),
(68, "Renamed category"),
(69, "Moved category"),
(70, "Could not save string"),
],
default=2,
),
),
migrations.RunPython(migrate_changes, migrations.RunPython.noop, elidable=True),
]
90 changes: 90 additions & 0 deletions weblate/trans/migrations/0007_alter_change_action.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
# Copyright © Michal Čihař <[email protected]>
#
# SPDX-License-Identifier: GPL-3.0-or-later

# Generated by Django 4.2.6 on 2023-10-12 12:56

from django.db import migrations, models


class Migration(migrations.Migration):
dependencies = [
("trans", "0006_alter_change_action"),
]

operations = [
migrations.AlterField(
model_name="change",
name="action",
field=models.IntegerField(
choices=[
(0, "Resource updated"),
(1, "Translation completed"),
(2, "Translation changed"),
(5, "Translation added"),
(3, "Comment added"),
(4, "Suggestion added"),
(6, "Automatically translated"),
(7, "Suggestion accepted"),
(8, "Translation reverted"),
(9, "Translation uploaded"),
(13, "Source string added"),
(14, "Component locked"),
(15, "Component unlocked"),
(17, "Changes committed"),
(18, "Changes pushed"),
(19, "Repository reset"),
(20, "Repository merged"),
(21, "Repository rebased"),
(22, "Repository merge failed"),
(23, "Repository rebase failed"),
(28, "Repository push failed"),
(24, "Parsing failed"),
(25, "Translation removed"),
(26, "Suggestion removed"),
(27, "Translation replaced"),
(29, "Suggestion removed during cleanup"),
(30, "Source string changed"),
(31, "String added"),
(32, "Bulk status changed"),
(33, "Visibility changed"),
(34, "User added"),
(35, "User removed"),
(36, "Translation approved"),
(37, "Marked for edit"),
(38, "Component removed"),
(39, "Project removed"),
(41, "Project renamed"),
(42, "Component renamed"),
(43, "Moved component"),
(45, "Contributor joined"),
(46, "Announcement posted"),
(47, "Alert triggered"),
(48, "Language added"),
(49, "Language requested"),
(50, "Project created"),
(51, "Component created"),
(52, "User invited"),
(53, "Repository notification received"),
(54, "Translation replaced file by upload"),
(55, "License changed"),
(56, "Contributor agreement changed"),
(57, "Screnshot added"),
(58, "Screnshot uploaded"),
(59, "String updated in the repository"),
(60, "Add-on installed"),
(61, "Add-on configuration changed"),
(62, "Add-on uninstalled"),
(63, "String removed"),
(64, "Comment removed"),
(65, "Comment resolved"),
(66, "Explanation updated"),
(67, "Category removed"),
(68, "Category renamed"),
(69, "Category moved"),
(70, "Saving string failed"),
],
default=2,
),
),
]
Loading
Loading