[base] create enum in base and use it in calendar and housing
This commit is contained in:
parent
92a0b9582f
commit
a3d351eb88
3 changed files with 17 additions and 24 deletions
|
|
@ -34,6 +34,21 @@ __all__ = ['UserError', 'FieldNotFound', 'NotAvailable',
|
|||
'empty', 'BaseObject']
|
||||
|
||||
|
||||
def enum(**enums):
|
||||
_values = enums.values()
|
||||
_keys = enums.keys()
|
||||
_items = enums.items()
|
||||
_types = list((type(value) for value in enums.values()))
|
||||
_index = dict((value if not isinstance(value, dict) else value.itervalues().next(), i) for i, value in enumerate(enums.values()))
|
||||
|
||||
enums['keys'] = _keys
|
||||
enums['values'] = _values
|
||||
enums['items'] = _items
|
||||
enums['index'] = _index
|
||||
enums['types'] = _types
|
||||
return type('Enum', (), enums)
|
||||
|
||||
|
||||
def empty(value):
|
||||
"""
|
||||
Checks if a value is empty (None, NotLoaded or NotAvailable).
|
||||
|
|
|
|||
|
|
@ -17,7 +17,7 @@
|
|||
# You should have received a copy of the GNU Affero General Public License
|
||||
# along with weboob. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
from .base import BaseObject, StringField, IntField, FloatField, Field
|
||||
from .base import BaseObject, StringField, IntField, FloatField, Field, enum
|
||||
from .collection import CapCollection, CollectionNotFound, Collection
|
||||
from .date import DateField
|
||||
|
||||
|
|
@ -27,17 +27,6 @@ from weboob.tools.date import parse_date
|
|||
__all__ = ['BaseCalendarEvent', 'CapCalendarEvent']
|
||||
|
||||
|
||||
def enum(**enums):
|
||||
_values = enums.values()
|
||||
_items = enums.items()
|
||||
_index = dict((value, i) for i, value in enumerate(enums.values()))
|
||||
_types = list((type(value) for value in enums.values()))
|
||||
enums['values'] = _values
|
||||
enums['items'] = _items
|
||||
enums['index'] = _index
|
||||
enums['types'] = _types
|
||||
return type('Enum', (), enums)
|
||||
|
||||
CATEGORIES = enum(CONCERT=u'Concert', CINE=u'Cinema', THEATRE=u'Theatre', TELE=u'Television', CONF=u'Conference')
|
||||
|
||||
#the following elements deal with ICalendar stantdards
|
||||
|
|
|
|||
|
|
@ -19,7 +19,7 @@
|
|||
|
||||
|
||||
from .base import Capability, BaseObject, Field, IntField, DecimalField, \
|
||||
StringField, BytesField
|
||||
StringField, BytesField, enum
|
||||
from .date import DateField
|
||||
|
||||
__all__ = ['HousingPhoto', 'Housing', 'Query', 'City', 'CapHousing']
|
||||
|
|
@ -71,17 +71,6 @@ class Query(BaseObject):
|
|||
TYPE_RENT = 0
|
||||
TYPE_SALE = 1
|
||||
|
||||
def enum(**enums):
|
||||
_values = enums.values()
|
||||
_items = enums.items()
|
||||
_index = dict((value, i) for i, value in enumerate(enums.values()))
|
||||
_types = list((type(value) for value in enums.values()))
|
||||
enums['values'] = _values
|
||||
enums['items'] = _items
|
||||
enums['index'] = _index
|
||||
enums['types'] = _types
|
||||
return type('Enum', (), enums)
|
||||
|
||||
HOUSE_TYPES = enum(APART=u'Apartment',
|
||||
HOUSE=u'House',
|
||||
PARKING=u'Parking',
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue