Exemplo n.º 1
0
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
Exemplo n.º 2
0
class BannerModel(BasicModel):
    class Meta:
        label_name = {
            "name": u"名稱",
            "description": u"描述",
            "link": u"連結網址",
            "link_title": u"連結標題",
            "image": u"圖片",
            "is_enable": u"啟用",
            "category": u"分類",
        }

    name = Fields.StringProperty()
    description = Fields.TextProperty()
    link = Fields.StringProperty()
    link_title = Fields.StringProperty()
    image = Fields.ImageProperty()
    is_enable = Fields.BooleanProperty(default=True)
    category = Fields.CategoryProperty(required=True, kind=BannerCategoryModel)

    @classmethod
    def all_enable(cls, category=None, *args, **kwargs):
        cat = None
        if category:
            cat = BannerCategoryModel.get_by_name(category)
        if cat is None:
            return cls.query(cls.is_enable == True).order(-cls.sort)
        else:
            return cls.query(cls.category == cat.key,
                             cls.is_enable == True).order(-cls.sort)
Exemplo n.º 3
0
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)
Exemplo n.º 4
0
class StoreModel(BasicModel):
    class Meta:
        behaviors = (Searchable, )
        label_name = {
            "title": u"商家名稱",
            "is_enable": u"顯示於前台",
        }

    title = Fields.StringProperty(default=u"未命名")
    is_enable = Fields.BooleanProperty(default=True)

    process_main = Fields.TextProperty(default=u"")  # 主流程
    process_normal = Fields.TextProperty(default=u"")  # 一般流程
    process_pre_order = Fields.TextProperty(default=u"")  # 預購流程

    process_order_change = Fields.TextProperty(default=u"")  # 訂單修改
    process_order_check = Fields.TextProperty(default=u"")  # 訂單確認
    process_order_cancel = Fields.TextProperty(default=u"")  # 訂單取消
    process_order_end = Fields.TextProperty(default=u"")  # 訂單結束

    process_send_goods = Fields.TextProperty(default=u"")  # 貨品寄送
    process_return_goods = Fields.TextProperty(default=u"")  # 退貨處理

    process_payment = Fields.TextProperty(default=u"")  # 金流收取
    process_refund = Fields.TextProperty(default=u"")  # 金流退款

    @classmethod
    def all_enable(cls):
        """
        Queries all posts in the system, regardless of user, ordered by date created descending.
        """
        return cls.query(cls.is_enable == True).order(-cls.sort)
Exemplo n.º 5
0
class WebInformationModel(BasicModel):
    class Meta:
        label_name = {
            "title": u"通用名稱",
            "name": u"識別碼",
            "domain_registration": u"網域註冊地",
            "domain_registration_price": u"網域註冊費用",
            "domain_registration_date": u"網域註冊日",
            "domain_expiration_date": u"網域到期日",
            "space_rental_level": u"伺服器等級",
            "space_rental_price": u"空間費用",
            "space_rental_date": u"空間租借日",
            "space_expiration_date": u"空間到期日",
            
            "manager_company": u"管理公司",
            "manager_website": u"公司網址",
            "manager_person": u"管理人姓名",
            "manager_telephone": u"管理人電話",
            "manager_mobile": u"管理人手機",
            "manager_email": u"管理人信箱",

            "contact_person": u"聯絡人",
            "contact_telephone": u"聯絡電話",
            "contact_mobile": u"聯絡手機",
            "contact_email": u"聯絡信箱",
            "contact_address": u"聯絡地址",
            "is_enable": u"顯示於前台",
        }
    title = Fields.StringProperty(required=True)
    name = Fields.StringProperty()

    domain_registration = Fields.StringProperty()
    domain_registration_price = Fields.StringProperty()
    domain_registration_date = Fields.DateProperty()
    domain_expiration_date = Fields.DateProperty()
    space_rental_level = Fields.StringProperty()
    space_rental_price = Fields.StringProperty()
    space_rental_date = Fields.DateProperty()
    space_expiration_date = Fields.DateProperty()

    manager_company = Fields.StringProperty(default=u"侑良科技")
    manager_website = Fields.StringProperty(default="http://")
    manager_person = Fields.StringProperty()
    manager_telephone = Fields.StringProperty()
    manager_mobile = Fields.StringProperty()
    manager_email = Fields.StringProperty()

    contact_person = Fields.StringProperty()
    contact_telephone = Fields.StringProperty()
    contact_mobile = Fields.StringProperty()
    contact_email = Fields.StringProperty()
    contact_address = Fields.StringProperty()
    is_enable = Fields.BooleanProperty(default=True)

    @classmethod
    def get_by_name(cls, name):
        return cls.query(cls.name==name).get()
