6
0

EditLabelName.py 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. from flask import request, abort, make_response
  2. from flask.views import View
  3. from pycs.database.Database import Database
  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, db: Database, nm: NotificationManager):
  12. # pylint: disable=invalid-name
  13. self.db = db
  14. self.nm = nm
  15. def dispatch_request(self, project_id: int, label_id: int):
  16. # extract request data
  17. data = request.get_json(force=True)
  18. if 'name' not in data:
  19. abort(400)
  20. # find project
  21. project = self.db.project(project_id)
  22. if project is None:
  23. abort(404)
  24. # find label
  25. label = project.label(label_id)
  26. if label is None:
  27. abort(404)
  28. # start transaction
  29. with self.db:
  30. # insert label
  31. label.set_name(data['name'])
  32. # send notification
  33. self.nm.edit_label(label)
  34. # return success response
  35. return make_response()