Merge remote-tracking branch 'openslides/stable/1.4.x'

Conflicts:
	openslides/core/templatetags/tags.py
This commit is contained in:
Oskar Hahn 2013-08-19 17:54:50 +02:00
commit 20cf960c82
6 changed files with 43 additions and 4 deletions

View File

@ -520,6 +520,9 @@ class MainWindow(wx.Frame):
if not last_backup is None:
self.last_backup = datetime.datetime.strptime(
last_backup, "%Y-%m-%d %H:%M:%S")
server_settings = settings.get("server_settings", {})
setattr_unless_none("host", server_settings.get("host"))
setattr_unless_none("port", server_settings.get("port"))
def save_gui_settings(self):
if self.last_backup is None:
@ -534,6 +537,9 @@ class MainWindow(wx.Frame):
"interval_unit": self.backupdb_interval_unit,
"last_backup": last_backup
},
"server_settings": {
"host": self.host,
"port": self.port,
}
dp = os.path.dirname(self.gui_settings_path)
@ -613,7 +619,10 @@ class MainWindow(wx.Frame):
self.cmd_run_ctrl.cancel_command()
return
args = ["--address", self._host, "--port", self._port]
if self._host == "0.0.0.0":
args = ["--port", self._port]
else:
args = ["--address", self._host, "--port", self._port]
if not self.cb_start_browser.GetValue():
args.append("--no-browser")

View File

@ -39,7 +39,10 @@ def trans(value):
def model_url(object, link='view'):
warnings.warn("model_url is deprecated; use absolute_url instead",
DeprecationWarning)
return object.get_absolute_url(link)
try:
return object.get_absolute_url(link)
except ValueError:
return ''
@register.filter

View File

@ -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):
"""

View File

@ -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:

View File

@ -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):

View File

@ -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()