parent
58affb4ca8
commit
99895a28d1
@ -51,6 +51,20 @@ class Person(object):
|
|||||||
"""
|
"""
|
||||||
return ''
|
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):
|
class Persons(object):
|
||||||
"""
|
"""
|
||||||
|
@ -81,7 +81,7 @@ class PersonMixin(object):
|
|||||||
% self)
|
% self)
|
||||||
|
|
||||||
def __unicode__(self):
|
def __unicode__(self):
|
||||||
return 'MyPerson: %s' % self.person_id
|
return self.person_id
|
||||||
|
|
||||||
def prepare_database_save(self, field):
|
def prepare_database_save(self, field):
|
||||||
if type(field) is PersonField:
|
if type(field) is PersonField:
|
||||||
|
@ -36,7 +36,10 @@ def trans(value):
|
|||||||
@register.simple_tag
|
@register.simple_tag
|
||||||
def model_url(object, link='view'):
|
def model_url(object, link='view'):
|
||||||
# TODO: Rename to object_url
|
# TODO: Rename to object_url
|
||||||
return object.get_absolute_url(link)
|
try:
|
||||||
|
return object.get_absolute_url(link)
|
||||||
|
except ValueError:
|
||||||
|
return ''
|
||||||
|
|
||||||
|
|
||||||
@register.filter
|
@register.filter
|
||||||
|
@ -13,6 +13,9 @@ class TestPerson(PersonMixin, models.Model):
|
|||||||
def __unicode__(self):
|
def __unicode__(self):
|
||||||
return self.name
|
return self.name
|
||||||
|
|
||||||
|
def get_absolute_url(self, link='detail'):
|
||||||
|
return 'absolute_url_of_test_person'
|
||||||
|
|
||||||
|
|
||||||
class TestPersonToPerson(object):
|
class TestPersonToPerson(object):
|
||||||
def __init__(self, person_prefix_filter=None, id_filter=None):
|
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 django.contrib.auth.models import AnonymousUser
|
||||||
|
|
||||||
from openslides.utils.test import TestCase
|
from openslides.utils.test import TestCase
|
||||||
|
from openslides.utils.person.api import get_person
|
||||||
|
|
||||||
from .models import TestPerson, TestModel
|
from .models import TestPerson, TestModel
|
||||||
|
|
||||||
|
|
||||||
class ItemTest(TestCase):
|
class PersonTest(TestCase):
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
self.person1 = TestPerson.objects.create(name='test1')
|
self.person1 = TestPerson.objects.create(name='test1')
|
||||||
|
|
||||||
@ -45,3 +46,12 @@ class ItemTest(TestCase):
|
|||||||
AttributeError,
|
AttributeError,
|
||||||
'You can not save \'<type \'int\'>\' into a person field.'):
|
'You can not save \'<type \'int\'>\' into a person field.'):
|
||||||
TestModel.objects.create(person=5)
|
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