Ejemplo n.º 1
0
    def put(self):
        appeal = self.request.validated['appeal']
        set_author(appeal.documents, self.request, 'author')
        upload_objects_documents(self.request, appeal)
        appeal.datePublished = appeal.dateCreated

        apply_patch(self.request, data=dict(appeal=appeal))
        self.LOGGER.info('Updated appeal {}'.format(self.request.context.id),
                         extra=context_unpack(self.request, {'MESSAGE_ID': 'appeal_put'}))
        return {'data': appeal.serialize('view')}
 def put(self):
     parent = self.request.context.__parent__
     document = upload_file(self.request)
     set_author(document, self.request, 'author')
     parent.documents.append(document)
     if save_inspection(self.request):
         self.LOGGER.info('Updated inspection document {}'.format(document.id),
                          extra=context_unpack(self.request,
                                               {'MESSAGE_ID': 'inspection_document_put'},
                                               {'DOCUMENT_ID': document.id}))
         return {'data': document.serialize("view")}
 def put(self):
     elimination = self.request.validated['eliminationreport']
     elimination.datePublished = elimination.dateCreated
     set_author(elimination.documents, self.request, 'author')
     upload_objects_documents(self.request, elimination)
     apply_patch(self.request,
                 data=dict(eliminationReport=elimination),
                 date_modified=elimination.dateCreated)
     self.LOGGER.info(
         'Updated elimination {}'.format(self.request.context.id),
         extra=context_unpack(self.request,
                              {'MESSAGE_ID': 'elimination_put'}))
     return {'data': elimination.serialize('view')}
 def collection_post(self):
     document = upload_file(self.request)
     set_author(document, self.request, 'author')
     documents = self.context.documents
     documents.append(document)
     if save_inspection(self.request):
         self.LOGGER.info('Created inspection document {}'.format(document.id),
                          extra=context_unpack(self.request,
                                               {'MESSAGE_ID': 'inspection_document_create'},
                                               {'DOCUMENT_ID': document.id}))
         route = self.request.matched_route.name.replace("collection_", "")
         location = self.request.current_route_url(document_id=document.id, _route_name=route, _query={})
         self.request.response.status = 201
         self.request.response.headers['Location'] = location
         return {'data': document.serialize("view")}
 def post(self):
     inspection = self.request.validated['inspection']
     inspection.id = generate_id()
     inspection.inspection_id = generate_inspection_id(
         get_now(), self.db, self.server_id)
     set_author(inspection.documents, self.request, 'author')
     save_inspection(self.request, date_modified=inspection.dateCreated)
     LOGGER.info('Created inspection {}'.format(inspection.id),
                 extra=context_unpack(self.request,
                                      {'MESSAGE_ID': 'inspection_create'},
                                      {'MONITORING_ID': inspection.id}))
     self.request.response.status = 201
     self.request.response.headers['Location'] = self.request.route_url(
         'Inspection', inspection_id=inspection.id)
     return {'data': inspection.serialize('view')}
Ejemplo n.º 6
0
 def put(self):
     """
     Monitoring Document Update
     """
     parent = self.request.context.__parent__
     document = upload_file(self.request)
     set_author(document, self.request, 'author')
     parent.documents.append(document)
     if save_monitoring(self.request):
         self.LOGGER.info(
             'Updated {} monitoring document {}'.format(
                 self.document_type, document.id),
             extra=context_unpack(self.request,
                                  {'MESSAGE_ID': 'monitoring_document_put'},
                                  {'DOCUMENT_ID': document.id}))
         return {'data': document.serialize('view')}
    def collection_post(self):

        monitoring = self.context
        liability = self.request.validated['liability']
        set_author(liability.documents, self.request, 'author')
        # upload_objects_documents(self.request, liability)
        monitoring.liabilities.append(liability)
        if save_monitoring(self.request):
            self.LOGGER.info(
                'Created monitoring liability {}'.format(liability.id),
                extra=context_unpack(self.request,
                                     {'MESSAGE_ID': 'liability_create'},
                                     {'liability_id': liability.id}))
            self.request.response.status = 201
            self.request.response.headers['Location'] = self.request.route_url(
                'Monitoring Liability',
                monitoring_id=monitoring.id,
                liability_id=liability.id)
            return {'data': liability.serialize('view')}
Ejemplo n.º 8
0
 def post(self):
     monitoring = self.request.validated['monitoring']
     monitoring.id = generate_id()
     monitoring.monitoring_id = generate_monitoring_id(
         get_now(), self.db, self.server_id)
     if monitoring.decision:
         upload_objects_documents(self.request,
                                  monitoring.decision,
                                  key="decision")
         set_author(monitoring.decision.documents, self.request, 'author')
     save_monitoring(self.request, date_modified=monitoring.dateCreated)
     LOGGER.info('Created monitoring {}'.format(monitoring.id),
                 extra=context_unpack(self.request,
                                      {'MESSAGE_ID': 'monitoring_create'},
                                      {'MONITORING_ID': monitoring.id}))
     self.request.response.status = 201
     self.request.response.headers['Location'] = self.request.route_url(
         'Monitoring', monitoring_id=monitoring.id)
     return {'data': monitoring.serialize('view')}
