Commit f0c336b7 authored by Michal Čihař's avatar Michal Čihař

Use new_lang field from a resource instead of a project

Issue #507
Signed-off-by: default avatarMichal Čihař <michal@cihar.com>
parent 007803de
......@@ -84,7 +84,7 @@
<div class="panel panel-primary">
<div class="panel-heading"><h4 class="panel-title">{% trans "New translation" %}</h4></div>
<div class="panel-body">
{% if object.project.new_lang == 'url' %}
{% if object.new_lang == 'url' %}
<p>{% blocktrans with object.project.instructions as url %}Should your language be missing, please follow <a href="{{ url }}">translator instructions</a>.{% endblocktrans %}</p>
{% else %}
<p>{% trans "Please choose the language into which you would like to translate." %}</p>
......
......@@ -237,16 +237,6 @@ class Project(models.Model, PercentMixin, URLMixin, PathMixin):
raise PermissionDenied
def clean(self):
if self.new_lang == 'url' and self.instructions == '':
raise ValidationError(_(
'Please either fill in instructions URL '
'or use different option for adding new language.'
))
if self.license == '' and self.license_url != '':
raise ValidationError(_(
'License URL can not be used without license summary.'
))
try:
self.create_path()
except OSError as exc:
......
......@@ -1030,6 +1030,17 @@ class SubProject(models.Model, PercentMixin, URLMixin, PathMixin):
Validator fetches repository and tries to find translation files.
Then it checks them for validity.
'''
if self.new_lang == 'url' and self.instructions == '':
raise ValidationError(_(
'Please either fill in instructions URL '
'or use different option for adding new language.'
))
if self.license == '' and self.license_url != '':
raise ValidationError(_(
'License URL can not be used without license summary.'
))
# Skip validation if we don't have valid project
if self.project_id is None:
return
......
......@@ -582,8 +582,8 @@ class SubProjectTest(RepoTestCase):
subproject.full_clean
)
subproject.project.new_lang = 'add'
subproject.project.save()
subproject.new_lang = 'add'
subproject.save()
# Check that it warns about not supported format
self.assertRaisesMessage(
......
......@@ -210,8 +210,8 @@ class NewLangTest(ViewTestCase):
return self.create_po_new_base()
def test_none(self):
self.project.new_lang = 'none'
self.project.save()
self.new_lang = 'none'
self.save()
response = self.client.get(
reverse('subproject', kwargs=self.kw_subproject)
......@@ -219,7 +219,8 @@ class NewLangTest(ViewTestCase):
self.assertNotContains(response, 'New translation')
def test_url(self):
self.project.new_lang = 'url'
self.new_lang = 'url'
self.save()
self.project.instructions = 'http://example.com/instructions'
self.project.save()
......@@ -230,8 +231,8 @@ class NewLangTest(ViewTestCase):
self.assertContains(response, 'http://example.com/instructions')
def test_contact(self):
self.project.new_lang = 'contact'
self.project.save()
self.new_lang = 'contact'
self.save()
response = self.client.get(
reverse('subproject', kwargs=self.kw_subproject)
......@@ -256,8 +257,8 @@ class NewLangTest(ViewTestCase):
)
def test_add(self):
self.project.new_lang = 'add'
self.project.save()
self.new_lang = 'add'
self.save()
self.assertFalse(
self.subproject.translation_set.filter(
......
......@@ -453,7 +453,7 @@ def new_language(request, project, subproject):
request,
_('Chosen translation already exists in this project!')
)
elif obj.project.new_lang == 'contact':
elif obj.new_lang == 'contact':
notify_new_language(obj, language, request.user)
messages.success(
request,
......@@ -462,7 +462,7 @@ def new_language(request, project, subproject):
"sent to the project's maintainers."
)
)
elif obj.project.new_lang == 'add':
elif obj.new_lang == 'add':
obj.add_new_language(language, request)
else:
messages.error(
......
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