EditLabelName.py 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. from flask import request, abort, make_response
  2. from flask.views import View
  3. from pycs.database.Project import Project
  4. from pycs.frontend.notifications.NotificationManager import NotificationManager
  5. class EditLabelName(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 'name' not in data:
  18. abort(400)
  19. # find project
  20. project = Project.query.get(project_id)
  21. if project is None:
  22. abort(404)
  23. # find label
  24. label = project.label(label_id)
  25. if label is None:
  26. abort(404)
  27. # start transaction
  28. with self.db:
  29. # change name
  30. label.set_name(data['name'])
  31. # send notification
  32. self.nm.edit_label(label.id)
  33. # return success response
  34. return make_response()