summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: dbc35d3)
raw | patch | inline | side by side (parent: dbc35d3)
author | stefan <stefan@57a73879-2fb5-44c3-a270-3262357dd7e2> | |
Thu, 14 Apr 2011 12:47:48 +0000 (12:47 +0000) | ||
committer | stefan <stefan@57a73879-2fb5-44c3-a270-3262357dd7e2> | |
Thu, 14 Apr 2011 12:47:48 +0000 (12:47 +0000) |
git-svn-id: http://svn.roundup-tracker.org/svnroot/roundup/roundup/trunk@4590 57a73879-2fb5-44c3-a270-3262357dd7e2
roundup/cgi/templating.py | patch | blob | history | |
roundup/hyperdb.py | patch | blob | history |
index a541f50244f5bda31bf14704e5367ef865c82c00..11e1449470ff25dd1742ebf786ed3d0117e6362a 100644 (file)
for klass, htmlklass in propclasses:
if not isinstance(prop, klass):
continue
- if isinstance(prop, hyperdb.Multilink):
- value = []
- else:
- value = None
+ value = prop.get_default_value()
return htmlklass(self._client, self._classname, None, prop, item,
value, self._anonymous)
l = []
for name, prop in self._props.items():
for klass, htmlklass in propclasses:
- if isinstance(prop, hyperdb.Multilink):
- value = []
- else:
- value = None
if isinstance(prop, klass):
+ value = prop.get_default_value()
l.append(htmlklass(self._client, self._classname, '',
- prop, name, value, self._anonymous))
+ prop, name, value, self._anonymous))
if sort:
l.sort(lambda a,b:cmp(a._name, b._name))
return l
diff --git a/roundup/hyperdb.py b/roundup/hyperdb.py
index 365921577741ca7efe2442a285e47d4744cddbb6..a9bb9e1550c5d35a3556280089158309aec371db 100644 (file)
--- a/roundup/hyperdb.py
+++ b/roundup/hyperdb.py
#
class _Type(object):
"""A roundup property type."""
- def __init__(self, required=False):
+ def __init__(self, required=False, default_value = None):
self.required = required
+ self.__default_value = default_value
def __repr__(self):
' more useful for dumps '
return '<%s.%s>'%(self.__class__.__module__, self.__class__.__name__)
+ def get_default_value(self):
+ """The default value when creating a new instance of this property."""
+ return self.__default_value
def sort_repr (self, cls, val, name):
"""Representation used for sorting. This should be a python
built-in type, otherwise sorting will take ages. Note that
class String(_Type):
"""An object designating a String property."""
- def __init__(self, indexme='no', required=False):
- super(String, self).__init__(required)
+ def __init__(self, indexme='no', required=False, default_value = ""):
+ super(String, self).__init__(required, default_value)
self.indexme = indexme == 'yes'
def from_raw(self, value, propname='', **kw):
"""fix the CRLF/CR -> LF stuff"""
class Date(_Type):
"""An object designating a Date property."""
- def __init__(self, offset=None, required=False):
- super(Date, self).__init__(required)
+ def __init__(self, offset=None, required=False, default_value = None):
+ super(Date, self).__init__(required = required,
+ default_value = default_value)
self._offset = offset
def offset(self, db):
if self._offset is not None:
class _Pointer(_Type):
"""An object designating a Pointer property that links or multilinks
to a node in a specified class."""
- def __init__(self, classname, do_journal='yes', required=False):
+ def __init__(self, classname, do_journal='yes', required=False,
+ default_value = None):
""" Default is to journal link and unlink events
"""
- super(_Pointer, self).__init__(required)
+ super(_Pointer, self).__init__(required, default_value)
self.classname = classname
self.do_journal = do_journal == 'yes'
def __repr__(self):
"do_journal" indicates whether the linked-to nodes should have
'link' and 'unlink' events placed in their journal
"""
+
+ def __init__(self, classname, do_journal = 'yes', required = False):
+
+ super(Multilink, self).__init__(classname,
+ do_journal,
+ required = required,
+ default_value = [])
+
def from_raw(self, value, db, klass, propname, itemid, **kw):
if not value:
return []