# Path: openprocurement/tender/openeu/utils.py
# LOGGER = getLogger(__name__)
# def check_initial_bids_count(request):
# def prepare_qualifications(request, bids=[], lotId=None):
# def all_bids_are_reviewed(request):
# def check_status(request):
# 
# Path: openprocurement/tender/openeu/validation.py
# def validate_update_bid_document_confidentiality(request):
#     if request.validated['tender_status'] != 'active.tendering' and 'confidentiality' in request.validated.get('data', {}):
#         if request.context.confidentiality != request.validated['data']['confidentiality']:
#             raise_operation_error(request, 'Can\'t update document confidentiality in current ({}) tender status'.format(request.validated['tender_status']))
# 
# def validate_add_bid_document_not_in_allowed_status(request):
#     if request.context.status in ['invalid', 'unsuccessful', 'deleted']:
#         raise_operation_error(request, 'Can\'t add document to \'{}\' bid'.format(request.context.status))
# 
# def validate_update_bid_document_not_in_allowed_status(request):
#     bid = getattr(request.context, "__parent__")
#     if bid and bid.status in ['invalid', 'unsuccessful', 'deleted']:
#         raise_operation_error(request, 'Can\'t update {} \'{}\' bid'.format('document in' if request.method == 'PUT' else 'document data for',bid.status))


