EditLabelParent.py 1.1 KB

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