Merge pull request #837 from normanjaeckel/issue-822-additional-new
Disable deleting active versions of a motion
This commit is contained in:
commit
edad6115b4
@ -130,9 +130,11 @@
|
|||||||
<a href="{% model_url version %}" title="{% trans 'Show' %}" class="btn btn-mini">
|
<a href="{% model_url version %}" title="{% trans 'Show' %}" class="btn btn-mini">
|
||||||
<i class="icon-search"></i>
|
<i class="icon-search"></i>
|
||||||
</a>
|
</a>
|
||||||
<a href="{% model_url version 'delete' %}" title="{% trans 'Delete' %}" class="btn btn-mini">
|
{% if version != motion.active_version %}
|
||||||
<i class="icon-remove"></i>
|
<a href="{% model_url version 'delete' %}" title="{% trans 'Delete' %}" class="btn btn-mini">
|
||||||
</a>
|
<i class="icon-remove"></i>
|
||||||
|
</a>
|
||||||
|
{% endif %}
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
{% if forloop.last %}
|
{% if forloop.last %}
|
||||||
|
@ -303,10 +303,19 @@ class VersionDeleteView(DeleteView):
|
|||||||
success_url_name = 'motion_detail'
|
success_url_name = 'motion_detail'
|
||||||
|
|
||||||
def get_object(self):
|
def get_object(self):
|
||||||
motion_id = int(self.kwargs.get('pk'))
|
try:
|
||||||
version_number = int(self.kwargs.get('version_number'))
|
motion = Motion.objects.get(pk=int(self.kwargs.get('pk')))
|
||||||
return MotionVersion.objects.get(motion=motion_id,
|
except Motion.DoesNotExist:
|
||||||
version_number=version_number)
|
raise Http404('Motion %s not found.' % self.kwargs.get('pk'))
|
||||||
|
try:
|
||||||
|
version = MotionVersion.objects.get(
|
||||||
|
motion=motion,
|
||||||
|
version_number=int(self.kwargs.get('version_number')))
|
||||||
|
except MotionVersion.DoesNotExist:
|
||||||
|
raise Http404('Version %s not found.' % self.kwargs.get('version_number'))
|
||||||
|
if version == motion.active_version:
|
||||||
|
raise Http404('You can not delete the active version of a motion.')
|
||||||
|
return version
|
||||||
|
|
||||||
def get_success_url_name_args(self):
|
def get_success_url_name_args(self):
|
||||||
return (self.object.motion_id, )
|
return (self.object.motion_id, )
|
||||||
@ -333,7 +342,7 @@ class VersionPermitView(SingleObjectMixin, QuestionMixin, RedirectView):
|
|||||||
try:
|
try:
|
||||||
self.version = self.object.versions.get(version_number=int(version_number))
|
self.version = self.object.versions.get(version_number=int(version_number))
|
||||||
except MotionVersion.DoesNotExist:
|
except MotionVersion.DoesNotExist:
|
||||||
raise Http404('Version %s not found' % version_number)
|
raise Http404('Version %s not found.' % version_number)
|
||||||
return super(VersionPermitView, self).get(*args, **kwargs)
|
return super(VersionPermitView, self).get(*args, **kwargs)
|
||||||
|
|
||||||
def get_url_name_args(self):
|
def get_url_name_args(self):
|
||||||
|
@ -150,7 +150,7 @@ class ModelTest(TestCase):
|
|||||||
motion = Motion.objects.create(title='foo', text='bar', identifier='')
|
motion = Motion.objects.create(title='foo', text='bar', identifier='')
|
||||||
motion.active_version = None
|
motion.active_version = None
|
||||||
motion.save(update_fields=['active_version'])
|
motion.save(update_fields=['active_version'])
|
||||||
self.assertEqual(str(motion), 'foo') # motion.__unicode__() did rais an AttributeError
|
self.assertEqual(str(motion), 'foo') # motion.__unicode__() raised an AttributeError
|
||||||
|
|
||||||
|
|
||||||
class ConfigTest(TestCase):
|
class ConfigTest(TestCase):
|
||||||
|
@ -412,6 +412,7 @@ class TestVersionPermitView(MotionViewTestCase):
|
|||||||
|
|
||||||
class TestVersionDeleteView(MotionViewTestCase):
|
class TestVersionDeleteView(MotionViewTestCase):
|
||||||
def test_get(self):
|
def test_get(self):
|
||||||
|
self.motion1.save(use_version=self.motion1.get_new_version(title='new', text='new'))
|
||||||
response = self.check_url('/motion/1/version/1/del/', self.admin_client, 302)
|
response = self.check_url('/motion/1/version/1/del/', self.admin_client, 302)
|
||||||
self.assertRedirects(response, '/motion/1/version/1/')
|
self.assertRedirects(response, '/motion/1/version/1/')
|
||||||
|
|
||||||
@ -424,3 +425,10 @@ class TestVersionDeleteView(MotionViewTestCase):
|
|||||||
response = self.admin_client.post('/motion/1/version/2/del/', {'yes': 1})
|
response = self.admin_client.post('/motion/1/version/2/del/', {'yes': 1})
|
||||||
self.assertRedirects(response, '/motion/1/')
|
self.assertRedirects(response, '/motion/1/')
|
||||||
self.assertEqual(self.motion1.versions.count(), 2)
|
self.assertEqual(self.motion1.versions.count(), 2)
|
||||||
|
|
||||||
|
def test_delete_active_version(self):
|
||||||
|
self.motion1.save(use_version=self.motion1.get_new_version(title='new_title_yae6Aequaiw5saeb8suG', text='new'))
|
||||||
|
motion = Motion.objects.all()[0]
|
||||||
|
self.assertEqual(motion.get_active_version().title, 'new_title_yae6Aequaiw5saeb8suG')
|
||||||
|
response = self.admin_client.post('/motion/1/version/2/del/', {'yes': 1})
|
||||||
|
self.assertEqual(response.status_code, 404)
|
||||||
|
Loading…
Reference in New Issue
Block a user