def put(self):
     """Tender Award Complaint Document Update"""
     if self.request.authenticated_role != self.context.author:
         self.request.errors.add('url', 'role', 'Can update document only author')
         self.request.errors.status = 403
         return
     if self.request.validated['tender_status'] not in ['active.qualification', 'active.awarded']:
         self.request.errors.add('body', 'data', 'Can\'t update document in current ({}) tender status'.format(self.request.validated['tender_status']))
         self.request.errors.status = 403
         return
     if any([i.status != 'active' for i in self.request.validated['tender'].lots if i.id == self.request.validated['award'].lotID]):
         self.request.errors.add('body', 'data', 'Can update document only in active lot status')
         self.request.errors.status = 403
         return
     if self.request.validated['complaint'].status not in STATUS4ROLE.get(self.request.authenticated_role, []):
         self.request.errors.add('body', 'data', 'Can\'t update document in current ({}) complaint status'.format(self.request.validated['complaint'].status))
         self.request.errors.status = 403
         return
     document = upload_file(self.request)
     document.author = self.request.authenticated_role
     self.request.validated['complaint'].documents.append(document)
     if save_tender(self.request):
         LOGGER.info('Updated tender award complaint document {}'.format(self.request.context.id),
                     extra=context_unpack(self.request, {'MESSAGE_ID': 'tender_award_complaint_document_put'}))
         return {'data': document.serialize("view")}
 def validate_complaint_document(self, operation):
     if operation == 'update' and self.request.authenticated_role != self.context.author:
         self.request.errors.add('url', 'role',
                                 'Can update document only author')
         self.request.errors.status = 403
         return
     if self.request.validated['tender_status'] not in [
             'active.qualification', 'active.awarded'
     ]:
         self.request.errors.add(
             'body', 'data',
             'Can\'t {} document in current ({}) tender status'.format(
                 operation, self.request.validated['tender_status']))
         self.request.errors.status = 403
         return
     if any([
             i.status != 'active'
             for i in self.request.validated['tender'].lots
             if i.id == self.request.validated['award'].lotID
     ]):
         self.request.errors.add(
             'body', 'data',
             'Can {} document only in active lot status'.format(operation))
         self.request.errors.status = 403
         return
     if self.request.validated['complaint'].status not in STATUS4ROLE.get(
             self.request.authenticated_role, []):
         self.request.errors.add(
             'body', 'data',
             'Can\'t {} document in current ({}) complaint status'.format(
                 operation, self.request.validated['complaint'].status))
         self.request.errors.status = 403
         return
     return True
 def collection_post(self):
     """Tender Award Complaint Document Upload
     """
     if self.request.validated['tender_status'] not in ['active.qualification', 'active.awarded']:
         self.request.errors.add('body', 'data', 'Can\'t add document in current ({}) tender status'.format(self.request.validated['tender_status']))
         self.request.errors.status = 403
         return
     if any([i.status != 'active' for i in self.request.validated['tender'].lots if i.id == self.request.validated['award'].lotID]):
         self.request.errors.add('body', 'data', 'Can add document only in active lot status')
         self.request.errors.status = 403
         return
     if self.context.status not in STATUS4ROLE.get(self.request.authenticated_role, []):
         self.request.errors.add('body', 'data', 'Can\'t add document in current ({}) complaint status'.format(self.context.status))
         self.request.errors.status = 403
         return
     document = upload_file(self.request)
     document.author = self.request.authenticated_role
     self.context.documents.append(document)
     if save_tender(self.request):
         LOGGER.info('Created tender award complaint document {}'.format(document.id),
                     extra=context_unpack(self.request, {'MESSAGE_ID': 'tender_award_complaint_document_create'}, {'document_id': document.id}))
         self.request.response.status = 201
         document_route = self.request.matched_route.name.replace("collection_", "")
         self.request.response.headers['Location'] = self.request.current_route_url(_route_name=document_route, document_id=document.id, _query={})
         return {'data': document.serialize("view")}
 def validate_complaint_document(self, operation):
     if operation == 'update' and self.request.authenticated_role != self.context.author:
         self.request.errors.add('url', 'role', 'Can update document only author')
         self.request.errors.status = 403
         return
     if self.request.validated['tender_status'] not in ['active.pre-qualification', 'active.pre-qualification.stand-still']:
         self.request.errors.add('body', 'data', 'Can\'t {} document in current ({}) tender status'.format(operation, self.request.validated['tender_status']))
         self.request.errors.status = 403
         return
     if any(i.status != 'active' for i in self.request.validated['tender'].lots if i.id == self.request.validated['qualification'].lotID):
         self.request.errors.add('body', 'data', 'Can {} document only in active lot status'.format(operation))
         self.request.errors.status = 403
         return
     if self.request.validated['complaint'].status not in STATUS4ROLE.get(self.request.authenticated_role, []):
         self.request.errors.add('body', 'data', 'Can\'t {} document in current ({}) complaint status'.format(operation, self.request.validated['complaint'].status))
         self.request.errors.status = 403
         return
     return True
 def validate_complaint_document(self, operation):
     if operation == 'update' and self.request.authenticated_role != self.context.author:
         self.request.errors.add('url', 'role',
                                 'Can update document only author')
         self.request.errors.status = 403
         return
     if self.request.validated['tender_status'] != 'active':
         self.request.errors.add(
             'body', 'data',
             'Can\'t {} document in current ({}) tender status'.format(
                 operation, self.request.validated['tender_status']))
         self.request.errors.status = 403
         return
     if self.request.validated['complaint'].status not in STATUS4ROLE.get(
             self.request.authenticated_role, []):
         self.request.errors.add(
             'body', 'data',
             'Can\'t {} document in current ({}) complaint status'.format(
                 operation, self.request.validated['complaint'].status))
         self.request.errors.status = 403
         return
     return True