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