12345678910111213141516171819202122232425262728293031323334353637383940414243 |
- from os import remove
- from flask import make_response, request, abort
- from flask.views import View
- from pycs.database.File import File
- from pycs.frontend.notifications.NotificationManager import NotificationManager
- class RemoveFile(View):
- """
- remove a given file
- """
- # pylint: disable=arguments-differ
- methods = ['POST']
- def dispatch_request(self, identifier):
- # extract request data
- data = request.get_json(force=True)
- if not data.get('remove', False):
- return abort(400)
- # find file
- file = File.query.get(identifier)
- if file is None:
- return abort(400)
- # check if project uses an external data directory
- if file.project.external_data:
- return abort(400)
- # remove file from database
- file.remove()
- # remove file from folder
- remove(file.path)
- # TODO remove temp files
- # send notification
- NotificationManager.removed("file", file.serialize())
- return make_response()
|