CreateLabel.py 1.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. from flask import request, abort, make_response
  2. from flask.views import View
  3. from pycs import db
  4. from pycs.database.Project import Project
  5. from pycs.frontend.notifications.NotificationManager import NotificationManager
  6. class CreateLabel(View):
  7. """
  8. create a new label
  9. """
  10. # pylint: disable=arguments-differ
  11. methods = ['POST']
  12. def __init__(self, nm: NotificationManager):
  13. # pylint: disable=invalid-name
  14. self.nm = nm
  15. def dispatch_request(self, identifier):
  16. # extract request data
  17. data = request.get_json(force=True)
  18. if 'name' not in data:
  19. abort(400)
  20. name = data['name']
  21. parent = data.get('parent')
  22. # find project
  23. project = Project.query.get(identifier)
  24. if project is None:
  25. abort(404)
  26. # insert label
  27. label, _ = project.create_label(name, parent_id=parent)
  28. # send notification
  29. self.nm.create_label(label.id)
  30. # return success response
  31. return make_response()