from openprocurement.api.utils import (
    get_file,
    upload_file,
    update_file_content_type,
    json_view,
    context_unpack,
    get_now,
    raise_operation_error
)
from openprocurement.api.validation import (
    validate_file_update,
    validate_file_upload,
    validate_patch_document_data,
)
from openprocurement.tender.core.validation import (
    validate_bid_document_operation_period,
    validate_bid_document_operation_with_award,
    validate_bid_document_operation_in_not_allowed_status
)
from openprocurement.tender.core.utils import (
    save_tender,
    apply_patch,
    optendersresource
)
from openprocurement.tender.openeu.utils import (
    bid_financial_documents_resource,
    bid_eligibility_documents_resource,
    bid_qualification_documents_resource,
)
from openprocurement.tender.openua.views.bid_document import (
    TenderUaBidDocumentResource
)
from openprocurement.tender.openeu.validation import (
    validate_update_bid_document_confidentiality,
    validate_add_bid_document_not_in_allowed_status,
    validate_update_bid_document_not_in_allowed_status
)
        is_bid_owner = self.request.authenticated_role == 'bid_owner'
        if self.request.validated['tender_status'] in self.view_forbidden_states and not is_bid_owner:
            raise_operation_error(self.request, 'Can\'t view bid document in current ({}) tender status'.format(self.request.validated['tender_status']))
        if self.request.validated['bid'].status in self.view_forbidden_bid_states and self.request.authenticated_role != 'bid_owner':
            raise_operation_error(self.request, 'Can\'t view bid documents in current ({}) bid status'.format(self.request.validated['bid'].status))

        document = self.request.validated['document']
        if self.request.params.get('download'):
            if self._doc_access_restricted(document):
                raise_operation_error(self.request, 'Document download forbidden.')
            else:
                return get_file(self.request)
        document_data = document.serialize('restricted_view' if self._doc_access_restricted(document) else 'view')
        document_data['previousVersions'] = [i.serialize('restricted_view') if self._doc_access_restricted(i) else i.serialize('view')
                                             for i in self.request.validated['documents'] if i.url != document.url]
        return {'data': document_data}

    @json_view(content_type="application/json", validators=(validate_patch_document_data, validate_bid_document_operation_in_not_allowed_status, validate_bid_document_operation_period,
               validate_bid_document_operation_with_award, validate_update_bid_document_confidentiality, validate_update_bid_document_not_in_allowed_status), permission='edit_bid')
    def patch(self):
        """Tender Bid Document Update"""
        if self.request.validated['tender_status'] == 'active.tendering':
            self.request.validated['tender'].modified = False
        if apply_patch(self.request, src=self.request.context.serialize()):
            update_file_content_type(self.request)
            self.LOGGER.info('Updated tender bid document {}'.format(self.request.context.id),
                        extra=context_unpack(self.request, {'MESSAGE_ID': 'tender_bid_document_patch'}))
            return {'data': self.request.context.serialize("view")}

    @json_view(validators=(validate_file_update, validate_bid_document_operation_in_not_allowed_status, validate_bid_document_operation_period, validate_bid_document_operation_with_award,

# Path: openprocurement/tender/openeu/utils.py
# LOGGER = getLogger(__name__)
# def check_initial_bids_count(request):
# def prepare_qualifications(request, bids=[], lotId=None):
# def all_bids_are_reviewed(request):
# def check_status(request):
# 
# Path: openprocurement/tender/openeu/validation.py
# def validate_update_bid_document_confidentiality(request):
#     if request.validated['tender_status'] != 'active.tendering' and 'confidentiality' in request.validated.get('data', {}):
#         if request.context.confidentiality != request.validated['data']['confidentiality']:
#             raise_operation_error(request, 'Can\'t update document confidentiality in current ({}) tender status'.format(request.validated['tender_status']))
# 
# def validate_add_bid_document_not_in_allowed_status(request):
#     if request.context.status in ['invalid', 'unsuccessful', 'deleted']:
#         raise_operation_error(request, 'Can\'t add document to \'{}\' bid'.format(request.context.status))
# 
# def validate_update_bid_document_not_in_allowed_status(request):
#     bid = getattr(request.context, "__parent__")
#     if bid and bid.status in ['invalid', 'unsuccessful', 'deleted']:
#         raise_operation_error(request, 'Can\'t update {} \'{}\' bid'.format('document in' if request.method == 'PUT' else 'document data for',bid.status))


# Path: openprocurement/tender/openeu/views/bid_document.py
from openprocurement.api.utils import (
    get_file,
    upload_file,
    update_file_content_type,
    json_view,
    context_unpack,
    get_now,
    raise_operation_error
)
from openprocurement.api.validation import (
    validate_file_update,
    validate_file_upload,
    validate_patch_document_data,
)
from openprocurement.tender.core.validation import (
    validate_bid_document_operation_period,
    validate_bid_document_operation_with_award,
    validate_bid_document_operation_in_not_allowed_status
)
from openprocurement.tender.core.utils import (
    save_tender,
    apply_patch,
    optendersresource
)
from openprocurement.tender.openeu.utils import (
    bid_financial_documents_resource,
    bid_eligibility_documents_resource,
    bid_qualification_documents_resource,
)
from openprocurement.tender.openua.views.bid_document import (
    TenderUaBidDocumentResource
)
from openprocurement.tender.openeu.validation import (
    validate_update_bid_document_confidentiality,
    validate_add_bid_document_not_in_allowed_status,
    validate_update_bid_document_not_in_allowed_status
)

        is_bid_owner = self.request.authenticated_role == 'bid_owner'
        if self.request.validated['tender_status'] in self.view_forbidden_states and not is_bid_owner:
            raise_operation_error(self.request, 'Can\'t view bid document in current ({}) tender status'.format(self.request.validated['tender_status']))
        if self.request.validated['bid'].status in self.view_forbidden_bid_states and self.request.authenticated_role != 'bid_owner':
            raise_operation_error(self.request, 'Can\'t view bid documents in current ({}) bid status'.format(self.request.validated['bid'].status))

        document = self.request.validated['document']
        if self.request.params.get('download'):
            if self._doc_access_restricted(document):
                raise_operation_error(self.request, 'Document download forbidden.')
            else:
                return get_file(self.request)
        document_data = document.serialize('restricted_view' if self._doc_access_restricted(document) else 'view')
        document_data['previousVersions'] = [i.serialize('restricted_view') if self._doc_access_restricted(i) else i.serialize('view')
                                             for i in self.request.validated['documents'] if i.url != document.url]
        return {'data': document_data}

    @json_view(content_type="application/json", validators=(validate_patch_document_data, validate_bid_document_operation_in_not_allowed_status, validate_bid_document_operation_period,
               validate_bid_document_operation_with_award, validate_update_bid_document_confidentiality, validate_update_bid_document_not_in_allowed_status), permission='edit_bid')
    def patch(self):
        """Tender Bid Document Update"""
        if self.request.validated['tender_status'] == 'active.tendering':
            self.request.validated['tender'].modified = False
        if apply_patch(self.request, src=self.request.context.serialize()):
            update_file_content_type(self.request)
            self.LOGGER.info('Updated tender bid document {}'.format(self.request.context.id),
                        extra=context_unpack(self.request, {'MESSAGE_ID': 'tender_bid_document_patch'}))
            return {'data': self.request.context.serialize("view")}

    @json_view(validators=(validate_file_update, validate_bid_document_operation_in_not_allowed_status, validate_bid_document_operation_period, validate_bid_document_operation_with_award,

               validate_update_bid_document_confidentiality, validate_update_bid_document_not_in_allowed_status), permission='edit_bid')