class ThemesModel(BasicModel): theme_title = Fields.StringProperty(required=True, verbose_name=u'樣式名稱') theme_name = Fields.StringProperty(required=True, verbose_name=u'識別名稱') exclusive = Fields.StringProperty(verbose_name=u'專屬項目', default='all') is_enable = Fields.BooleanProperty(verbose_name=u'顯示於前台', default=True) author = Fields.StringProperty(verbose_name=u'作者') using = Fields.TextProperty(verbose_name=u'使用的欄位') thumbnail = Fields.StringProperty(verbose_name=u'縮圖位置') in_datastore = Fields.BooleanProperty(verbose_name=u'是否位於 DataStore', default=False) @classmethod def find_by_theme_name(cls, theme_name): return cls.query(cls.theme_name == theme_name).get() @classmethod def get_list(cls, identifier_name): return cls.query( cls.exclusive.IN([identifier_name, u'all']) ).order(-cls.sort, -cls._key) @classmethod def check_in_list(cls, identifier_name, theme_name): item = cls.query( ndb.AND( cls.exclusive.IN([identifier_name, u'all']), cls.theme_name == theme_name ) ).order(-cls.sort, -cls._key).get() if item: return True else: return False
class RoleModel(BasicModel): name = Fields.StringProperty(required=True, verbose_name=u'識別名稱') title = Fields.StringProperty(required=True, verbose_name=u'角色名稱') prohibited_actions = Fields.TextProperty(verbose_name=u'禁止的操作', default='') level = Fields.IntegerProperty(verbose_name=u'權限等級', default=0) @classmethod def create_role(cls, name, title, level, prohibited_actions): n = cls() n.name = name n.title = title n.level = level n.prohibited_actions = prohibited_actions n.put() return n @classmethod def get_role(cls, name): a = cls.query(cls.name == name).get() return a @classmethod def get_list(cls): return cls.query(cls.level < 1000).order(cls.level, -cls.sort) @classmethod def find_lowest_level(cls): return cls.query().order(cls.level).get()
class UserShopPointProductModel(BasicModel): name = Fields.StringProperty(verbose_name=u'識別名稱') title = Fields.StringProperty(verbose_name=u'標題', default=u'50點') price = Fields.FloatProperty(verbose_name=u'價格', default=50.0) point = Fields.FloatProperty(verbose_name=u'獲得點數', default=50.0) is_enable = Fields.BooleanProperty(verbose_name=u'啟用', default=True) remark = Fields.TextProperty(verbose_name=u'說明', default=u'')
class LineBotModel(BasicModel): title = Fields.TextProperty(verbose_name=u'檢查的字串', default=u'') py_code = Fields.TextProperty(verbose_name=u'PyCode', default=u'') source_type = Fields.StringProperty(verbose_name=u'要處理的訊息來源', default=u'user', choices=( u'user', u'group', u'room', u'input', u'all', )) message_type = Fields.StringProperty(verbose_name=u'要處理的訊息類型', default=u'text', choices=( u'text', u'image', u'video', u'audio', u'location', u'sticker', u'follow', u'unfollow', u'join', u'leave', u'postback', )) return_message_type = Fields.StringProperty(verbose_name=u'回傳的訊息類型', default=u'TextSendMessage', choices=( u'TextSendMessage', u'ImageSendMessage', u'TemplateSendMessage', )) weights = Fields.FloatProperty(verbose_name=u'權重', default=0.0) @classmethod def get_or_create_by_name(cls, name): item = cls.get_by_name(name) if item is None: import time item = cls() item.name = name item.weights = time.time() item.put() return item
class UserShopPointHistoryModel(BasicModel): name = Fields.StringProperty(verbose_name=u'識別名稱') shop_point_target = Fields.KeyProperty(verbose_name=u'所屬單位', kind=UserShopPointModel) order_no = Fields.StringProperty(verbose_name=u'訂單編號', default=u'') order_amount = Fields.StringProperty(verbose_name=u'訂單金額', default=u'') decrease_point = Fields.FloatProperty(verbose_name=u'點數减少', default=0) increase_point = Fields.FloatProperty(verbose_name=u'點數增加', default=0) point = Fields.FloatProperty(verbose_name=u'剩餘點數', default=0) remark = Fields.TextProperty(verbose_name=u'說明', default=u'') @classmethod def all_enable(cls, target=None, *args, **kwargs): if target: return cls.query( cls.shop_point_target == target.key).order(-cls.sort) return cls.query().order(-cls.sort)