6
0

EditLabelParent.py 992 B

1234567891011121314151617181920212223242526272829303132333435363738
  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 __init__(self, nm: NotificationManager):
  12. # pylint: disable=invalid-name
  13. self.nm = nm
  14. def dispatch_request(self, project_id: int, label_id: int):
  15. # extract request data
  16. data = request.get_json(force=True)
  17. if 'parent' not in data:
  18. abort(400)
  19. # find label
  20. label = Label.query.filter_by(id=label_id, project_id=project_id).one_or_none()
  21. if label is None:
  22. abort(404)
  23. # change parent
  24. label.set_parent(data['parent'])
  25. # send notification
  26. self.nm.edit_label(label.id)
  27. # return success response
  28. return make_response()