[damned-lies] Provide a way to consult action history after a commit (Bug #567973)
- From: Stéphane Raimbault <stephaner src gnome org>
- To: svn-commits-list gnome org
- Subject: [damned-lies] Provide a way to consult action history after a commit (Bug #567973)
- Date: Fri, 29 May 2009 19:57:17 -0400 (EDT)
commit 79f56baa1869475a37968ceb8fd638346f3ba5b8
Author: Stéphane Raimbault <stephane raimbault gmail com>
Date: Sat May 30 01:43:23 2009 +0200
Provide a way to consult action history after a commit (Bug #567973)
- new CSS class for the links
- load humanize for grandparent level
- new method to get the cycle sequence
- ActionDbArchived has now a similar behaviour to ActionDb
- new formatting of urls.py (to appy to other files if found nice)
- new URL
---
media/css/main.css | 60 ++++++++-------
stats/models.py | 8 +-
templates/base.html | 4 +-
templates/vertimus/vertimus_detail.html | 106 +++++++++++++++++++-------
vertimus/models.py | 125 ++++++++++++++++++++-----------
vertimus/urls.py | 24 +++++-
vertimus/views.py | 50 +++++++++----
7 files changed, 253 insertions(+), 124 deletions(-)
diff --git a/media/css/main.css b/media/css/main.css
index 97c5a69..9feb88c 100644
--- a/media/css/main.css
+++ b/media/css/main.css
@@ -2,33 +2,35 @@ table.stats {
width: 100%;
}
-.stats th {
- text-align: left;
- background: gray;
+.stats th {
+ text-align: left;
+ background: gray;
color: white;
padding-left: 2px;
- padding-right: 2px;
+ padding-right: 2px;
}
-.stats td {
- background: #f0f0f0;
+.stats td {
+ background: #f0f0f0;
text-align: center;
padding-left: 2px;
padding-right: 2px;
color: black;
}
-.stats td.leftcell {
+.stats td.leftcell {
text-align: left;
}
td.supported {
color: #FFFFFF;
- background-color: green;
+ background-color: green;
}
+
td.partially {
background-color: orange;
}
+
td.not_supported {
}
@@ -70,10 +72,10 @@ div.graphinline {
}
div.translated {
- position: absolute;
+ position: absolute;
top: 0px;
- height:100%;
- left: 0%;
+ height:100%;
+ left: 0%;
background: #448844;
background: url(../img/green-bar.png);
background-repeat: repeat-x;
@@ -81,9 +83,9 @@ div.translated {
}
div.goodchange {
- position: absolute;
+ position: absolute;
top: 0px;
- height:100%;
+ height:100%;
background: #55DD55;
background: url(../img/cyan-bar.png);
background-repeat: repeat-x;
@@ -91,9 +93,9 @@ div.goodchange {
}
div.fuzzy {
- position: absolute;
+ position: absolute;
top: 0px;
- height:100%;
+ height:100%;
background: #4444AA;
background: url(../img/purple-bar.png);
background-repeat: repeat-x;
@@ -101,8 +103,8 @@ div.fuzzy {
}
div.untranslated {
- position: absolute;
- height:100%;
+ position: absolute;
+ height:100%;
top: 0px;
background: #FF4444;
background: url(../img/red-bar.png);
@@ -239,6 +241,11 @@ p#show, p#hide {
}
/* Used in vertimus_detail */
+#vertimus_actions_title a {
+ font-size: small;
+ font-weight: normal;
+}
+
.vertimus_action {
margin: 1em 0 1.5em;
border: solid #ddd 1px;
@@ -279,17 +286,17 @@ div.uploaded_file {
ul.errorlist {
list-style: none;
margin-left: 0;
- padding: 0;
+ padding: 0;
}
-.errorlist li {
- font-size: 12px !important;
- display: block;
- padding: 4px 5px 4px 25px;
- margin: 0 0 3px 0;
- border: 1px solid red;
- color: white;
- background: red url(../img/admin/icon_alert.gif) 5px .3em no-repeat;
+.errorlist li {
+ font-size: 12px !important;
+ display: block;
+ padding: 4px 5px 4px 25px;
+ margin: 0 0 3px 0;
+ border: 1px solid red;
+ color: white;
+ background: red url(../img/admin/icon_alert.gif) 5px .3em no-repeat;
}
.footnote {
@@ -299,3 +306,4 @@ ul.errorlist {
margin-top: 20px;
color: #aaaaaa;
}
+
diff --git a/stats/models.py b/stats/models.py
index a898e11..a212e1c 100644
--- a/stats/models.py
+++ b/stats/models.py
@@ -22,13 +22,13 @@
import os, sys, re, hashlib
import threading
from datetime import datetime
-from django.db import models, connection
+
+from django.conf import settings
from django.utils.translation import ungettext, ugettext as _, ugettext_noop
from django.utils import dateformat
-from django.conf import settings
-from stats import utils
-from stats import signals
+from django.db import models, connection
+from stats import utils, signals
from people.models import Person
from languages.models import Language
diff --git a/templates/base.html b/templates/base.html
index ba2467f..6b4ee51 100644
--- a/templates/base.html
+++ b/templates/base.html
@@ -15,7 +15,7 @@
<link rel="stylesheet" href="/media/css/rtl.css"/>
{% endif %}
<script type="text/javascript" src="{{ MEDIA_URL }}js/main.js"></script>
- <script type="text/javascript" src="{{ MEDIA_URL }}js/jquery.min.js"></script>
+ <script type="text/javascript" src="{{ MEDIA_URL }}js/jquery.min.js"></script>
{% block extrahead %}
{% endblock %}
</head>
@@ -92,7 +92,7 @@
<div id="footer">
{% trans "Copyright © 2006-2009" %} <a href="http://www.gnome.org/">{% trans "The GNOME Project" %}</a>.
- <br />
+ <br />
{% trans "Maintained in the <a href='http://git.gnome.org/cgit/damned-lies/'>damned-lies</a> module on <a href='http://git.gnome.org/'>git.gnome.org</a>" %}
<br />
{% trans "Hosted by" %} <a href="http://www.canonical.com/">Canonical</a>.
diff --git a/templates/vertimus/vertimus_detail.html b/templates/vertimus/vertimus_detail.html
index 8be96ea..4c65ad4 100644
--- a/templates/vertimus/vertimus_detail.html
+++ b/templates/vertimus/vertimus_detail.html
@@ -1,5 +1,6 @@
{% extends "base.html" %}
{% load i18n %}
+{% load humanize %}
{% block title %}
{% blocktrans with module.get_description as name %}Module Translation: {{ name }}{% endblocktrans %}
@@ -12,13 +13,18 @@
{% if releases %}
<p><em>{% trans "Used in release(s):" %}</em><br />
{% for release in releases %}
- <a href="{% url languages.views.language_release language.locale, release.name, domain.dtype %}">{% trans release.description %}</a><br />
+ <a href="{% url languages.views.language_release language.locale,release.name,domain.dtype %}">
+ {% trans release.description %}
+ </a><br/>
{% endfor %}
{% endif %}
</div>
{% endwith %}
-<h1><a href="{% url stats.views.module module.name %}">{{ module.get_description }}</a> - {{ branch.name }} - {{ domain.get_description }} - {{ language.get_name }}</h1>
+<h1>
+<a href="{% url stats.views.module module.name %}">{{ module.get_description }}</a>
+- {{ branch.name }} - {{ domain.get_description }} - {{ language.get_name }}
+</h1>
{% if module.comment %}
<p>{{ module.comment|safe }}</p>
@@ -28,25 +34,30 @@
{% endif %}
{% endif %}
-<h3>{% trans "State:" %} {{ state.description }}
+<h3>
+{% trans "State:" %} {{ state.description }}
{% ifnotequal state.name 'none' %}
({{ state.updated|date:_("Y-m-d g:i a O") }})
{% endifnotequal %}
</h3>
<div style="line-height: 1.7">
-<em><a href="{{ stats.pot_url }}"><img src="{{ MEDIA_URL }}img/download.png" alt="{% trans "Download POT file" %}" /></a> {{ stats.pot_text }}</em><br />
-<a href="{{ po_url }}"><img src="{{ MEDIA_URL }}img/download.png" alt="{% trans "Download PO file" %}" /></a> {% trans "Translated:" %}
-{{ stats.get_translationstat|safe }}
-<div class="graph graphinline">
- <div class="translated" style="width: {{ stats.tr_percentage }}px;"></div>
- <div class="fuzzy" style="{{ LANGUAGE_BIDI|yesno:"right,left" }}:{{ stats.tr_percentage }}px; width:{{ stats.fu_percentage }}px;"></div>
- <div class="untranslated" style="{{ LANGUAGE_BIDI|yesno:"right,left" }}:{{ stats.tr_percentage|add:stats.fu_percentage }}px; width: {{ stats.un_percentage }}px;"></div>
-</div>
-{% if stats.fig_count and stats.language %}
- <a href="{% url stats.views.docimages module_name=module.name,potbase=stats.domain.name,branch_name=branch.name,langcode=stats.language.locale %}">
- <img src="{{ MEDIA_URL }}img/figure.png" alt="{% trans "Display document figures" %}"></a>
-{% endif %}
+ <em><a href="{{ stats.pot_url }}">
+ <img src="{{ MEDIA_URL }}img/download.png" alt="{% trans "Download POT file" %}" /></a>
+ {{ stats.pot_text }}
+ </em>
+ <br/>
+ <a href="{{ po_url }}"><img src="{{ MEDIA_URL }}img/download.png" alt="{% trans "Download PO file" %}" /></a> {% trans "Translated:" %}
+ {{ stats.get_translationstat|safe }}
+ <div class="graph graphinline">
+ <div class="translated" style="width: {{ stats.tr_percentage }}px;"></div>
+ <div class="fuzzy" style="{{ LANGUAGE_BIDI|yesno:"right,left" }}:{{ stats.tr_percentage }}px; width:{{ stats.fu_percentage }}px;"></div>
+ <div class="untranslated" style="{{ LANGUAGE_BIDI|yesno:"right,left" }}:{{ stats.tr_percentage|add:stats.fu_percentage }}px; width: {{ stats.un_percentage }}px;"></div>
+ </div>
+ {% if stats.fig_count and stats.language %}
+ <a href="{% url stats.views.docimages module_name=module.name,potbase=stats.domain.name,branch_name=branch.name,langcode=stats.language.locale %}">
+ <img src="{{ MEDIA_URL }}img/figure.png" alt="{% trans "Display document figures" %}"></a>
+ {% endif %}
</div>
{% if stats.information_set.all %}
@@ -63,29 +74,56 @@
{% if other_states %}
<div style="margin-top:0.5em;">
- <img src="{{ MEDIA_URL }}img/warn.png" alt="Warning logo" /> {% trans "On-going activities in same module:" %}
+ <img src="{{ MEDIA_URL }}img/warn.png" alt="Warning logo" />
+ {% trans "On-going activities in same module:" %}
{% for st in other_states %}
- <a href="{% url vertimus-ids-view st.branch.pk st.domain.pk st.language.pk %}">{{ st.branch.name }}</a>
+ <a href="{% url vertimus-ids-view st.branch.pk,st.domain.pk,st.language.pk %}">{{ st.branch.name }}</a>
{% endfor %}
</div>
{% endif %}
+<div id="vertimus_actions_title">
+ <h2>
+ {% ifequal level 0 %}
+ {% trans "Actions" %}
+ {% else %}
+ {% blocktrans with level|ordinal|safe as human_level %}
+ Archived Actions ({{ human_level }} grandparent)
+ {% endblocktrans %}
+ <a href="{% url vertimus-names-view module.name,branch.name,domain.name,language.locale %}">
+ {% trans "(Return to current)" %}
+ </a>
+ {% endifequal %}
+ {% if grandparent_level %}
+ <a href="{% url vertimus_archives_by_names module.name,branch.name,domain.name,language.locale,grandparent_level %}">
+ {% trans "(Previous action history)" %}
+ </a>
+ {% endif %}
+ </h2>
+</div>
+
{% if action_history %}
-<h2>{% trans "Action History" %}</h2>
<div>
{% for action,files in action_history %}
<div class="vertimus_action">
<div class="vertimus_action_head">
- <img src="{{ MEDIA_URL }}img/nobody-16.png" alt="Person"/> <a href="{{ action.person.get_absolute_url }}">{{ action.person.name }}</a>
+ <img src="{{ MEDIA_URL }}img/nobody-16.png" alt="Person"/>
+ <a href="{{ action.person.get_absolute_url }}">{{ action.person.name }}</a>
, <strong>{{ action }}</strong>, {{ action.created|date:_("Y-m-d g:i a O") }}
</div>
<div class="vertimus_action_content">
{% if action.file %}
<div class="uploaded_file">
- <a href="{{ action.file.url }}"><img src="{{ MEDIA_URL }}img/download.png"/> {{ action.get_filename }}</a><br />
+ <a href="{{ action.file.url }}">
+ <img src="{{ MEDIA_URL }}img/download.png"/> {{ action.get_filename }}
+ </a>
+ <br/>
{% if action.has_po_file %}
{% if action.merged_file.url %}
- <a href="{{ action.merged_file.url }}"><img src="{{ MEDIA_URL }}img/download.png"/> {{ action.merged_file.filename }}</a><br />
+ <a href="{{ action.merged_file.url }}">
+ <img src="{{ MEDIA_URL }}img/download.png"/> {{ action.merged_file.filename }}
+ </a>
+ <br/>
{% endif %}
<div class="right_actions">{% trans "diff with:" %}
{% for f in files %}
@@ -105,20 +143,30 @@
</div>
{% endfor %}
</div>
+{% else %}
+ <p><em>{% trans "No current actions." %}</em></p>
{% endif %}
-<h2>{% trans "New Action" %}</h2>
+{% ifequal level 0 %}
+ <h2>{% trans "New Action" %}</h2>
-{% if action_form %}
- <form enctype="multipart/form-data" action="{% url vertimus-stats-id-view stats.id language.id %}" method="POST">
+ {% if action_form %}
+ <form enctype="multipart/form-data"
+ action="{% url vertimus-stats-id-view stats.id language.id %}"
+ method="POST">
<table class="djform">
{{ action_form.as_table }}
- <tr><td></td>
- <td><input type="submit" value="{% trans "Submit" %}"></td><tr>
+ <tr>
+ <td></td>
+ <td><input type="submit" value="{% trans "Submit" %}"></td>
+ <tr>
</table>
</form>
-{% else %}
- {% blocktrans with language.team.get_description as team_name %}You need to be authenticated and to be member of the {{ team_name }} team.{% endblocktrans %}
-{% endif %}
+ {% else %}
+ {% blocktrans with language.team.get_description as team_name %}
+ You need to be authenticated and to be member of the {{ team_name }} team.
+ {% endblocktrans %}
+ {% endif %}
+{% endifequal %}
{% endblock %}
diff --git a/vertimus/models.py b/vertimus/models.py
index 54024bf..5423cd1 100644
--- a/vertimus/models.py
+++ b/vertimus/models.py
@@ -26,6 +26,7 @@ from django.core import mail, urlresolvers
from django.contrib.sites.models import Site
from django.conf import settings
from django.db.models.signals import post_save, pre_delete
+from django.db import connection
from stats.models import Branch, Domain, Statistics
from stats.signals import pot_has_changed
@@ -130,6 +131,29 @@ class StateAbstract(object):
else:
raise Exception('Not allowed')
+ def get_action_sequence_from_level(self, level):
+ """Get the sequence corresponding to the requested level.
+ The first level is 1."""
+ if level <= 0:
+ raise Exception("Level must be greater than 0")
+
+ # Raw SQL in waiting for Django 1.1.
+ query = """
+ SELECT sequence
+ FROM action_archived
+ WHERE state_db_id = %s
+ GROUP BY sequence
+ ORDER BY sequence DESC
+ LIMIT 1 OFFSET %s"""
+ cursor = connection.cursor()
+ cursor.execute(query, (self._state_db.id, level - 1))
+ try:
+ sequence = cursor.fetchone()[0]
+ except:
+ sequence = None
+
+ return sequence
+
def save(self):
self._state_db.save()
@@ -287,6 +311,32 @@ def generate_upload_filename(instance, filename):
ext)
return "%s/%s" % (settings.UPLOAD_DIR, new_filename)
+def action_db_get_action_history(cls, state_db=None, sequence=None):
+ """
+ Return action history as a list of tuples (action, file_history),
+ file_history is a list of previous po files, used in vertimus view to
+ generate diff links
+ """
+ history = []
+ if state_db or sequence:
+ file_history = [{'action_id':0, 'title': ugettext("File in repository")}]
+ if not sequence:
+ query = cls.objects.filter(state_db__id=state_db.id)
+ else:
+ # Not necessary to filter on state_db with a sequence (unique)
+ query = cls.objects.filter(sequence=sequence)
+ for action_db in query.order_by('id'):
+ history.append((action_db.get_action(), list(file_history)))
+ if action_db.file and action_db.file.path.endswith('.po'):
+ # Action.id and ActionDb.id are identical (inheritance)
+ file_history.insert(0, {
+ 'action_id': action_db.id,
+ 'title': ugettext("Uploaded file by %(name)s on %(date)s") % {
+ 'name': action_db.person.name,
+ 'date': action_db.created },
+ })
+ return history
+
class ActionDb(models.Model):
state_db = models.ForeignKey(StateDb)
person = models.ForeignKey(Person)
@@ -300,6 +350,9 @@ class ActionDb(models.Model):
class Meta:
db_table = 'action'
+ def __unicode__(self):
+ return "%s (%s)" % (self.name, self.id)
+
def get_action(self):
action = eval('Action' + self.name)()
action._action_db = self
@@ -311,7 +364,7 @@ class ActionDb(models.Model):
same state.
"""
try:
- action_db = ActionDb.objects.filter(file__endswith=".po", state_db=self.state_db,
+ action_db = self.objects.filter(file__endswith=".po", state_db=self.state_db,
id__lt=self.id).latest('id')
return action_db
except ActionDb.DoesNotExist:
@@ -329,29 +382,36 @@ class ActionDb(models.Model):
@classmethod
def get_action_history(cls, state_db):
- """
- Return action history as a list of tuples (action, file_history),
- file_history is a list of previous po files, used in vertimus view to
- generate diff links
- """
- history = []
- if state_db:
- file_history = [{'action_id':0, 'title': ugettext("File in repository")}]
- for action_db in ActionDb.objects.filter(state_db__id=state_db.id).order_by('id'):
- history.append((action_db.get_action(), list(file_history)))
- if action_db.file and action_db.file.path.endswith('.po'):
- # Action.id and ActionDb.id are identical (inheritance)
- file_history.insert(0, {
- 'action_id': action_db.id,
- 'title': ugettext("Uploaded file by %(name)s on %(date)s") % {
- 'name': action_db.person.name,
- 'date': action_db.created },
- })
- return history
+ return action_db_get_action_history(cls, state_db=state_db)
+
+def generate_archive_filename(instance, original_filename):
+ return "%s/%s" % (settings.UPLOAD_ARCHIVED_DIR, os.path.basename(original_filename))
+
+class ActionDbArchived(models.Model):
+ state_db = models.ForeignKey(StateDb)
+ person = models.ForeignKey(Person)
+
+ name = models.SlugField(max_length=8)
+ # Datetime copied from ActionDb
+ created = models.DateTimeField(editable=False)
+ comment = models.TextField(blank=True, null=True)
+ file = models.FileField(upload_to=generate_archive_filename, blank=True, null=True)
+ sequence = models.IntegerField()
+
+ class Meta:
+ db_table = 'action_archived'
def __unicode__(self):
return "%s (%s)" % (self.name, self.id)
+ def get_action(self):
+ action = eval('Action' + self.name)()
+ action._action_db = self
+ return action
+
+ @classmethod
+ def get_action_history(cls, sequence):
+ return action_db_get_action_history(cls, state_db=None, sequence=sequence)
class ActionAbstract(object):
"""Abstract class"""
@@ -664,31 +724,6 @@ class ActionTR(ActionAbstract):
self.send_mail_new_state(state, new_state, (state.language.team.mailing_list,))
return new_state
-def generate_archive_filename(instance, original_filename):
- return "%s/%s" % (settings.UPLOAD_ARCHIVED_DIR, os.path.basename(original_filename))
-
-class ActionDbArchived(models.Model):
- state_db = models.ForeignKey(StateDb)
- person = models.ForeignKey(Person)
-
- name = models.SlugField(max_length=8)
- # Datetime copied from ActionDb
- created = models.DateTimeField(editable=False)
- comment = models.TextField(blank=True, null=True)
- file = models.FileField(upload_to=generate_archive_filename, blank=True, null=True)
- sequence = models.IntegerField(blank=True, null=True)
-
- class Meta:
- db_table = 'action_archived'
-
- def __unicode__(self):
- return "%s (%s)" % (self.name, self.id)
-
- def get_action(self):
- action = eval('Action' + self.name)()
- action._action_db = self
- return action
-
class ActionAA(ActionAbstract):
name = 'AA'
description = _('Archive the actions')
diff --git a/vertimus/urls.py b/vertimus/urls.py
index 6438acd..6cce149 100644
--- a/vertimus/urls.py
+++ b/vertimus/urls.py
@@ -1,8 +1,24 @@
from django.conf.urls.defaults import *
urlpatterns = patterns('vertimus.views',
- url(r'^(?P<stats_id>\d+)/(?P<lang_id>\d+)$', 'vertimus_by_stats_id', name='vertimus-stats-id-view'),
- url(r'^(?P<branch_id>\d+)/(?P<domain_id>\d+)/(?P<language_id>\d+)', 'vertimus_by_ids', name='vertimus-ids-view'),
- url(r'^(?P<module_name>[\w\+\-\.]+)/(?P<branch_name>[\w\-\.]+)/(?P<domain_name>[\w\-]+)/(?P<locale_name>[\w\- ]+)', 'vertimus_by_names', name='vertimus-names-view'),
- url(r'^diff/(?P<action_id_1>\d+)/(?P<action_id_2>\d+)?$', 'vertimus_diff', name='vertimus-diff-view')
+ url(
+ regex = r'^(?P<stats_id>\d+)/(?P<lang_id>\d+)$',
+ view = 'vertimus_by_stats_id',
+ name = 'vertimus-stats-id-view'),
+ url(
+ regex = r'^(?P<branch_id>\d+)/(?P<domain_id>\d+)/(?P<language_id>\d+)',
+ view = 'vertimus_by_ids',
+ name = 'vertimus-ids-view'),
+ url(
+ regex = '^(?P<module_name>[\w\+\-\.]+)/(?P<branch_name>[\w\-\.]+)/(?P<domain_name>[\w\-]+)/(?P<locale_name>[\w\- ]+)/level(?P<level>\d+)/$',
+ view = 'vertimus_by_names',
+ name = 'vertimus_archives_by_names'),
+ url(
+ regex = r'^(?P<module_name>[\w\+\-\.]+)/(?P<branch_name>[\w\-\.]+)/(?P<domain_name>[\w\-]+)/(?P<locale_name>[\w\- ]+)',
+ view = 'vertimus_by_names',
+ name = 'vertimus-names-view'),
+ url(
+ regex = r'^diff/(?P<action_id_1>\d+)/(?P<action_id_2>\d+)?$',
+ view = 'vertimus_diff',
+ name = 'vertimus-diff-view')
)
diff --git a/vertimus/views.py b/vertimus/views.py
index 92de6b9..9182988 100644
--- a/vertimus/views.py
+++ b/vertimus/views.py
@@ -26,7 +26,7 @@ from django.template import RequestContext
from django.core import urlresolvers
from stats.models import Statistics, Module, Branch, Domain, Language
-from vertimus.models import StateDb, ActionDb, ActionAbstract
+from vertimus.models import StateDb, ActionDb, ActionDbArchived, ActionAbstract
from vertimus.forms import ActionForm
def vertimus_by_stats_id(request, stats_id, lang_id):
@@ -42,17 +42,21 @@ def vertimus_by_ids(request, branch_id, domain_id, language_id):
language = get_object_or_404(Language, pk=language_id)
return vertimus(request, branch, domain, language)
-def vertimus_by_names(request, module_name, branch_name, domain_name, locale_name):
- """Access to Vertimus view by Branch, Domain and language names"""
+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)
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)
- return vertimus(request, branch, domain, language)
+def vertimus(request, branch, domain, language, stats=None, level="0"):
+ """The Vertimus view and form management. Level argument is used to
+ access to the previous action history, first level (1) is the
+ grandparent, second (2) is the parent of the grandparent, etc."""
+ level = int(level)
-def vertimus(request, branch, domain, language, stats=None):
- """The Vertimus view and form management"""
if not stats:
try:
stats = Statistics.objects.get(branch=branch, domain=domain, language=language)
@@ -70,16 +74,29 @@ def vertimus(request, branch, domain, language, stats=None):
branch=branch,
domain=domain,
language=language)
- other_branch_states = StateDb.objects.filter(domain=domain, language=language).exclude(branch=branch.pk).exclude(name='None')
+ other_branch_states = StateDb.objects.filter(
+ domain=domain, language=language).exclude(branch=branch.pk).exclude(name='None')
state = state_db.get_state()
- action_history = ActionDb.get_action_history(state_db)
+ if level == 0:
+ # Current actions
+ action_history = ActionDb.get_action_history(state_db)
+ else:
+ sequence = state.get_action_sequence_from_level(level)
+ action_history = ActionDbArchived.get_action_history(sequence)
- if request.user.is_authenticated():
- # Only authenticated user can act on the translation
+ # Get the sequence of the grandparent to know if exists a previous action
+ # history
+ sequence_grandparent = state.get_action_sequence_from_level(level + 1)
+ grandparent_level = level + 1 if sequence_grandparent else 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
person = request.user.person
- available_actions = [(va.name, va.description) for va in state.get_available_actions(person)]
+ available_actions = [(va.name, va.description)
+ for va in state.get_available_actions(person)]
if request.method == 'POST':
action_form = ActionForm(available_actions, request.POST, request.FILES)
@@ -89,12 +106,14 @@ def vertimus(request, branch, domain, language, stats=None):
comment = action_form.cleaned_data['comment']
action = ActionAbstract.new_by_name(action)
- new_state = state.apply_action(action, person, comment, request.FILES.get('file', None))
+ new_state = state.apply_action(action, person, comment,
+ request.FILES.get('file', None))
new_state.save()
return HttpResponseRedirect(
urlresolvers.reverse('vertimus-names-view',
- args=(branch.module.name, branch.name, domain.name, language.locale)))
+ args=(branch.module.name, branch.name, domain.name,
+ language.locale)))
else:
action_form = ActionForm(available_actions)
else:
@@ -112,11 +131,14 @@ def vertimus(request, branch, domain, language, stats=None):
'non_standard_repo_msg' : _(settings.VCS_HOME_WARNING),
'state': state,
'action_history': action_history,
- 'action_form': action_form
+ 'action_form': action_form,
+ 'level': level,
+ 'grandparent_level': grandparent_level,
}
return render_to_response('vertimus/vertimus_detail.html', context,
context_instance=RequestContext(request))
+
def vertimus_diff(request, action_id_1, action_id_2=None):
"""Show a diff between current action po file and previous file"""
import difflib
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]