Fix keyboards and nullable fields.

This commit is contained in:
Alex Root Junior 2017-10-21 21:20:37 +03:00
parent 4bf5409295
commit f4b9bf5339
3 changed files with 14 additions and 13 deletions

View file

@ -39,7 +39,7 @@ class BaseField(metaclass=abc.ABCMeta):
:param instance: :param instance:
:return: :return:
""" """
return instance.values.get(self.alias) return instance.values.get(self.alias, self.default)
def set_value(self, instance, value, parent=None): def set_value(self, instance, value, parent=None):
""" """
@ -96,7 +96,10 @@ class Field(BaseField):
return value return value
def deserialize(self, value, parent=None): def deserialize(self, value, parent=None):
if self.base_object is not None and not hasattr(value, 'base_object') and not hasattr(value, 'to_python'): if isinstance(value, dict) \
and self.base_object is not None \
and not hasattr(value, 'base_object') \
and not hasattr(value, 'to_python'):
return self.base_object(conf={'parent': parent}, **value) return self.base_object(conf={'parent': parent}, **value)
return value return value

View file

@ -14,12 +14,12 @@ class InlineKeyboardMarkup(base.TelegramObject):
https://core.telegram.org/bots/api#inlinekeyboardmarkup https://core.telegram.org/bots/api#inlinekeyboardmarkup
""" """
inline_keyboard: 'typing.List[typing.List[InlineKeyboardButton]]' = fields.ListOfLists(base='InlineKeyboardButton', inline_keyboard: 'typing.List[typing.List[InlineKeyboardButton]]' = fields.ListOfLists(base='InlineKeyboardButton')
default=[])
@classmethod def __init__(self, row_width=3, inline_keyboard=None):
def create(cls, row_width=3): if inline_keyboard is None:
return cls(conf={'row_width': row_width}) inline_keyboard = []
super(InlineKeyboardMarkup, self).__init__(conf={'row_width': row_width}, inline_keyboard=inline_keyboard)
@property @property
def row_width(self): def row_width(self):

View file

@ -18,13 +18,11 @@ class ReplyKeyboardMarkup(base.TelegramObject):
def __init__(self, keyboard: 'typing.List[typing.List[KeyboardButton]]' = None, def __init__(self, keyboard: 'typing.List[typing.List[KeyboardButton]]' = None,
resize_keyboard: base.Boolean = None, resize_keyboard: base.Boolean = None,
one_time_keyboard: base.Boolean = None, one_time_keyboard: base.Boolean = None,
selective: base.Boolean = None): selective: base.Boolean = None,
row_width: base.Integer = 3):
super(ReplyKeyboardMarkup, self).__init__(keyboard=keyboard, resize_keyboard=resize_keyboard, super(ReplyKeyboardMarkup, self).__init__(keyboard=keyboard, resize_keyboard=resize_keyboard,
one_time_keyboard=one_time_keyboard, selective=selective) one_time_keyboard=one_time_keyboard, selective=selective,
conf={'row_width': row_width})
@classmethod
def create(cls, row_width=3):
return cls(conf={'row_width': row_width})
@property @property
def row_width(self): def row_width(self):