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 not data.get('remove', False): abort(400, "\"remove\" command was not found!") # find project project = Project.query.get(project_id) if project is None: abort(404, f"Project with id {project_id} not found") # find label label = project.label(label_id) if label is None: abort(404, f"Label with id {label_id} not found") # start transaction with db.session.begin_nested(): # remove children's parent entry for child in label.children: child.set_parent(None, commit=False) NotificationManager.edited("label", child.id, Label) # remove label label.remove() NotificationManager.removed("label", label.serialize()) # return success response return make_response()