[damned-lies] Allowed archiving states on archived modules
- From: Claude Paroz <claudep src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [damned-lies] Allowed archiving states on archived modules
- Date: Sat, 8 Aug 2015 07:53:28 +0000 (UTC)
commit fea27d0f4d55c7201004b0fc99b6b2f71951648b
Author: Claude Paroz <claude 2xlibre net>
Date: Sat Aug 8 09:52:00 2015 +0200
Allowed archiving states on archived modules
Fixes bug #753074. Thanks Anders Jonsson for the report.
templates/vertimus/vertimus_detail.html | 18 ++++++++++--------
vertimus/models.py | 7 +++++++
vertimus/tests/tests.py | 13 +++++++++++++
vertimus/views.py | 9 +++++----
4 files changed, 35 insertions(+), 12 deletions(-)
---
diff --git a/templates/vertimus/vertimus_detail.html b/templates/vertimus/vertimus_detail.html
index a1a28f0..96f0f57 100644
--- a/templates/vertimus/vertimus_detail.html
+++ b/templates/vertimus/vertimus_detail.html
@@ -213,9 +213,18 @@ $(document).ready(function() {
<p><em>{% trans "No current actions." %}</em></p>
{% endif %}
-{% if level == 0 and not module.archived %}
+{% if level == 0 %}
<h2>{% trans "New Action" %}</h2>
+ {% if not user.is_authenticated %}
+ {% url 'login' as login_url %}
+ {% blocktrans with team_name=language.team.get_description %}You need <a href="{{ login_url }}">to be
authenticated</a> and member of the {{ team_name }} team.{% endblocktrans %}
+ {% endif %}
+
+ {% if module.archived %}
+ <p class="errornote">{% trans "This module has been archived. It is only kept for statistical purposes.
Please don't translate it any more." %}</p>
+ {% endif %}
+
{% if action_form %}
<form enctype="multipart/form-data"
action="{% url 'vertimus_by_stats_id' stats.id language.id %}"
@@ -242,13 +251,6 @@ $(document).ready(function() {
<tr>
</table>
</form>
- {% else %}
- {% url 'login' as login_url %}
- {% blocktrans with team_name=language.team.get_description %}You need <a href="{{ login_url }}">to be
authenticated</a> and member of the {{ team_name }} team.{% endblocktrans %}
- {% endif %}
-{% else %}
- {% if module.archived %}
- <p class="errornote">{% trans "This module has been archived. It is only kept for statistical purposes.
Please don't translate it any more." %}</p>
{% endif %}
{% endif %}
{% else %}
diff --git a/vertimus/models.py b/vertimus/models.py
index 8f4f406..4920efd 100644
--- a/vertimus/models.py
+++ b/vertimus/models.py
@@ -101,6 +101,13 @@ class State(models.Model):
self.save()
def _get_available_actions(self, person, action_names):
+ # For archived modules, the only possible action is to archive the state (by the coordinator only)
+ if self.branch.module.archived:
+ if self.name != 'None' and person.is_coordinator(self.language.team):
+ return [ActionAA()]
+ else:
+ return []
+
action_names.append('WC')
# Allow the coordinator to cancel current reserved state
if person.is_coordinator(self.language.team) and \
diff --git a/vertimus/tests/tests.py b/vertimus/tests/tests.py
index e4d0f04..084470e 100644
--- a/vertimus/tests/tests.py
+++ b/vertimus/tests/tests.py
@@ -495,6 +495,19 @@ class VertimusTest(TeamsAndRolesTests):
self.assertEqual(state.name, 'Translated')
+ def test_action_on_archived_module(self):
+ state = StateTranslated.objects.create(branch=self.b, domain=self.d, language=self.l)
+ self.m.archived = True
+ self.m.save()
+
+ # For an archived module, the only available action is to archive the state by a coord.
+ self.assertEqual(state.get_available_actions(self.pt), [])
+ self.assertEqual(state.get_available_actions(self.pcoo), [ActionAA()])
+
+ action = Action.new_by_name('AA', person=self.pcoo)
+ action.apply_on(state, {'send_to_ml': False})
+ self.assertEqual(state.name, 'None')
+
def test_delete(self):
""" Test that a whole module tree can be properly deleted """
state = StateNone(branch=self.b, domain=self.d, language=self.l)
diff --git a/vertimus/views.py b/vertimus/views.py
index edf905d..690b3ae 100644
--- a/vertimus/views.py
+++ b/vertimus/views.py
@@ -51,7 +51,9 @@ def vertimus_by_names(request, module_name, branch_name,
domain_name, locale_name, level="0"):
"""Access to Vertimus view by Branch, Domain and Language names"""
module = get_object_or_404(Module, name=module_name)
- branch = get_object_or_404(Branch, name=branch_name, module__id=module.id)
+ branch = get_object_or_404(
+ Branch.objects.select_related('module'), name=branch_name, module__id=module.id
+ )
domain = get_object_or_404(Domain, name=domain_name, module__id=module.id)
language = get_object_or_404(Language, locale=locale_name)
return vertimus(request, branch, domain, language, level=level)
@@ -89,6 +91,7 @@ def vertimus(request, branch, domain, language, stats=None, level="0"):
sequence_grandparent = state.get_action_sequence_from_level(level + 1)
grandparent_level = level + 1 if sequence_grandparent else None
+ action_form = None
if request.user.is_authenticated() and level == 0:
# Only authenticated user can act on the translation and it's not
# possible to edit an archived workflow
@@ -119,10 +122,8 @@ def vertimus(request, branch, domain, language, stats=None, level="0"):
urlresolvers.reverse('vertimus_by_names',
args=(branch.module.name, branch.name, domain.name,
language.locale)))
- else:
+ elif available_actions:
action_form = ActionForm(state, available_actions, has_ml)
- else:
- action_form = None
context = {
'pageSection': 'module',
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]