123456789101112131415161718192021222324252627282930313233343536373839404142 |
- from flask import request, abort, make_response
- from flask.views import View
- from pycs import db
- from pycs.database.Project import Project
- from pycs.frontend.notifications.NotificationManager import NotificationManager
- class CreateLabel(View):
- """
- create a new label
- """
- # pylint: disable=arguments-differ
- methods = ['POST']
- def __init__(self, nm: NotificationManager):
- # pylint: disable=invalid-name
- self.nm = nm
- 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
- self.nm.create_label(label.id)
- # return success response
- return make_response()
|