예제 #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
예제 #2
0
class OnlineCodeModel(BasicModel):
    class Meta:
        behaviors = (Searchable, )
        label_name = {
            "title": u"團體名稱",
            "customer": u"所屬客戶",
            "code_type": u"類型",
            "source": u"原始碼",
        }

    title = Fields.StringProperty(default=u"未命名")
    target = Fields.CategoryProperty(kind=OnlineCodeTargetModel)
    code_type = Fields.StringProperty()
    source = Fields.TextProperty()
    vision = Fields.IntegerProperty(default=0)

    @classmethod
    def all_with_target(cls, target, code_type):
        return cls.query(cls.code_type == code_type,
                         cls.target == target.key).order(-cls.sort)

    @classmethod
    def get_source(cls, target, code_type, vision):
        return cls.query(cls.code_type == code_type, cls.target == target.key,
                         cls.vision == int(vision)).order(-cls.sort).get()
예제 #3
0
class StoreClientModel(BasicModel):
    class Meta:
        behaviors = (Searchable, )
        label_name = {
            "title": u"團購名稱",
            "store": u"商家",
        }

    store = Fields.CategoryProperty(kind=UserInfoModel)
    client_id = Fields.StringProperty(default=u"")
예제 #4
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)
예제 #5
0
class ProductModel(BasicModel):
    class Meta:
        behaviors = (Searchable, )
        label_name = {
            "title": u"商品名稱",
            "spec": u"商品規格",
            "image_url": u"圖片網址",
            "quantity": u"庫存數量",
            "date": u"可購買期限",
            "price": u"價格",
            "limit_1": u"已出售數量",
            "limit_2": u"可供購買數量",
        }

    title = Fields.StringProperty(default=u"未命名的商品")
    spec = Fields.StringProperty(default=u"")
    image_url = Fields.StringProperty(default=u"")
    date = Fields.DateTimeProperty()
    price = Fields.FloatProperty(default=0.0)
    limit_1 = Fields.IntegerProperty(default=0)
    limit_2 = Fields.IntegerProperty(default=99999)
    store = Fields.CategoryProperty(kind=StoreModel)
    group_info = Fields.CategoryProperty(kind=GroupInfoModel)

    @classmethod
    def get_by_feature(cls, store, group_info, title, spec, price):
        p = float(price)
        return cls.query(cls.title == title, cls.spec == spec, cls.price == p,
                         cls.store == store,
                         cls.group_info == group_info).get()
예제 #6
0
class OrderItemModel(BasicModel):
    class Meta:
        behaviors = (Searchable,)
        label_name = {
            "title": u"摘要",
            "order_detail": u"所屬訂單細節",
        }
        not_show = {
            "title": u"摘要",
            "order_detail": u"所屬訂單細節",
        }
    title = Fields.StringProperty(default=u"未命名的商品")
    order_detail = Fields.CategoryProperty(kind=OrderDetailModel)
    product = Fields.CategoryProperty(kind=ProductModel)
    quantity = Fields.IntegerProperty()
예제 #7
0
class ReportModel(BasicModel):
    class Meta:
        behaviors = (Searchable,)
        label_name = {
            "title": u"摘要",
        }
    title = Fields.StringProperty(default=u"未命名")
예제 #8
0
class StoreProcessModel(BasicModel):
    class Meta:
        behaviors = (Searchable, )
        label_name = {
            "title": u"商家名稱",
            "is_enable": u"顯示於前台",
        }

    title = Fields.StringProperty(default=u"未命名的流程")
    path = Fields.StringProperty(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)
예제 #9
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)
예제 #10
0
class OrderDetailModel(BasicModel):
    class Meta:
        behaviors = (Searchable, )
        label_name = {
            "title": u"訂購方式",
            "order_info": u"所屬訂單",
        }

    title = Fields.StringProperty(default=u"")
    order_info = Fields.CategoryProperty(kind=OrderInfoModel)
    group_info = Fields.CategoryProperty(kind=GroupInfoModel)
    shipping_fee = Fields.FloatProperty()
    sum = Fields.FloatProperty()

    def items(self):
        from order_item import OrderItemModel
        return OrderItemModel.query(OrderItemModel.order_detail == self.key
                                    ).order(-OrderItemModel.sort).fetch()
