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
def loader(): try: current = int(request.args.get('current')) except ValueError: current = None return jsonify(forms=serialize_sqla(CustomForm.aslist(current)))
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))
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))
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))
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.")
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()))