123456789101112131415161718192021222324252627282930313233343536373839404142434445 |
- from flask import request, abort, make_response
- from flask.views import View
- from pycs.database.Project import Project
- from pycs.frontend.notifications.NotificationManager import NotificationManager
- class EditLabelName(View):
- """
- edit a labels name
- """
- # pylint: disable=arguments-differ
- methods = ['POST']
- def __init__(self, nm: NotificationManager):
- # pylint: disable=invalid-name
- self.nm = nm
- def dispatch_request(self, project_id: int, label_id: int):
- # extract request data
- data = request.get_json(force=True)
- if 'name' not in data:
- abort(400)
- # find project
- project = Project.query.get(project_id)
- if project is None:
- abort(404)
- # find label
- label = project.label(label_id)
- if label is None:
- abort(404)
- # start transaction
- with self.db:
- # change name
- label.set_name(data['name'])
- # send notification
- self.nm.edit_label(label.id)
- # return success response
- return make_response()
|