Пример #1
0
 def on_model_change(self, form, model, created=False):
     if model.default and model.follow:
         Message.objects(db.Q(default=True) | db.Q(follow=True)).update(
             __raw__={'$set': dict(default=False, follow=False)})
     elif model.follow:
         Message.objects(follow=True).update(
             __raw__={'$set': dict(follow=False)})
     else:
         Message.objects(default=True).update(
             __raw__={'$set': dict(default=False)})
Пример #2
0
    def post(self):
        args = self.get_args()
        self.validate(args)

        doc = db.Q(phone=args['account']) | db.Q(email=args['account'])
        user = um.models.User.objects(doc).first()
        if not user:
            abort(ACCOUNT_NOT_EXISTS)
        if user.is_lock:
            abort(ACCOUNT_LOCKED)
        if user.password != args['password']:
            user.login_error()
            abort(PASSWORD_ERROR)

        return self.success(user, args)
Пример #3
0
    def get(self):
        res = dict(apis={},
                   icons={},
                   tpls={},
                   actions=defaultdict(list),
                   options={})
        version = get_version()

        for api in API.objects.all():
            if api.key == 'global':
                res['expire'] = api.expire
            res['apis'][api.key] = api.detail

        for icon in Icon.objects.all():
            res['icons'][icon.key] = icon.icon.base64

        for option in Option.objects.all():
            res['options'][option.key] = option.value
        res['options']['uuid'] = '0'
        res['options']['channel'] = '0'

        tpls = TPL.objects(enable__in=Enable.get())
        for tpl in tpls:
            res['tpls'][tpl.key] = dict(
                key=tpl.key,
                name=tpl.name,
                url=tpl.tpl.link,
                modified=str(tpl.modified),
            )

        query = db.Q(enable__in=Enable.get())
        if get_os() == 2:
            query = query & (db.Q(android_start__lte=version) | db.Q(android_start=None)) & \
                (db.Q(android_end__gte=version) | db.Q(android_end=None))
        elif get_os() == 1:
            query = query & (db.Q(ios_start__lte=version) | db.Q(ios_start=None)) & \
                (db.Q(ios_end__gte=version) | db.Q(ios_end=None))

        actions = Action.objects(enable__in=Enable.get()).order_by('sort')
        for action in actions:
            if action.module:
                res['actions'][action.module].append(action.detail)

        slides = Slide.objects(enable__in=Enable.get()).order_by('sort')
        for slide in slides:
            if slide.module:
                res['actions'][slide.module].append(slide.detail)

        if hasattr(self, 'handle') and callable(self.handle):
            self.handle(res)

        return res
Пример #4
0
    def get(self):
        res = dict(apis={}, tpls={}, actions=defaultdict(list), options={})
        version = get_version()

        apis = APIItem.objects.all()
        for api in apis:
            res['apis'][api.key] = api.detail

        for option in OptionItem.objects.all():
            res['options'][option.key] = option.value
        res['options']['uuid'] = '0'
        res['options']['channel'] = '0'

        tpls = TPLItem.objects(enable__in=Enable.get()).order_by('sort')
        for tpl in tpls:
            res['tpls'][tpl.key] = dict(
                key=tpl.key,
                name=tpl.name,
                url=tpl.tpl.link,
                modified=str(tpl.modified),
            )

        query = db.Q(enable__in=Enable.get())
        if get_os() == 2:
            query = query & (db.Q(android_version__lte=version) | db.Q(android_version=None)) & \
                (db.Q(android_version_end__gte=version) | db.Q(android_version_end=None))
        elif get_os() == 1:
            query = query & (db.Q(ios_version__lte=version) | db.Q(ios_version=None)) & \
                (db.Q(ios_version_end__gte=version) | db.Q(ios_version_end=None))
        if not current_user.is_authenticated():
            query = query & (db.Q(login_show=False) | db.Q(login_show=None))

        actions = ActionItem.objects(enable__in=Enable.get()).order_by('sort')
        for action in actions:
            if action.module and action.module.key:
                res['actions'][action.module.key].append(action.detail)

        slides = SlideItem.objects(enable__in=Enable.get()).order_by('sort')
        for slide in slides:
            if slide.module and slide.module.key:
                res['actions'][slide.module.key].append(slide.detail)

        return res
Пример #5
0
 def get_user(self, args):
     doc = db.Q(phone=args['account']) | db.Q(email=args['account'])
     return um.models.User.objects(doc).first()