Beispiel #1
0
 def post(self):
     form = UserGroupForm(data=request.get_json())
     if not form.validate():
         abort(400)
     group = UserGroup(**form.data)
     db.session.add(group)
     db.session.commit()
     response = jsonify(**group.to_dict())
     response.status_code = 201
     response.headers.add("Location", f"groups/{group.id}")
     return response
Beispiel #2
0
 def put(self, group_id):
     group = UserGroup.query.filter_by(id=int(group_id)).first()
     if not group:
         abort(404)
     form = UserGroupForm(data=request.get_json())
     if not form.validate():
         abort(400)
     columns_keys = UserGroup.__table__.columns.keys()
     for field in columns_keys:
         if field in form.data:
             setattr(group, field, form.data[field])
     db.session.commit()
     response = jsonify(group.to_dict())
     response.status_code = 200
     return response