Commit 2cfbae07 authored by Michal Čihař's avatar Michal Čihař

Add translation review (issue #1)

parent 0f1e7e62
......@@ -34,6 +34,9 @@
{% if perms.trans.upload_translation %}
<li><a href="#upload">{% trans "Upload" %}</a></li>
{% endif %}
{% if review_form %}
<li><a href="#review">{% trans "Review" %}</a></li>
{% endif %}
{% if autoform %}
<li><a href="#auto">{% trans "Automatic translation" %}</a></li>
{% endif %}
......@@ -73,6 +76,18 @@
</div>
{% endif %}
{% if review_form %}
<div id="review">
<p>{% trans "Review translations touched by other users." %}</p>
<form action="{{ object.get_translate_url }}" method="GET">
<table>
{{ review_form.as_table }}
</table>
<p><input type="submit" value="{% trans "Process" %}" /></p>
</form>
</div>
{% endif %}
{% if autoform %}
<div id="auto">
<p>{% trans "Automatic translation takes existing translations in this project and applies it to current subproject. It can be used to push translations to different branch or to fix inconsistent translations." %}</p>
......@@ -85,6 +100,7 @@
</form>
</div>
{% endif %}
</div>
{% endblock %}
......
......@@ -241,4 +241,5 @@ $(function() {
}
},
});
$("#id_date").datepicker();
});
......@@ -2,6 +2,7 @@ from django import forms
from django.utils.translation import ugettext_lazy as _, ugettext
from django.utils.safestring import mark_safe
from django.utils.encoding import smart_unicode
from django.forms import ValidationError
def escape_newline(value):
'''
......@@ -121,3 +122,12 @@ class WordForm(forms.Form):
class DictUploadForm(forms.Form):
file = forms.FileField(label = _('File'))
overwrite = forms.BooleanField(label = _('Overwrite existing'), required = False)
class ReviewForm(forms.Form):
date = forms.DateField(label = _('Starting date'))
type = forms.CharField(widget = forms.HiddenInput, initial = 'review')
def clean_type(self):
if self.cleaned_data['type'] != 'review':
raise ValidationError('Invalid value')
return self.cleaned_data['type']
......@@ -144,6 +144,12 @@ class UnitManager(models.Manager):
else:
return self.all()
def review(self, date, user):
from trans.models import Change
sample = self.all()[0]
changes = Change.objects.filter(unit__translation = sample.translation, timestamp__gte = date).exclude(user = user)
return self.filter(id__in = changes.values_list('unit__id', flat = True))
def add_to_source_index(self, checksum, source, context, translation, writer):
writer.update_document(
checksum = unicode(checksum),
......
......@@ -14,10 +14,11 @@ from django.core.urlresolvers import reverse
from trans.models import Project, SubProject, Translation, Unit, Suggestion, Check, Dictionary, Change
from lang.models import Language
from trans.forms import TranslationForm, UploadForm, SimpleUploadForm, ExtraUploadForm, SearchForm, MergeForm, AutoForm, WordForm, DictUploadForm
from trans.forms import TranslationForm, UploadForm, SimpleUploadForm, ExtraUploadForm, SearchForm, MergeForm, AutoForm, WordForm, DictUploadForm, ReviewForm
from util import is_plural, split_plural, join_plural
from accounts.models import Profile
from whoosh.analysis import StandardAnalyzer, StemmingAnalyzer
import datetime
import logging
import os.path
import json
......@@ -316,6 +317,7 @@ def show_translation(request, project, subproject, lang):
'form': form,
'autoform': autoform,
'search_form': search_form,
'review_form': ReviewForm(initial = {'date': datetime.date.today() - datetime.timedelta(days = 31)}),
}))
@login_required
......@@ -472,6 +474,9 @@ def parse_search_url(request):
search_context = True
search_url = ''
if 'date' in request.REQUEST:
search_url += '&date=%s' % request.REQUEST['date']
return (
rqtype,
direction,
......@@ -673,8 +678,19 @@ def translate(request, project, subproject, lang):
# If we failed to get unit above or on no POST
if unit is None:
reviewform = ReviewForm(request.GET)
if reviewform.is_valid():
units = obj.unit_set.review(reviewform.cleaned_data['date'], request.user)
# Review
if direction == 'stay':
units = units.filter(position = pos)
elif direction == 'back':
units = units.filter(position__lt = pos).order_by('-position')
else:
units = units.filter(position__gt = pos)
elif search_query != '':
# Apply search conditions
if search_query != '':
if search_exact:
query = Q()
if search_source:
......
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