6
0

EditLabelParent.py 907 B

1234567891011121314151617181920212223242526272829303132333435
  1. from flask import request, abort, make_response
  2. from flask.views import View
  3. from pycs.database.Label import Label
  4. from pycs.frontend.notifications.NotificationManager import NotificationManager
  5. class EditLabelParent(View):
  6. """
  7. edit a labels name
  8. """
  9. # pylint: disable=arguments-differ
  10. methods = ['POST']
  11. def dispatch_request(self, project_id: int, label_id: int):
  12. # extract request data
  13. data = request.get_json(force=True)
  14. if 'parent' not in data:
  15. abort(400)
  16. # find label
  17. label = Label.query.filter_by(id=label_id, project_id=project_id).one_or_none()
  18. if label is None:
  19. abort(404)
  20. # change parent
  21. label.set_parent(data['parent'])
  22. # send notification
  23. NotificationManager.edited("label", label.id, Label)
  24. # return success response
  25. return make_response()