damned-lies r1241 - in trunk: . stats stats/tests templates templates/vertimus vertimus vertimus/tests
- From: claudep svn gnome org
- To: svn-commits-list gnome org
- Subject: damned-lies r1241 - in trunk: . stats stats/tests templates templates/vertimus vertimus vertimus/tests
- Date: Wed, 24 Dec 2008 22:12:10 +0000 (UTC)
Author: claudep
Date: Wed Dec 24 22:12:10 2008
New Revision: 1241
URL: http://svn.gnome.org/viewvc/damned-lies?rev=1241&view=rev
Log:
2008-12-24 Claude Paroz <claude 2xlibre net>
* settings_sample.py: MEDIA_URL should contain ending slash.
* stats/models.py: Prepare subclassed save function in order to act on
vcs_root change (TODO). Allow creation of a branch without checkout(),
useful for test suites.
* stats/tests/__init__.py: Missing parameter to update_stats.
* templates/base.html: Log in link is important now.
* templates/vertimus/vertimus_detail.html: Use MEDIA_URL to compose link.
* vertimus/models.py:
* vertimus/views.py: File saving is handled through FileField and not
manually.
* vertimus/tests/__init__.py: apply_action needs a real file object.
Modified:
trunk/ChangeLog
trunk/settings_sample.py
trunk/stats/models.py
trunk/stats/tests/__init__.py
trunk/templates/base.html
trunk/templates/vertimus/vertimus_detail.html
trunk/vertimus/models.py
trunk/vertimus/tests/__init__.py
trunk/vertimus/views.py
Modified: trunk/settings_sample.py
==============================================================================
--- trunk/settings_sample.py (original)
+++ trunk/settings_sample.py Wed Dec 24 22:12:10 2008
@@ -68,7 +68,7 @@
# URL that handles the media served from MEDIA_ROOT. Make sure to use a
# trailing slash if there is a path component (optional in other cases).
# Examples: "http://media.lawrence.com", "http://example.com/media/"
-MEDIA_URL = 'media'
+MEDIA_URL = '/media/'
# By default, Django stores files locally, using the MEDIA_ROOT and MEDIA_URL settings
UPLOAD_DIR = 'upload'
Modified: trunk/stats/models.py
==============================================================================
--- trunk/stats/models.py (original)
+++ trunk/stats/models.py Wed Dec 24 22:12:10 2008
@@ -73,6 +73,10 @@
def get_absolute_url(self):
return ('stats.views.module', [self.name])
+ def save(self, force_insert=False, force_update=False):
+ super(Module, self).save(force_insert, force_update)
+ #FIXME: delete and recreate branch if vcs_root changed?
+
def get_description(self):
if self.description:
return _(self.description)
@@ -116,10 +120,11 @@
class BranchCharField(models.CharField):
def pre_save(self, model_instance, add):
""" Check if branch is valid before saving the instance """
- try:
- model_instance.checkout()
- except:
- raise ValueError("Branch not valid: error while checking out the branch.")
+ if model_instance.checkout_on_creation:
+ try:
+ model_instance.checkout()
+ except:
+ raise ValueError("Branch not valid: error while checking out the branch.")
return getattr(model_instance, self.attname)
class Branch(models.Model):
@@ -129,6 +134,9 @@
vcs_subpath = models.CharField(max_length=50, null=True, blank=True)
module = models.ForeignKey(Module)
# 'releases' is the backward relation name from Release model
+
+ # May be set to False by test suite
+ checkout_on_creation = True
class Meta:
db_table = 'branch'
Modified: trunk/stats/tests/__init__.py
==============================================================================
--- trunk/stats/tests/__init__.py (original)
+++ trunk/stats/tests/__init__.py Wed Dec 24 22:12:10 2008
@@ -82,7 +82,7 @@
f.write("dummy_file.h")
f.close()
# Regenerate stats (mail should be sent)
- branch.update_stats()
+ branch.update_stats(force=False)
# Assertions
self.assertEquals(len(mail.outbox), 1);
self.assertEquals(mail.outbox[0].subject, "String additions to '%s'")
Modified: trunk/templates/base.html
==============================================================================
--- trunk/templates/base.html (original)
+++ trunk/templates/base.html Wed Dec 24 22:12:10 2008
@@ -83,7 +83,7 @@
{% if user.is_authenticated %}
{% blocktrans with user|linked_with:user.username|safe as username %}Logged in as: {{ username }}{% endblocktrans %}
{% else %}
- <!-- Not useful right now <a href="{% url login %}">{% trans "Log in" %}</a> -->
+ <a href="{% url login %}">{% trans "Log in" %}</a>
{% endif %}
</div>
Modified: trunk/templates/vertimus/vertimus_detail.html
==============================================================================
--- trunk/templates/vertimus/vertimus_detail.html (original)
+++ trunk/templates/vertimus/vertimus_detail.html Wed Dec 24 22:12:10 2008
@@ -24,7 +24,7 @@
{% endifnotequal %}
</h3>
-<a href="{{ stats.po_url }}"><img src="/media/img/download.png" alt="Download POT file" /></a>
+<a href="{{ stats.po_url }}"><img src="{{ MEDIA_URL }}img/download.png" alt="Download POT file" /></a>
{{ stats.pot_text }}
{% if stats.information_set.all %}
Modified: trunk/vertimus/models.py
==============================================================================
--- trunk/vertimus/models.py (original)
+++ trunk/vertimus/models.py Wed Dec 24 22:12:10 2008
@@ -18,6 +18,8 @@
# along with Damned Lies; if not, write to the Free Software Foundation, Inc.,
# 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+import os
+
from datetime import datetime
from django.db import models
from django.utils.translation import ugettext as _
@@ -247,6 +249,14 @@
'IC', 'TR',
'BA', 'UNDO')
+def generate_upload_file_name(instance, original_filename):
+ filename = "%s-%s-%s-%s-%s.po" % (instance.state_db.branch.module.name,
+ instance.state_db.branch.name,
+ instance.state_db.domain.name,
+ instance.state_db.language.locale,
+ instance.state_db.id)
+ return "%s/%s" % (settings.UPLOAD_DIR, filename)
+
class ActionDb(models.Model):
state_db = models.ForeignKey(StateDb)
person = models.ForeignKey(Person)
@@ -255,7 +265,7 @@
description = None
created = models.DateTimeField(auto_now_add=True, editable=False)
comment = models.TextField(blank=True, null=True)
- file = models.FileField(upload_to=settings.UPLOAD_DIR, blank=True, null=True)
+ file = models.FileField(upload_to=generate_upload_file_name, blank=True, null=True)
class Meta:
db_table = 'action'
@@ -276,7 +286,7 @@
def __unicode__(self):
return self.name
-
+
class ActionAbstract(object):
"""Abstract class"""
@@ -305,6 +315,8 @@
"""Used by apply"""
self._action_db = ActionDb(state_db=state._state_db,
person=person, name=self.name, comment=comment, file=file)
+ if file:
+ self._action_db.file.save(file.name, file, save=False)
self._action_db.save()
def __unicode__(self):
@@ -492,6 +504,9 @@
self.send_mail_new_state(state, new_state, (state.language.team.mailing_list,))
return new_state
+def generate_backup_file_name(instance, original_filename):
+ return "%s/%s" % (settings.UPLOAD_BACKUP_DIR, original_filename)
+
class ActionDbBackup(models.Model):
state_db = models.ForeignKey(StateDb)
person = models.ForeignKey(Person)
@@ -499,7 +514,7 @@
name = models.SlugField(max_length=8)
created = models.DateField(auto_now_add=True, editable=False)
comment = models.TextField(blank=True, null=True)
- file = models.FileField(upload_to=settings.UPLOAD_BACKUP_DIR, blank=True, null=True)
+ file = models.FileField(upload_to=generate_backup_file_name, blank=True, null=True)
sequence = models.IntegerField(blank=True, null=True)
class Meta:
@@ -519,13 +534,18 @@
sequence = None
for action_db in actions_db:
+ file_to_backup = None
+ if action_db.file:
+ file_to_backup = action_db.file.file # get a file object, not a filefield
action_db_backup = ActionDbBackup(
state_db=action_db.state_db,
person=action_db.person,
name=action_db.name,
created=action_db.created,
comment=action_db.comment,
- file=action_db.file)
+ file=file_to_backup)
+ if file_to_backup:
+ action_db_backup.file.save(os.path.basename(action_db.file.name), file_to_backup, save=False)
action_db_backup.save()
if sequence == None:
@@ -533,15 +553,7 @@
action_db_backup.sequence = sequence
action_db_backup.save()
- if action_db.file:
- # Move the file to UPLOAD_BACKUP_DIR
- # FIXME Hack
- default_storage.save(
- settings.UPLOAD_BACKUP_DIR + '/' + action_db.file.name[len(settings.UPLOAD_DIR):],
- action_db.file)
- default_storage.delete(action_db.file.path)
-
- action_db.delete()
+ action_db.delete() # The file is also automatically deleted, if it is not referenced elsewhere
return self._new_state()
Modified: trunk/vertimus/tests/__init__.py
==============================================================================
--- trunk/vertimus/tests/__init__.py (original)
+++ trunk/vertimus/tests/__init__.py Wed Dec 24 22:12:10 2008
@@ -18,8 +18,9 @@
# along with Damned Lies; if not, write to the Free Software Foundation, Inc.,
# 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+import os
+
from django.test import TestCase
-from django.core.files.storage import default_storage
from django.core.files.base import ContentFile
from django.conf import settings
@@ -77,6 +78,7 @@
vcs_web="http://svn.gnome.org/viewvc/gedit")
self.m.save()
+ Branch.checkout_on_creation = False
self.b = Branch(name='gnome-2-24', module=self.m)
# Block the update of Statistics by the thread
self.b.save(update_statistics=False)
@@ -255,8 +257,11 @@
state = StateDb(branch=self.b, domain=self.d, language=self.l, name='Translating', person=self.pt).get_state()
state.save()
+ test_file = ContentFile('test content')
+ test_file._name = 'mytestfile.po'
+
action = ActionAbstract.new_by_name('UT')
- new_state = state.apply_action(action, self.pt, "Done by translator.", 'myfile.po')
+ new_state = state.apply_action(action, self.pt, "Done by translator.", test_file)
new_state.save()
def test_action_rp(self):
@@ -271,8 +276,11 @@
state = StateDb(branch=self.b, domain=self.d, language=self.l, name='Proofreading', person=self.pr).get_state()
state.save()
+ test_file = ContentFile('test content')
+ test_file._name = 'mytestfile.po'
+
action = ActionAbstract.new_by_name('UP')
- new_state = state.apply_action(action, self.pr, "Done.", 'myfile.po')
+ new_state = state.apply_action(action, self.pr, "Done.", test_file)
new_state.save()
def test_action_tc(self):
@@ -312,13 +320,16 @@
state.save()
# Create a new file
- filename = 'mytestfile.po'
- path = default_storage.save(settings.UPLOAD_DIR + filename, ContentFile('test content'))
+ test_file = ContentFile('test content')
+ test_file._name = 'mytestfile.po'
action = ActionAbstract.new_by_name('UP')
- state = state.apply_action(action, self.pr, "Done.", path)
+ state = state.apply_action(action, self.pr, "Done.", test_file)
state.save()
+ file_path = os.path.join(settings.MEDIA_ROOT, action.file.name)
+ self.assert_(os.access(file_path, os.W_OK))
+
action = ActionAbstract.new_by_name('TC')
state = state.apply_action(action, self.pc, "To commit.")
state.save()
@@ -335,11 +346,13 @@
state = state.apply_action(action, self.pc, comment="I don't want to disappear")
state.save()
- self.assert_(not default_storage.exists(path))
- self.assert_(default_storage.exists(settings.UPLOAD_BACKUP_DIR + '/' + filename))
-
+ self.assert_(not os.access(file_path, os.F_OK))
+
# Remove test file
- default_storage.delete(settings.UPLOAD_BACKUP_DIR + '/' + filename)
+ backup_action = ActionDbBackup.objects.get(comment="Done.")
+ backup_file_path = os.path.join(settings.MEDIA_ROOT, backup_action.file.name)
+ backup_action.delete()
+ self.assert_(not os.access(backup_file_path, os.F_OK))
def test_action_undo(self):
state = StateDb(branch=self.b, domain=self.d, language=self.l, name='None').get_state()
Modified: trunk/vertimus/views.py
==============================================================================
--- trunk/vertimus/views.py (original)
+++ trunk/vertimus/views.py Wed Dec 24 22:12:10 2008
@@ -26,7 +26,6 @@
from django import forms
from django.core import urlresolvers
from django.conf import settings
-from django.core.files.storage import default_storage
from people.models import Person
from stats.models import Statistics, Module, Branch, Domain, Language
@@ -68,13 +67,6 @@
return vertimus(request, branch, domain, language)
-def handle_uploaded_file(f, branch, domain, language):
- filename = "%s-%s-%s-%s.po" % (branch.module.name, branch.name, domain.name, language.locale)
- path = default_storage.save(settings.UPLOAD_DIR + '/' + filename, f)
-
- # Keep only the new filename (duplicate files)
- return path
-
def vertimus(request, branch, domain, language, stats=None):
"""The Vertimus view and form management"""
if not stats:
@@ -102,13 +94,8 @@
action = action_form.cleaned_data['action']
comment = action_form.cleaned_data['comment']
- if 'file' in request.FILES:
- file = handle_uploaded_file(request.FILES['file'], branch, domain, language)
- else:
- file = None
-
action = ActionAbstract.new_by_name(action)
- new_state = state.apply_action(action, person, comment, file)
+ new_state = state.apply_action(action, person, comment, request.FILES.get('file',None))
new_state.save()
return HttpResponseRedirect(
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]