def put(self):
     """Auction 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['auction_status'] not in ['active.qualification', 'active.awarded']:
         self.request.errors.add('body', 'data', 'Can\'t update document in current ({}) auction status'.format(self.request.validated['auction_status']))
         self.request.errors.status = 403
         return
     if any([i.status != 'active' for i in self.request.validated['auction'].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_auction(self.request):
         self.LOGGER.info('Updated auction award complaint document {}'.format(self.request.context.id),
                     extra=context_unpack(self.request, {'MESSAGE_ID': 'auction_award_complaint_document_put'}))
         return {'data': document.serialize("view")}
 def put(self):
     """Auction 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['auction_status'] not in ['active.qualification', 'active.awarded']:
         self.request.errors.add('body', 'data', 'Can\'t update document in current ({}) auction status'.format(self.request.validated['auction_status']))
         self.request.errors.status = 403
         return
     if any([i.status != 'active' for i in self.request.validated['auction'].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_auction(self.request):
         self.LOGGER.info('Updated auction award complaint document {}'.format(self.request.context.id),
                     extra=context_unpack(self.request, {'MESSAGE_ID': 'auction_award_complaint_document_put'}))
         return {'data': document.serialize("view")}
 def collection_post(self):
     """Auction Award Complaint Document Upload
     """
     if self.request.validated['auction_status'] not in ['active.qualification', 'active.awarded']:
         self.request.errors.add('body', 'data', 'Can\'t add document in current ({}) auction status'.format(self.request.validated['auction_status']))
         self.request.errors.status = 403
         return
     if any([i.status != 'active' for i in self.request.validated['auction'].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_auction(self.request):
         self.LOGGER.info('Created auction award complaint document {}'.format(document.id),
                     extra=context_unpack(self.request, {'MESSAGE_ID': 'auction_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 collection_post(self):
     """Auction Award Complaint Document Upload
     """
     if self.request.validated['auction_status'] not in ['active.qualification', 'active.awarded']:
         self.request.errors.add('body', 'data', 'Can\'t add document in current ({}) auction status'.format(self.request.validated['auction_status']))
         self.request.errors.status = 403
         return
     if any([i.status != 'active' for i in self.request.validated['auction'].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_auction(self.request):
         self.LOGGER.info('Created auction award complaint document {}'.format(document.id),
                     extra=context_unpack(self.request, {'MESSAGE_ID': 'auction_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")}
Example #5
0
 def patch(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
     if apply_patch(self.request, src=self.request.context.serialize()):
         update_file_content_type(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_patch'}))
         return {'data': self.request.context.serialize("view")}
 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):
         self.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 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):
         self.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 patch(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
     if apply_patch(self.request, src=self.request.context.serialize()):
         update_file_content_type(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_patch'}))
         return {'data': self.request.context.serialize("view")}