Exemplo n.º 6
0
class OrderInfoModel(BasicModel):
    class Meta:
        behaviors = (Searchable, )
        label_name = {
            "store": u"商家",
            "purchaser": u"購買人",
            "purchaser_name": u"購買人姓名",
            "purchaser_mobile": u"購買人手機",
            "receiver_name": u"收件人姓名",
            "receiver_address": u"收件人地址",
            "receiver_mobile": u"收件人手機",
            "state": u"訂單狀態",
            "cash_flow_state": u"金流狀態",
            "freight_flow_state": u"物流狀態",
            "official_order": u"正式訂單",
            "official_order_date": u"正式訂單成立時間",
        }

    order_info_id = Fields.StringProperty()
    store = Fields.CategoryProperty(kind=StoreModel)
    purchaser = Fields.CategoryProperty(kind=UserInfoModel)
    purchaser_name = Fields.StringProperty(default=u"")
    purchaser_mobile = Fields.StringProperty(default=u"")
    receiver = Fields.CategoryProperty(kind=UserInfoModel)
    receiver_name = Fields.StringProperty(default=u"")
    receiver_address = Fields.StringProperty(default=u"")
    receiver_mobile = Fields.StringProperty(default=u"")
    state = Fields.IntegerProperty(default=0)
    cash_flow_state = Fields.IntegerProperty(default=0)
    freight_flow_state = Fields.IntegerProperty(default=0)
    path_event = Fields.StringProperty(default="")
    path_forecast = Fields.StringProperty(default="")
    path_now = Fields.StringProperty(default="")
    path_next = Fields.StringProperty(default="")

    process_now = Fields.StringProperty(default="")
    process_1 = Fields.TextProperty(default="")
    process_2 = Fields.TextProperty(default="")
    process_3 = Fields.TextProperty(default="")
    process_4 = Fields.TextProperty(default="")
    process_5 = Fields.TextProperty(default="")

    official_order = Fields.BooleanProperty(default=False)
    official_order_date = Fields.DateTimeProperty()

    def details(self):
        from order_detail import OrderDetailModel
        return OrderDetailModel.query(OrderDetailModel.order_info == self.key
                                      ).order(-OrderDetailModel.sort).fetch()

    def messages(self):
        from message import MessageModel
        return MessageModel.query(MessageModel.order_info == self.key).order(
            -MessageModel.sort).fetch()
