예제 #1
0
    def to_dict(self):
        """Convert a sqlalchemy object instance to a dictionary.

        This is needed for json serialization of an object. The jsons attribute
        is used to determine what values to serialize (password hashes and such
        should not in there).

        """
        attrs = {}
        set_jsons = False

        if not self.jsons:
            self.jsons = (column.name for column in self.__table__.columns)
            set_jsons = True

        for column in self.jsons:
            value = serialize_sqla(getattr(self, column))
            attrs[column] = value

        if self.json_relationships:
            for rel in self.json_relationships:
                attrs[rel] = serialize_sqla(getattr(self, rel).all())

        if set_jsons:
            self.jsons = None

        return attrs
예제 #2
0
def loader():
    try:
        current = int(request.args.get('current'))
    except ValueError:
        current = None

    return jsonify(forms=serialize_sqla(CustomForm.aslist(current)))
예제 #3
0
파일: matrix.py 프로젝트: JelteF/bottor
def get_all():
    """ Get all data matrices """
    matrices = MatrixController.get_all_data()

    if not matrices:
        return jsonify(error='No matrices were found'), 500

    return jsonify(matrices=serialize_sqla(matrices))
예제 #4
0
파일: matrix.py 프로젝트: JelteF/bottor
def get(matrix_id):
    """ Get matrix """
    matrix = MatrixController.get(matrix_id)

    if not matrix:
        return jsonify(error='Matrix not found'), 500

    return jsonify(matrix=serialize_sqla(matrix))
예제 #5
0
def get(peer_id):
    """ Get peer """
    peer = PeerController.get(peer_id)

    if not peer:
        return jsonify(error='Peer not found'), 500

    return jsonify(peer=serialize_sqla(peer))
예제 #6
0
파일: peer.py 프로젝트: JelteF/bottor
def get(peer_id):
    """ Get peer """
    peer = PeerController.get(peer_id)

    if not peer:
        return jsonify(error='Peer not found'), 500

    return jsonify(peer=serialize_sqla(peer))
예제 #7
0
파일: login.py 프로젝트: JelteF/bottor
def check_login(name, password):
    """Check if a username, password combination match."""
    user = Account.query.filter(Account.name == name).first()
    if user is None:
        raise ValueError("Gebruiker niet gevonden.")
    else:
        if user.check_password(password):
            return serialize_sqla(user)
        else:
            raise ValueError("Verkeerd wachtwoord.")
예제 #8
0
def get_contacts(location_id):
    if not ModuleAPI.can_read('contacts'):
        return jsonify(error=_('No permissions to read contacts'))

    location = Location.query.get(location_id)
    return jsonify(contacts=serialize_sqla(location.contacts.all()))