Ejemplo n.º 9
0
 def collection_post(self):
     """
     Monitoring Document Upload
     """
     document = upload_file(self.request)
     set_author(document, self.request, 'author')
     documents = self.context.documents
     documents.append(document)
     if save_monitoring(self.request):
         self.LOGGER.info('Created {} monitoring document {}'.format(
             self.document_type, document.id),
                          extra=context_unpack(
                              self.request,
                              {'MESSAGE_ID': 'monitoring_document_create'},
                              {'DOCUMENT_ID': document.id}))
         route = self.request.matched_route.name.replace('collection_', '')
         location = self.request.current_route_url(document_id=document.id,
                                                   _route_name=route,
                                                   _query={})
         self.request.response.status = 201
         self.request.response.headers['Location'] = location
         return {'data': document.serialize('view')}
Ejemplo n.º 10
0
 def collection_post(self):
     """
     Post a post
     """
     monitoring = self.context
     post = self.request.validated['post']
     set_author(post, self.request, 'author')
     set_author(post.documents, self.request, 'author')
     upload_objects_documents(self.request, post)
     if post.author == get_monitoring_role('sas') and post.relatedPost is None:
         accelerator = get_monitoring_accelerator(self.context)
         post.dateOverdue = calculate_normalized_business_date(get_now(), POST_OVERDUE_TIME, accelerator)
     if monitoring.status in (ADDRESSED_STATUS, DECLINED_STATUS):
         post.postOf = CONCLUSION_OBJECT_TYPE
     monitoring.posts.append(post)
     if save_monitoring(self.request):
         self.LOGGER.info('Created monitoring post {}'.format(post.id),
                          extra=context_unpack(self.request,
                                               {'MESSAGE_ID': 'monitoring_post_create'},
                                               {'POST_ID': post.id}))
         self.request.response.status = 201
         self.request.response.headers['Location'] = self.request.route_url(
             'Monitoring Post', monitoring_id=monitoring.id, post_id=post.id)
         return {'data': post.serialize('view')}
Ejemplo n.º 11
0
    def patch(self):
        monitoring = self.request.validated['monitoring']
        monitoring_old_status = monitoring.status
        elimination_resolution = monitoring.eliminationResolution

        apply_patch(self.request,
                    save=False,
                    src=self.request.validated['monitoring_src'])

        now = get_now()
        if monitoring_old_status == DRAFT_STATUS and monitoring.status == ACTIVE_STATUS:
            set_author(monitoring.decision.documents, self.request, 'author')
            accelerator = get_monitoring_accelerator(self.context)
            monitoring.monitoringPeriod = generate_period(
                now, MONITORING_TIME, accelerator)
            monitoring.decision.datePublished = now
            monitoring.endDate = calculate_normalized_business_date(
                now, MONITORING_TIME, accelerator)
        elif monitoring_old_status == ACTIVE_STATUS and monitoring.status == ADDRESSED_STATUS:
            set_author(monitoring.conclusion.documents, self.request, 'author')
            accelerator = get_monitoring_accelerator(self.context)
            monitoring.conclusion.datePublished = now
            monitoring.eliminationPeriod = generate_period(
                now, ELIMINATION_PERIOD_TIME, accelerator)
        elif monitoring_old_status == ACTIVE_STATUS and monitoring.status == DECLINED_STATUS:
            accelerator = get_monitoring_accelerator(self.context)
            monitoring.eliminationPeriod = generate_period(
                now, ELIMINATION_PERIOD_NO_VIOLATIONS_TIME, accelerator)
            monitoring.conclusion.datePublished = now
        elif any([
                monitoring_old_status == DRAFT_STATUS
                and monitoring.status == CANCELLED_STATUS,
                monitoring_old_status == ACTIVE_STATUS
                and monitoring.status == STOPPED_STATUS,
                monitoring_old_status == DECLINED_STATUS
                and monitoring.status == STOPPED_STATUS,
                monitoring_old_status == ADDRESSED_STATUS
                and monitoring.status == STOPPED_STATUS
        ]):
            set_author(monitoring.cancellation.documents, self.request,
                       'author')
            monitoring.cancellation.datePublished = now

        if not elimination_resolution and monitoring.eliminationResolution:
            validate_posting_elimination_resolution(self.request)
            monitoring.eliminationResolution.datePublished = monitoring.eliminationResolution.dateCreated

        # download (change urls of) documents for Decision, Conclusion, etc.
        raw_data = self.request.json.get("data", {})
        for key in raw_data.keys():
            if hasattr(getattr(monitoring, key, None),
                       "documents") and "documents" in raw_data[key]:
                upload_objects_documents(self.request,
                                         getattr(monitoring, key),
                                         key=key)

        save_monitoring(self.request, date_modified=now)
        LOGGER.info('Updated monitoring {}'.format(monitoring.id),
                    extra=context_unpack(self.request,
                                         {'MESSAGE_ID': 'monitoring_patch'}))
        return {'data': monitoring.serialize('view')}