12345678910111213141516171819202122232425262728293031323334353637383940 |
- from flask import request, abort, make_response
- from flask.views import View
- from pycs import db
- from pycs.database.Project import Project
- from pycs.database.Label import Label
- from pycs.frontend.notifications.NotificationManager import NotificationManager
- class CreateLabel(View):
- """
- create a new label
- """
- # pylint: disable=arguments-differ
- methods = ['POST']
- def dispatch_request(self, identifier):
- # extract request data
- data = request.get_json(force=True)
- if 'name' not in data:
- abort(400)
- name = data['name']
- parent = data.get('parent')
- # find project
- project = Project.query.get(identifier)
- if project is None:
- abort(404)
- # insert label
- label, _ = project.create_label(name, parent_id=parent)
- # send notification
- NotificationManager.created("label", label.id, Label)
- # return success response
- return make_response()
|