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

Add translation review (issue #1)

parent 0f1e7e62
...@@ -34,6 +34,9 @@ ...@@ -34,6 +34,9 @@
{% if perms.trans.upload_translation %} {% if perms.trans.upload_translation %}
<li><a href="#upload">{% trans "Upload" %}</a></li> <li><a href="#upload">{% trans "Upload" %}</a></li>
{% endif %} {% endif %}
{% if review_form %}
<li><a href="#review">{% trans "Review" %}</a></li>
{% endif %}
{% if autoform %} {% if autoform %}
<li><a href="#auto">{% trans "Automatic translation" %}</a></li> <li><a href="#auto">{% trans "Automatic translation" %}</a></li>
{% endif %} {% endif %}
...@@ -73,6 +76,18 @@ ...@@ -73,6 +76,18 @@
</div> </div>
{% endif %} {% 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 %} {% if autoform %}
<div id="auto"> <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> <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 @@ ...@@ -85,6 +100,7 @@
</form> </form>
</div> </div>
{% endif %} {% endif %}
</div> </div>
{% endblock %} {% endblock %}
......
...@@ -241,4 +241,5 @@ $(function() { ...@@ -241,4 +241,5 @@ $(function() {
} }
}, },
}); });
$("#id_date").datepicker();
}); });
...@@ -2,6 +2,7 @@ from django import forms ...@@ -2,6 +2,7 @@ from django import forms
from django.utils.translation import ugettext_lazy as _, ugettext from django.utils.translation import ugettext_lazy as _, ugettext
from django.utils.safestring import mark_safe from django.utils.safestring import mark_safe
from django.utils.encoding import smart_unicode from django.utils.encoding import smart_unicode
from django.forms import ValidationError
def escape_newline(value): def escape_newline(value):
''' '''
...@@ -121,3 +122,12 @@ class WordForm(forms.Form): ...@@ -121,3 +122,12 @@ class WordForm(forms.Form):
class DictUploadForm(forms.Form): class DictUploadForm(forms.Form):
file = forms.FileField(label = _('File')) file = forms.FileField(label = _('File'))
overwrite = forms.BooleanField(label = _('Overwrite existing'), required = False) 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): ...@@ -144,6 +144,12 @@ class UnitManager(models.Manager):
else: else:
return self.all() 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): def add_to_source_index(self, checksum, source, context, translation, writer):
writer.update_document( writer.update_document(
checksum = unicode(checksum), checksum = unicode(checksum),
......
...@@ -14,10 +14,11 @@ from django.core.urlresolvers import reverse ...@@ -14,10 +14,11 @@ from django.core.urlresolvers import reverse
from trans.models import Project, SubProject, Translation, Unit, Suggestion, Check, Dictionary, Change from trans.models import Project, SubProject, Translation, Unit, Suggestion, Check, Dictionary, Change
from lang.models import Language 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 util import is_plural, split_plural, join_plural
from accounts.models import Profile from accounts.models import Profile
from whoosh.analysis import StandardAnalyzer, StemmingAnalyzer from whoosh.analysis import StandardAnalyzer, StemmingAnalyzer
import datetime
import logging import logging
import os.path import os.path
import json import json
...@@ -316,6 +317,7 @@ def show_translation(request, project, subproject, lang): ...@@ -316,6 +317,7 @@ def show_translation(request, project, subproject, lang):
'form': form, 'form': form,
'autoform': autoform, 'autoform': autoform,
'search_form': search_form, 'search_form': search_form,
'review_form': ReviewForm(initial = {'date': datetime.date.today() - datetime.timedelta(days = 31)}),
})) }))
@login_required @login_required
...@@ -472,6 +474,9 @@ def parse_search_url(request): ...@@ -472,6 +474,9 @@ def parse_search_url(request):
search_context = True search_context = True
search_url = '' search_url = ''
if 'date' in request.REQUEST:
search_url += '&date=%s' % request.REQUEST['date']
return ( return (
rqtype, rqtype,
direction, direction,
...@@ -673,8 +678,19 @@ def translate(request, project, subproject, lang): ...@@ -673,8 +678,19 @@ def translate(request, project, subproject, lang):
# If we failed to get unit above or on no POST # If we failed to get unit above or on no POST
if unit is None: if unit is None:
# Apply search conditions reviewform = ReviewForm(request.GET)
if search_query != '':
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_exact: if search_exact:
query = Q() query = Q()
if search_source: 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