예제 #11
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)
예제 #12
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()
예제 #13
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)
예제 #14
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)
예제 #16
0
class OnlineCodeTargetModel(BasicModel):
    class Meta:
        behaviors = (Searchable, )
        label_name = {
            "title": u"目標名稱",
            "url": u"網址",
            "is_enable": u"顯示於前台",
            "telephone": u"連絡方式",
            "image": u"照片",
            "content": u"簡介",
        }

    title = Fields.StringProperty(default=u"未命名")
    js_vision = Fields.IntegerProperty(default=0)
    css_vision = Fields.IntegerProperty(default=0)
    html_vision = Fields.IntegerProperty(default=0)

    @classmethod
    def get_by_name(cls, name):
        return cls.query(cls.title == name).get()
예제 #17
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()
예제 #18
0
class WebFileModel(BasicModel):
    class Meta:
        label_name = {
            "filename": u"檔案名稱",
            "content_type": u"類型",
            "hash": u"hash",
            "size": u"大小",
            "file": u"檔案鍵值",
            "url": u"網址",
            "is_enable": u"顯示於前台",
        }

    filename = Fields.StringProperty()
    content_type = Fields.StringProperty()
    hash = Fields.StringProperty()
    size = Fields.IntegerProperty(default=0)
    file = Fields.BlobKeyProperty()
    url = Fields.StringProperty()

    @classmethod
    def all_by_created(cls):
        return cls.query().order(-cls.created)
예제 #19
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()
예제 #20
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)
예제 #21
0
class MobileKeyModel(BasicModel):
    class Meta:
        behaviors = (Searchable,)
        label_name = {
            "mobile": u"手機號碼",
            "code": u"驗証碼",
        }
    code = Fields.StringProperty(required=True)
    client_id = Fields.StringProperty()
    mobile = Fields.StringProperty(default=u"")
    user_agent = Fields.StringProperty(default=u"")

    @classmethod
    def create(cls, controller):
        """ 產生一組 Key """
        client_id = None
        if "client_id" in controller.session:
            client_id = controller.session["client_id"]
        cid = controller.params.get_string("client_id")
        if cid != u"":
            client_id = cid
            n = cls.query(cls.client_id==client_id).order(-cls.sort).get()
            logging.info("cid %s" % cid)
            if n is not None:
                controller.session["mobile_code"] = n.code
                controller.session["mobile_code_time"] = n.sort
                controller.session["client_id"] = client_id
                return n
        for i in xrange(0, 100):
            rnd = ''.join([str(random.randint(100, 999)) for x in range(0, 10)])
            code = rnd[0:6]
            f = cls.get_by_code(code)
            if client_id is None:
                client_id = code + rnd[11:16] + rnd[21:26]
            if f is None:
                f = cls()
                f.code = code
                f.client_id = client_id
                f.user_agent = controller.request.environ.get('HTTP_USER_AGENT')
                f.put()
                controller.session["mobile_code"] = f.code
                controller.session["mobile_code_time"] = f.sort
                controller.session["client_id"] = client_id
                return f

    @classmethod
    def clean(cls, die=timeout):
        """ 清除過期 Key """
        t1 = time.time()-die
        r = cls.query(cls.mobile=="",cls.sort<t1).fetch(100, keys_only=True)
        if r:
            ndb.delete_multi(r)
        t2 = time.time()-die*10
        r2 = cls.query(cls.sort<t2).fetch(100, keys_only=True)
        if r2:
            ndb.delete_multi(r2)

    @classmethod
    def clean_by_client_id(cls, client_id, die=timeout):
        """ 清除特定客戶端 Key """
        r = cls.query(cls.sort<time.time()-die, cls.client_id==client_id).fetch(100, keys_only=True)
        if r:
            ndb.delete_multi(r)

    @classmethod
    def get_by_code(cls, code):
        """ 依驗証碼取得 Key """
        return cls.query(cls.code == code).get()

    @classmethod
    def get_by_mobile(cls, mobile):
        """ 依手機取得 Key """
        return cls.query(cls.mobile == mobile).get()

    @classmethod
    def get_by_client_id(cls, client_id, user_agent):
        """ 取得特定客戶端 Key """
        return cls.query(cls.client_id == client_id, cls.user_agent == user_agent).get()

    @classmethod
    def get_key(cls, controller, check_first=True):
        """ 取得連線 token 與 登入資訊"""
        cls.clean()
        ms = None
        if check_first:
            # 先檢查同客戶端是否存在
            ms = cls.get_by_client_id(controller.params.get_string("client_id"), controller.request.environ.get('HTTP_USER_AGENT'))

            # 用驗証碼檢查
            # 正向驗証使用
            if "mobile_code" in controller.session and ms is None:
                ms = cls.get_by_code(controller.session["mobile_code"])

        # 若上列2項皆不存在,則建立新的
        if ms is None:
            ms = cls.create(controller)
        # 延長存續時間
        ms.sort = time.time()
        ms.put()
        controller.session["client_id"] = ms.client_id
        controller.context["mobile_code"] = ms.code
        controller.context["token"] = crete_channel_token(ms.client_id)
        controller.context["second"] = int(timeout - (time.time() - float(ms.sort)))
        return ms

    @classmethod
    def login(cls, mobile, code):
        # 檢查手機格式
        ms = cls.get_by_code(code)
        if mobile.startswith("09"):
            mobile = "+886" + mobile[1:]
        if ms:
            # 如果還沒過期
            if int(timeout - (time.time() - ms.sort)) >= 0:
                ms.mobile = mobile
                rv = {
                    "action": "login",
                    "status": "success",
                    "client": ms.client_id,
                    "mobile": mobile
                }
                # 主動式登入 - 廣播
                send_message_to_mobile(mobile, rv)
                send_message_to_client(ms.client_id, rv)
                ms.put()
                return ms

    def is_login(self):
        if self.code != u"" and self.client_id != u"" and self.mobile != u"":
            return True
        else:
            return False
