示例#1
0
def getAccounts(sinceState=None):
    if sinceState is not None and type(sinceState) is not str:
        raise InvalidArguments

    yield [
        "accounts",
        [
            account.toDict()
            for account in Account.getAccountsByUserId(auth.current_user.id)
        ]
    ]
示例#2
0
def _set(object, ifInState, create, update, destroy):
    """
    setFoos method, see specs.
    """
    # TODO handle ifInState
    newState = current_user.getNextState()
    response = {
        'oldState': None,
        'newState': newState,
        'created': {},
        'updated': [],
        'destroyed': [],
        'notCreated': {},
        'notUpdated': {},
        'notDestroyed': {},
    }
    # create
    for id, data in create:
        try:
            obj = Account()
            obj.setFromArray(data, newState)
            obj.save()
            response['created'][id] = obj.toDict()
        except Exception as e:
            current_app.logger.warning(e)
            response['notCreated'][id] = {
                'type': e,
                'description': e.message
            }

    # update
    for id, data in update:
        try:
            obj = Account.getAccountById(id)
            obj.setFromArray(data, newState)
            obj.save()
            response['updated'].push(id)
        except Exception as e:
            current_app.logger.warning(e)
            response['notUpdated'][id] = {
                'type': e,
                'description': e.message
            }

    # destroy
    for id, data in delete:
        try:
            obj = Account.getAccountById(id)
            obj.markAsDeleted(newState)
            obj.save()
            response['destroyed'].push(id)
        except Exception as e:
            current_app.logger.warning(e)
            response['notDestroyed'][id] = {
                'type': e,
                'description': e.message
            }

    db.commit()
    yield response
示例#3
0
文件: methods.py 项目: ligro/pyjmap
def getAccounts(sinceState=None):
    if sinceState is not None and type(sinceState) is not str:
        raise InvalidArguments

    yield ["accounts", [account.toDict() for account in Account.getAccountsByUserId(auth.current_user.id)]]
示例#4
0
def getAccounts(sinceState=None):
    if sinceState is not None and type(sinceState) is not str:
        raise InvalidArguments

    current_app.logger.debug(auth.current_user)
    yield ["accounts", Account.getAccountsByUserId(auth.current_user.id)]