Exemplo n.º 7
0
class WebMenuModel(BasicModel):
    class Meta:
        label_name = {
            "title": u"通用名稱",
            "name": u"識別碼",
            "title_lang_zhtw": u"繁中名稱",
            "title_lang_zhcn": u"簡中名稱",
            "title_lang_enus": u"英文名稱",
            "page_url": u"網址",
            "category": u"分類",
            "is_enable": u"顯示於前台",
        }
    title = Fields.StringProperty(required=True)
    name = Fields.StringProperty()
    title_lang_zhtw = Fields.StringProperty(default=u"未命名")
    title_lang_zhcn = Fields.StringProperty(default=u"未命名")
    title_lang_enus = Fields.StringProperty(default=u"未命名")
    page_url = Fields.StringProperty(required=True)
    is_enable = Fields.BooleanProperty(default=True)
    category = Fields.CategoryProperty(kind=WMM)

    @classmethod
    def get_by_url(cls, url, *args, **kwargs):
        return cls.query(cls.page_url==url)

    @classmethod
    def get_title(cls, url, *args, **kwargs):
        item_q = cls.get_by_url(url)
        item = item_q.get()
        if item is None:
            return ""
        if "lang" in kwargs:
            if kwargs["lang"] == "zhtw":
                return item.title_lang_zhtw
            if kwargs["lang"] == "zhcn":
                return item.title_lang_zhcn
            if kwargs["lang"] == "enus":
                return item.title_lang_enus
        return item.title

    @classmethod
    def get_by_name(cls, name):
        return cls.query(cls.name==name).get()

    @classmethod
    def all_enable(cls, category=None, *args, **kwargs):
        cat = None
        if category:
            cat = cls.get_by_name(category)
        if cat is None:
            return cls.query(cls.category==None, cls.is_enable==True).order(-cls.sort)
        else:
            return cls.query(cls.category==cat.key, cls.is_enable==True).order(-cls.sort)
Exemplo n.º 8
0
class UserInfoModel(BasicModel):
    class Meta:
        behaviors = (Searchable,)
        label_name = {
            "user_name": u"使用者名稱",
            "is_enable": u"顯示於前台",
        }
    title = Fields.StringProperty(default=u"未命名")
    user_name = Fields.StringProperty(default=u"未命名")
    is_enable = Fields.BooleanProperty(default=True)


    @classmethod
    def all_enable(cls):
        """
        Queries all posts in the system, regardless of user, ordered by date created descending.
        """
        return cls.query(cls.is_enable==True).order(-cls.sort)
Exemplo n.º 9
0
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()
Exemplo n.º 10
0
class BannerCategoryModel(BasicModel):
    class Meta:
        label_name = {
            "name": u"識別名稱",
            "title": u"分類標題",
            "is_enable": u"啟用",
        }

    name = Fields.StringProperty()
    title = Fields.StringProperty()
    is_enable = Fields.BooleanProperty(default=True)

    @classmethod
    def get_by_name(cls, name):
        return cls.query(cls.name == name).get()

    @classmethod
    def all_enable(cls):
        return cls.query(cls.is_enable == True).order(-cls.sort)
class ApplicationUserRoleModel(BasicModel):
    class Meta:
        label_name = {
            "title": u"角色名稱",
            "name": u"角色識別碼",
            "is_enable": u"啟用",
            "prohibited_actions": u"禁止的操作",
            "level": u"權限等級"
        }

    title = Fields.StringProperty(required=True)
    name = Fields.StringProperty(required=True)
    prohibited_actions = Fields.StringProperty(default="")
    is_enable = Fields.BooleanProperty(default=True)
    level = Fields.IntegerProperty(default=0)

    @classmethod
    def get_role(cls, name):
        a = cls.query(cls.name == name).get()
        return a

    @classmethod
    def has_record(cls):
        r = cls.query().get()
        if r is not None:
            return True
        else:
            return False

    @classmethod
    def create_account(cls, name, account, password, prohibited_actions):
        n = cls()
        n.name = name
        n.account = account
        n.password = password
        n.prohibited_actions = prohibited_actions
        n.put()
        return n

    @classmethod
    def get_list(cls):
        return cls.query(cls.level < 1000).order(cls.level, -cls.sort)
