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')}
Example #2
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')}
 def post(self):
     obj = self.request.validated["request"]
     obj.id = generate_id()
     obj.requestId = generate_request_id(get_now(), self.db, self.server_id)
     set_author(obj.documents, self.request, "author")
     upload_objects_documents(self.request, obj)
     save_request(self.request, date_modified=obj.dateCreated)
     LOGGER.info(
         "Created request {}".format(obj.id),
         extra=context_unpack(
             self.request,
             {"MESSAGE_ID": "request_create"},
             {"MONITORING_ID": obj.id},
         ),
     )
     self.request.response.status = 201
     self.request.response.headers["Location"] = self.request.route_url(
         "Request", request_id=obj.id
     )
     return {"data": request_serialize_view(obj, self.request.authenticated_role)}
def set_ownership(data, request, fieldname='owner'):
    for item in data if isinstance(data, list) else [data]:
        setattr(item, fieldname, request.authenticated_userid)
        setattr(item, '{}_token'.format(fieldname), generate_id())