:class:wsattr
now takes a 'default' parameter
This commit is contained in:
parent
15dd8b0206
commit
1bc806dd90
@ -6,6 +6,9 @@ next
|
||||
|
||||
* Now handle dict and UserType types as GET/POST params.
|
||||
|
||||
* :class:`wsattr` now takes a 'default' parameter that will be returned
|
||||
instead of 'Unset' if no value has been set.
|
||||
|
||||
0.3b1
|
||||
-----
|
||||
|
||||
|
@ -183,7 +183,7 @@ class wsattr(object):
|
||||
mandatoryvalue = wsattr(int, mandatory=True)
|
||||
|
||||
"""
|
||||
def __init__(self, datatype, mandatory=False, name=None):
|
||||
def __init__(self, datatype, mandatory=False, name=None, default=Unset):
|
||||
#: The attribute name in the parent python class.
|
||||
#: Set by :func:`inspect_class`
|
||||
self.key = None # will be set by class inspection
|
||||
@ -194,11 +194,14 @@ class wsattr(object):
|
||||
self.datatype = datatype
|
||||
#: True if the attribute is mandatory
|
||||
self.mandatory = mandatory
|
||||
#: Default value. The attribute will return this instead
|
||||
#: of :data:`Unset` if no value has been set.
|
||||
self.default = default
|
||||
|
||||
def __get__(self, instance, owner):
|
||||
if instance is None:
|
||||
return self
|
||||
return getattr(instance, '_' + self.key, Unset)
|
||||
return getattr(instance, '_' + self.key, self.default)
|
||||
|
||||
def __set__(self, instance, value):
|
||||
try:
|
||||
|
Loading…
x
Reference in New Issue
Block a user