1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950 |
- 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 RemoveLabel(View):
- """
- remove a label from database
- """
- # pylint: disable=arguments-differ
- methods = ['POST']
- def dispatch_request(self, project_id: int, label_id: int):
- # extract request data
- data = request.get_json(force=True)
- if 'remove' not in data or data['remove'] is not True:
- 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)
- # find children
- children = label.children
- # start transaction
- with db.session.begin_nested():
- # remove children's parent entry
- for child in children:
- child.set_parent(None)
- NotificationManager.edited("label", child.id, Label)
- # remove label
- label.remove()
- NotificationManager.removed("label", label.serialize())
- # return success response
- return make_response()
|