Before saving a new l10n Document, make sure the Revision submitted is valid. [bug 611357]

This commit is contained in:
Ricky Rosario 2010-11-11 15:31:21 -05:00
Родитель 919257d8b7
Коммит 76869f1a88
2 изменённых файлов: 17 добавлений и 1 удалений

Просмотреть файл

@ -709,6 +709,16 @@ class TranslateTests(TestCaseBase):
response = self.client.post(url, data)
eq_(200, response.status_code)
def test_invalid_revision_form(self):
"""When creating a new translation, an invalid revision form shouldn't
result in a new Document being created."""
url = reverse('wiki.translate', locale='es', args=[self.d.slug])
data = _translation_data()
data['content'] = '' # Content is required
response = self.client.post(url, data)
eq_(200, response.status_code)
eq_(0, self.d.translations.count())
@mock.patch_object(wiki.tasks.send_ready_for_review_notification, 'delay')
@mock.patch_object(wiki.tasks.send_edited_notification, 'delay')
@mock.patch_object(Site.objects, 'get_current')

Просмотреть файл

@ -412,7 +412,13 @@ def translate(request, document_slug):
doc_form = DocumentForm(post_data, instance=doc)
doc_form.instance.locale = request.locale
doc_form.instance.parent = parent_doc
if doc_form.is_valid():
if which_form == 'both':
rev_form = RevisionForm(request.POST)
# If we are submitting the whole form, we need to check that
# the Revision is valid before saving the Document.
if doc_form.is_valid() and (which_form == 'doc' or
rev_form.is_valid()):
doc = doc_form.save(parent_doc)
# Possibly schedule a rebuild.