Skip to content

Commit

Permalink
Proof of Concept of Zen in Suggestions
Browse files Browse the repository at this point in the history
  • Loading branch information
juliancoffee committed Mar 13, 2024
1 parent 60e2fd9 commit 8403ff0
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 1 deletion.
2 changes: 1 addition & 1 deletion weblate/templates/snippets/suggestions.html
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
{% else %}
{% perm 'suggestion.delete' suggestion as user_can_delete_suggestion %}
{% if user_can_vote_suggestion or user_can_accept_suggestion or user_can_delete_suggestion %}
<div class="btn-float pull-right flip">
<div class="btn-float pull-right flip" style="top: -20px">
{% if user_can_vote_suggestion %}
<button type="submit" class="btn btn-link green" name="upvote" value="{{ suggestion.id }}" title="{% trans "Vote for" %}">{% icon "thumb-up.svg" %}</button>
<button type="submit" class="btn btn-link red" name="downvote" value="{{ suggestion.id }}" title="{% trans "Vote against" %}">{% icon "thumb-down.svg" %}</button>
Expand Down
11 changes: 11 additions & 0 deletions weblate/templates/zen-units.html
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,17 @@
{% endif %}
<td {% if user.profile.zen_mode != user.profile.ZEN_HORIZONTAL %}colspan="2"{% endif %} class="translator">
{% crispy item.form %}

{% perm 'suggestion.add' item.unit as user_can_suggest %}
{% perm 'suggestion.accept' item.unit as user_can_accept_suggestion %}
{% perm 'suggestion.vote' item.unit.translation as user_can_vote_suggestion %}

<form action="{{ this_unit_url }}" method="post">
{% csrf_token %}
<input type="hidden" name="checksum" value="{{ item.unit.checksum }}" />

{% include "snippets/suggestions.html" with suggestions=item.unit.suggestions %}
</form>
</td>
</tr>

Expand Down
26 changes: 26 additions & 0 deletions weblate/trans/views/edit.py
Original file line number Diff line number Diff line change
Expand Up @@ -893,6 +893,32 @@ def zen(request, path):

search_result, unitdata = get_zen_unitdata(obj, project, unit_set, request)
sort = get_sort_name(request, obj)
if (
request.method == "POST"
and "merge" not in request.POST
and (
"accept" in request.POST
or "accept_edit" in request.POST
or "accept_approve" in request.POST
or "delete" in request.POST
or "spam" in request.POST
or "upvote" in request.POST
or "downvote" in request.POST
)
):
# Handle accepting/deleting suggestions
_obj, unit_set, _context = parse_path_units(

Check warning on line 910 in weblate/trans/views/edit.py

View check run for this annotation

Codecov / codecov/patch

weblate/trans/views/edit.py#L910

Added line #L910 was not covered by tests
request, path, (Translation, ProjectLanguage, CategoryLanguage)
)

checksum_form = ChecksumForm(unit_set, request.POST)

Check warning on line 914 in weblate/trans/views/edit.py

View check run for this annotation

Codecov / codecov/patch

weblate/trans/views/edit.py#L914

Added line #L914 was not covered by tests
if not checksum_form.is_valid():
show_form_errors(request, checksum_form)
return HttpResponseBadRequest("Invalid checksum")

Check warning on line 917 in weblate/trans/views/edit.py

View check run for this annotation

Codecov / codecov/patch

weblate/trans/views/edit.py#L916-L917

Added lines #L916 - L917 were not covered by tests

unit = checksum_form.cleaned_data["unit"]

Check warning on line 919 in weblate/trans/views/edit.py

View check run for this annotation

Codecov / codecov/patch

weblate/trans/views/edit.py#L919

Added line #L919 was not covered by tests
# We are ignoring any redirects and responses here
_response = handle_suggestions(request, unit, "", "")

Check warning on line 921 in weblate/trans/views/edit.py

View check run for this annotation

Codecov / codecov/patch

weblate/trans/views/edit.py#L921

Added line #L921 was not covered by tests

# Handle redirects
if isinstance(search_result, HttpResponse):
Expand Down

0 comments on commit 8403ff0

Please sign in to comment.