Exemplo n.º 12
0
class NewsCategoryModel(BasicModel):
    class Meta:
        label_name = {
            "name": u"分類識別碼",
            "is_enable": u"啟用",
            "title": u"分類名稱",
            "title_lang_zhtw": u"繁體中文分類名稱",
            "title_lang_zhcn": u"簡體中文分類名稱",
            "title_lang_enus": u"英文分類名稱",
        }

    name = Fields.StringProperty(required=True)
    title = Fields.StringProperty(default=u"未命名")
    title_lang_zhtw = Fields.StringProperty(default=u"未命名")
    title_lang_zhcn = Fields.StringProperty(default=u"未命名")
    title_lang_enus = Fields.StringProperty(default=u"未命名")
    is_enable = Fields.BooleanProperty(default=True)

    @classmethod
    def get_by_name(cls, name):
        return cls.query(cls.name == name).get()
Exemplo n.º 13
0
class MobileModel(BasicModel):
    class Meta:
        behaviors = (Searchable, )
        label_name = {
            "number": u"電話",
            "code": u"驗証碼",
            "password": u"密碼",
            "store": u"所屬商家",
            "is_enable": u"啟用/停用",
        }
        hide_filed = ["account", "store"]

    number = Fields.StringProperty(required=True)
    code = Fields.StringProperty()
    password = Fields.StringProperty()
    store = Fields.CategoryProperty(kind=StoreModel)
    account = Fields.CategoryProperty(kind=UserInfoModel)
    is_enable = Fields.BooleanProperty(default=True)

    @classmethod
    def format_mobile_number(cls, value=u''):
        """
        處理手機格式
        :param value: 輸入值
        :param taiwan_format: 台灣手機
        :return: 正確的手機格式 或 None
        """
        if value.startswith("09") is True:
            if len(value) == 10:
                return "+886" + value[1:]
        if value.startswith("+886") is True:
            if len(value) == 13:
                return value
        return None

    @classmethod
    def get_by_number(cls, number):
        return cls.query(cls.number == number).get()

    @classmethod
    def get_or_create_by_number(cls,
                                number,
                                name=u"未命名使用者",
                                store_name=u"未命名店家"):
        number = cls.format_mobile_number(number)
        if number is None:
            raise u"手機格式有誤"
        mobile = cls.get_by_number(number)

        if mobile is None:
            mobile = MobileModel()
            mobile.number = number
            mobile.put()
        if mobile.store is None:
            s = StoreModel()
            s.title = store_name
            s.process_main = '[{"id":"process_order_check"},{"id":"process_payment"},{"id":"process_send_goods"},{"id":"process_order_end"}]'
            s.put()
            mobile.store = s.key
            mobile.put()
        if mobile.account is None:
            a = UserInfoModel()
            a.user_name = name
            a.put()
            mobile.account = a.key
            mobile.put()
        return mobile

    @classmethod
    def already_register_check_and_login(cls, mobile, code):
        r = cls.query(cls.number == mobile, cls.password == code).get()
        if r is None:
            r = cls.query(cls.number == mobile, cls.code == code).get()
            if r is None:
                return None
        return r

    @classmethod
    def all_enable(cls):
        return cls.query(cls.is_enable == True).order(-cls.sort)

    @classmethod
    def all_enable_with_category(cls, cat):
        return cls.query(cls.is_enable == True,
                         cls.store == cat.key).order(-cls.sort)

    @classmethod
    def get_prev_one_with_enable(cls, item):
        return cls.query(cls.is_enable == True,
                         cls.sort > item.sort).order(cls.sort).get()

    @classmethod
    def get_next_one_with_enable(cls, item):
        return cls.query(cls.is_enable == True,
                         cls.sort < item.sort).order(-cls.sort).get()