예제 #22
0
class PostTokenModel(BasicModel):
    class Meta:
        behaviors = (Searchable, )
        label_name = {
            "mobile": u"手機號碼",
            "token": u"驗証碼",
        }

    token = Fields.StringProperty(required=True)
    client_id = Fields.StringProperty()
    mobile = Fields.StringProperty()

    @classmethod
    def create(cls, controller):
        """
        產生一組驗証碼
        """
        client_id = None
        if "client_id" in controller.session:
            client_id = controller.session["client_id"]
        for i in xrange(0, 100):
            rnd = ''.join(
                [str(random.randint(100, 999)) for x in range(0, 10)])
            token = rnd[0:6]
            f = cls.get_by_token(token)
            if client_id is None:
                client_id = token + rnd[11:16] + rnd[21:26]
            if f is None:
                f = cls()
                f.token = token
                f.client_id = client_id
                f.put()
                controller.session["mobile_token"] = f.token
                controller.session["mobile_token_time"] = f.sort
                controller.session["client_id"] = client_id
                return f

    @classmethod
    def clean(cls, die=timeout):
        """
        產生一組驗証碼
        """
        r = cls.query(cls.sort < time.time() - die).fetch(100, keys_only=True)
        if r:
            ndb.delete_multi(r)

    @classmethod
    def get_by_token(cls, token):
        """
        Queries all posts in the system, regardless of user, ordered by date created descending.
        """
        return cls.query(cls.token == token).get()

    @classmethod
    def check_token(cls, mobile, token):
        k = cls.get_by_token(token)
        if k is None:
            return False
        if k.mobile == mobile:
            return k.client_id
        else:
            return None

    @classmethod
    def get_key(cls, controller):
        cls.clean()
        length = 30
        m = cls()
        m.client_id = controller.session["client_id"]
        m.token = ''.join(
            random.choice(string.lowercase) for i in range(length))
        m.mobile = controller.session["mobile"]
        m.put()
        return m
예제 #23
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)
예제 #24
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
예제 #25
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()
예제 #26
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()