12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849 |
- from flask import abort
- from flask import make_response
- from flask import request
- from flask.views import View
- from pycs import db
- from pycs.database.File import File
- from pycs.frontend.notifications.NotificationManager import NotificationManager
- class CopyResults(View):
- """
- copy all results for one file to another
- """
- # pylint: disable=arguments-differ
- methods = ['POST']
- def __init__(self, nm: NotificationManager):
- # pylint: disable=invalid-name
- self.nm = nm
- def dispatch_request(self, user: str, file_id: int):
- request_data = request.get_json(force=True)
- if 'copy_from' not in request_data:
- abort(400, "copy_from argument is missing")
- new = []
- # start transaction
- with db.session.begin_nested():
- file = File.get_or_404(file_id)
- other_file = File.get_or_404(request_data.get('copy_from'))
- for result in other_file.results.all():
- new_result = file.create_result(
- origin='pipeline',
- result_type=result.type,
- origin_user=None,
- label=result.label_id,
- data=result.data,
- commit=False)
- new.append(new_result)
- for new_result in new:
- self.nm.create_result(new_result)
- return make_response()
|