6
0

EditLabelName.py 1014 B

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