Exemplo n.º 14
0
class ApplicationUserModel(BasicModel):
    class Meta:
        label_name = {
            "name": u"名稱",
            "account": u"帳號",
            "password": u"密碼",
            "is_enable": u"啟用",
            "avatar": u"頭像",
            "role": u"角色"
        }

    name = Fields.StringProperty(required=True)
    account = Fields.StringProperty(required=True)
    password = Fields.StringProperty(required=True)
    avatar = Fields.ImageProperty()
    is_enable = Fields.BooleanProperty(default=True)
    role = Fields.CategoryProperty(kind=ApplicationUserRoleModel,
                                   required=True)

    @classmethod
    def init(cls, name, account, password, prohibited_actions, avatar):
        if ApplicationUserRoleModel.has_record() is False:
            su_role = ApplicationUserRoleModel()
            su_role.name = "super_monkey"
            su_role.title = u"超級猴子"
            su_role.level = 9999
            su_role.put()

            admin_role = ApplicationUserRoleModel()
            admin_role.name = "super_user"
            admin_role.title = u"超級管理員"
            admin_role.level = 999
            admin_role.prohibited_actions = prohibited_actions
            admin_role.put()
        else:
            su_role = ApplicationUserRoleModel.get_role("super_monkey")
            admin_role = ApplicationUserRoleModel.get_role("super_user")
        cls.create_account(u"猴子", "iammonkey", "iammonkey", su_role.key,
                           avatar)
        return cls.create_account(name, account, password, admin_role.key,
                                  avatar)

    @classmethod
    def get_login(cls, account, password, is_enable=True):
        a = cls.query(cls.account == account, cls.password == password,
                      cls.is_enable == is_enable).get()
        if a is None:
            return None
        role = None
        if a.role is not None:
            role = a.role.get()
        if role is not None and role.is_enable is False:
            return None
        return a

    @classmethod
    def has_record(cls):
        r = cls.query().get()
        if r is not None:
            return True
        else:
            return False

    @classmethod
    def create_account(cls, name, account, password, role, avatar=None):
        n = cls()
        n.name = name
        n.account = account
        n.password = password
        n.role = role
        n.avatar = avatar
        n.put()
        return n

    @classmethod
    def get_list(cls):
        return cls.query(cls.account != "iammonkey").order(
            cls.account, -cls.sort, -cls._key)
Exemplo n.º 15
0
class MessageModel(BasicModel):
    class Meta:
        behaviors = (Searchable, )
        label_name = {
            "title": u"團購名稱",
            "store": u"商家",
        }

    store = Fields.CategoryProperty(kind=StoreModel)
    user_a = Fields.CategoryProperty(kind=UserInfoModel)
    user_b = Fields.CategoryProperty(kind=UserInfoModel)
    order_info = Fields.CategoryProperty(kind=OrderInfoModel)

    store_text = Fields.StringProperty()
    user_a_text = Fields.StringProperty()
    user_b_text = Fields.StringProperty()

    message_type = Fields.StringProperty()
    message_from = Fields.StringProperty()
    store_read = Fields.BooleanProperty(default=False)
    user_a_read = Fields.BooleanProperty(default=False)
    user_b_read = Fields.BooleanProperty(default=False)

    @classmethod
    def read(cls, order_info, store_key, account_key):
        r = ndb.Key(urlsafe=order_info).get()
        if r is None:
            return
        li = cls.query(cls.order_info == r.key).fetch()
        to_put = []
        for item in li:
            if item.store == store_key and item.store_read is False:
                item.store_read = True
                to_put.append(item)
            else:
                if r.purchaser == account_key and item.user_a_read is False:
                    r.user_a_read = True
                    to_put.append(item)
                elif item.user_b_read is False:
                    r.user_b_read = True
                    to_put.append(item)
        ndb.put_multi(to_put)

    @classmethod
    def insert(cls,
               msg_from,
               msg_type,
               store,
               purchaser,
               receiver,
               order_info=None):
        msg = cls()
        if order_info is not None:
            msg.order_info = order_info.key
        msg.store = store["key"]
        msg.store_text = store["message"]
        msg.user_a = purchaser["key"]
        msg.user_a_text = purchaser["message"]
        msg.user_b = receiver["key"]
        msg.user_b_text = u""
        if purchaser["key"] != purchaser["key"]:
            msg.user_b_text = receiver["message"]
        msg.message_from = msg_from
        msg.message_type = msg_type
        msg.put()
        return msg