Merge pull request #847 from ostcar/issue-845
Fix get_absolute_url for deleted persons.
This commit is contained in:
commit
1b199e0295
@ -51,6 +51,20 @@ class Person(object):
|
||||
"""
|
||||
return ''
|
||||
|
||||
def get_absolute_url(self, link='detail'):
|
||||
"""
|
||||
Return an absolute url for the person.
|
||||
|
||||
The argument 'link' affects which url it is. Typically it is one of:
|
||||
* detail
|
||||
* edit
|
||||
* delete
|
||||
|
||||
You should raise an 'ValueError', if your person does not have
|
||||
one of this links.
|
||||
"""
|
||||
raise ValueError('This person object has no url.')
|
||||
|
||||
|
||||
class Persons(object):
|
||||
"""
|
||||
|
@ -81,7 +81,7 @@ class PersonMixin(object):
|
||||
% self)
|
||||
|
||||
def __unicode__(self):
|
||||
return 'MyPerson: %s' % self.person_id
|
||||
return self.person_id
|
||||
|
||||
def prepare_database_save(self, field):
|
||||
if type(field) is PersonField:
|
||||
|
@ -36,7 +36,10 @@ def trans(value):
|
||||
@register.simple_tag
|
||||
def model_url(object, link='view'):
|
||||
# TODO: Rename to object_url
|
||||
try:
|
||||
return object.get_absolute_url(link)
|
||||
except ValueError:
|
||||
return ''
|
||||
|
||||
|
||||
@register.filter
|
||||
|
@ -13,6 +13,9 @@ class TestPerson(PersonMixin, models.Model):
|
||||
def __unicode__(self):
|
||||
return self.name
|
||||
|
||||
def get_absolute_url(self, link='detail'):
|
||||
return 'absolute_url_of_test_person'
|
||||
|
||||
|
||||
class TestPersonToPerson(object):
|
||||
def __init__(self, person_prefix_filter=None, id_filter=None):
|
||||
|
@ -15,11 +15,12 @@ from django.db.models.query import EmptyQuerySet
|
||||
from django.contrib.auth.models import AnonymousUser
|
||||
|
||||
from openslides.utils.test import TestCase
|
||||
from openslides.utils.person.api import get_person
|
||||
|
||||
from .models import TestPerson, TestModel
|
||||
|
||||
|
||||
class ItemTest(TestCase):
|
||||
class PersonTest(TestCase):
|
||||
def setUp(self):
|
||||
self.person1 = TestPerson.objects.create(name='test1')
|
||||
|
||||
@ -45,3 +46,12 @@ class ItemTest(TestCase):
|
||||
AttributeError,
|
||||
'You can not save \'<type \'int\'>\' into a person field.'):
|
||||
TestModel.objects.create(person=5)
|
||||
|
||||
def test_get_absolute_url_with_deleted_person(self):
|
||||
person2 = TestPerson.objects.create(name='test2')
|
||||
self.assertEqual(person2.get_absolute_url(), 'absolute_url_of_test_person')
|
||||
person_id = person2.person_id
|
||||
self.assertEqual(get_person(person_id).get_absolute_url(), 'absolute_url_of_test_person')
|
||||
person2.delete()
|
||||
with self.assertRaisesRegexp(ValueError, 'This person object has no url.'):
|
||||
get_person(person_id).get_absolute_url()
|
||||
|
Loading…
Reference in New Issue
Block a user