Commit 04facbe4 authored by Michal Čihař's avatar Michal Čihař

Support for deleting comments.

Fixes #601.
Signed-off-by: default avatarMichal Čihař <michal@cihar.com>
parent 1fe176ef
...@@ -10,6 +10,7 @@ Released on ? 2015. ...@@ -10,6 +10,7 @@ Released on ? 2015.
* Fulltext search on location and comments fields. * Fulltext search on location and comments fields.
* New SVG/javascript based activity charts. * New SVG/javascript based activity charts.
* Support for Django 1.8. * Support for Django 1.8.
* Support for deleting comments.
weblate 2.1 weblate 2.1
----------- -----------
......
...@@ -76,7 +76,9 @@ ...@@ -76,7 +76,9 @@
</tr> </tr>
<tr> <tr>
<td> <td>
{% with next as next_url %}
{% include "list-comments.html" %} {% include "list-comments.html" %}
{% endwith %}
</td> </td>
</tr> </tr>
{% endif %} {% endif %}
......
...@@ -13,6 +13,14 @@ ...@@ -13,6 +13,14 @@
{% endif %} {% endif %}
</span> </span>
</div> </div>
{% if perms.trans.delete_comment %}
<form method="POST" action="{% url 'delete-comment' pk=comment.pk %}">
{% csrf_token %}
<input type="hidden" name="next" value="{{ next_url }}" />
<button class="btn btn-danger btn-xs pull-right flip"><i class="fa fa-trash"></i> {% trans "Delete" %}</button>
</form>
<div class="clearfix"></div>
{% endif %}
<div class="list-group"> <div class="list-group">
<div class="list-group-item" dir="auto">{{ comment.comment }}</div> <div class="list-group-item" dir="auto">{{ comment.comment }}</div>
</div> </div>
......
...@@ -281,7 +281,9 @@ ...@@ -281,7 +281,9 @@
<div class="panel panel-primary"> <div class="panel panel-primary">
<div class="panel-heading"><h4 class="panel-title">{% trans "Comments" %}</h4></div> <div class="panel-heading"><h4 class="panel-title">{% trans "Comments" %}</h4></div>
<div class="panel-body"> <div class="panel-body">
{% with this_unit_url as next_url %}
{% include "list-comments.html" %} {% include "list-comments.html" %}
{% endwith %}
</div> </div>
</div> </div>
{% endif %} {% endif %}
......
...@@ -19,6 +19,7 @@ ...@@ -19,6 +19,7 @@
# #
from django.shortcuts import render, get_object_or_404, redirect from django.shortcuts import render, get_object_or_404, redirect
from django.views.decorators.http import require_POST
from django.utils.translation import ugettext as _ from django.utils.translation import ugettext as _
from django.http import HttpResponseRedirect, HttpResponse from django.http import HttpResponseRedirect, HttpResponse
from django.contrib import messages from django.contrib import messages
...@@ -28,7 +29,8 @@ import uuid ...@@ -28,7 +29,8 @@ import uuid
import time import time
from weblate.trans.models import ( from weblate.trans.models import (
SubProject, Unit, Change, Comment, Suggestion, Dictionary SubProject, Unit, Change, Comment, Suggestion, Dictionary,
get_related_units,
) )
from weblate.trans.autofixes import fix_target from weblate.trans.autofixes import fix_target
from weblate.trans.forms import ( from weblate.trans.forms import (
...@@ -678,6 +680,27 @@ def comment(request, pk): ...@@ -678,6 +680,27 @@ def comment(request, pk):
return redirect(request.POST.get('next', translation)) return redirect(request.POST.get('next', translation))
@login_required
@require_POST
def delete_comment(request, pk):
"""
Deletes comment.
"""
comment = get_object_or_404(Comment, pk=pk)
comment.project.check_acl(request)
units = get_related_units(comment)
if units.exists():
fallback_url = units[0].get_absolute_url()
else:
fallback_url = comment.project.get_absolute_url()
comment.delete()
messages.info(request, _('Translation comment has been deleted.'))
return redirect(request.POST.get('next', fallback_url))
def get_zen_unitdata(translation, request): def get_zen_unitdata(translation, request):
''' '''
Loads unit data for zen mode. Loads unit data for zen mode.
......
...@@ -272,6 +272,11 @@ urlpatterns = patterns( ...@@ -272,6 +272,11 @@ urlpatterns = patterns(
'weblate.trans.views.edit.comment', 'weblate.trans.views.edit.comment',
name='comment', name='comment',
), ),
url(
r'^comment/(?P<pk>[0-9]+)/delete/$',
'weblate.trans.views.edit.delete_comment',
name='delete-comment',
),
# VCS manipulation - commit # VCS manipulation - commit
url( url(
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment