class NewsModel(BasicModel): class Meta: label_name = { "name": u"名稱", "date": u"日期", "is_enable": u"啟用", "category": u"分類", "title_lang_zhtw": u"繁體中文標題", "title_lang_zhcn": u"簡體中文標題", "title_lang_enus": u"英文標題", "content_lang_zhtw": u"繁體中文內容", "content_lang_zhcn": u"簡體中文內容", "content_lang_enus": u"英文內容", } name = Fields.StringProperty(required=True) date = Fields.DateProperty() is_enable = Fields.BooleanProperty(default=True) # category = Fields.CategoryProperty(kind=NewsCategoryModel) title_lang_zhtw = Fields.StringProperty() title_lang_zhcn = Fields.StringProperty() title_lang_enus = Fields.StringProperty() content_lang_zhtw = Fields.RichTextProperty() content_lang_zhcn = Fields.RichTextProperty() content_lang_enus = Fields.RichTextProperty() @classmethod def all_enable(cls, category=None, *args, **kwargs): cat = None if hasattr(cls, "category"): if category: cat = NewsCategoryModel.get_by_name(category) if cat is not None: return cls.query(cls.category == cat.key, cls.is_enable==True).order(-cls.sort) return cls.query(cls.is_enable==True).order(-cls.sort)
class PluginsModel(BasicModel): class Meta: label_name = { "theme_name": u"樣式名稱", "theme_key": u"識別名稱", "exclusive": u"專屬項目", "is_enable": u"顯示於前台", "content": u"描述 " } theme_name = Fields.StringProperty(required=True) theme_key = Fields.StringProperty(required=True) exclusive = Fields.StringProperty(default="all") is_enable = Fields.BooleanProperty(default=True) content = Fields.RichTextProperty() @classmethod def get_by_theme_key(cls, theme_key): return cls.query(cls.theme_key == theme_key).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_key): item = cls.query( ndb.AND(cls.exclusive.IN([identifier_name, u"all"]), cls.theme_key == theme_key)).order(-cls.sort, -cls._key).get() if item: return True else: return False
class WebPageModel(BasicModel): class Meta: label_name = { "title": u"標題", "title_en": u"英文標題", "page_url": u"頁面識別碼", "is_enable": u"顯示於前台", "content": u"內容 " } title = Fields.StringProperty(required=True) title_en = Fields.StringProperty(required=True) page_url = Fields.StringProperty(required=True) is_enable = Fields.BooleanProperty(default=True) content = Fields.RichTextProperty() @classmethod def get_by_url(cls, page_url): return cls.query(cls.page_url == page_url).get()