Ejemplo n.º 1
0
 def post(self, request):
     """
     This POST method expects a file identified by the key 'file' in the set of files uploaded
     by the client in multipart MIME format ('multipart/form-data'). The uploaded file is used
     to create a competition definition bundle on behalf of the logged in user. When the bundle
     is created a job is launched to start the process of creating the competition from the
     specified definition. The job ID is returned to the client in a JSON object:
         { 'token': <value> }
     Use the token with CompetitionCreationStatusApi to track the progress of the job.
     """
     blob_name = request.DATA['id'] if 'id' in request.DATA else ''
     if len(blob_name) <= 0:
         return Response("Invalid or missing tracking ID.",
                         status=status.HTTP_400_BAD_REQUEST)
     owner = self.request.user
     logger.debug("CompetitionCreation: owner=%s; filename=%s.", owner.id,
                  blob_name)
     cdb = webmodels.CompetitionDefBundle.objects.create(owner=owner)
     cdb.config_bundle.name = blob_name
     cdb.save()
     logger.debug("CompetitionCreation def: owner=%s; def=%s; blob=%s.",
                  owner.id, cdb.pk, cdb.config_bundle.name)
     job = create_competition(cdb.pk)
     logger.debug("CompetitionCreation job: owner=%s; def=%s; job=%s.",
                  owner.id, cdb.pk, job.pk)
     return Response({'token': job.pk}, status=status.HTTP_201_CREATED)
Ejemplo n.º 2
0
 def post(self, request):
     """
     This POST method expects a file identified by the key 'file' in the set of files uploaded
     by the client in multipart MIME format ('multipart/form-data'). The uploaded file is used
     to create a competition definition bundle on behalf of the logged in user. When the bundle
     is created a job is launched to start the process of creating the competition from the
     specified definition. The job ID is returned to the client in a JSON object:
         { 'token': <value> }
     Use the token with CompetitionCreationStatusApi to track the progress of the job.
     """
     blob_name = request.DATA["id"] if "id" in request.DATA else ""
     if len(blob_name) <= 0:
         return Response("Invalid or missing tracking ID.", status=status.HTTP_400_BAD_REQUEST)
     owner = self.request.user
     logger.debug("CompetitionCreation: owner=%s; filename=%s.", owner.id, blob_name)
     cdb = webmodels.CompetitionDefBundle.objects.create(owner=owner)
     cdb.config_bundle.name = blob_name
     cdb.save()
     logger.debug("CompetitionCreation def: owner=%s; def=%s; blob=%s.", owner.id, cdb.pk, cdb.config_bundle.name)
     job = create_competition(cdb.pk)
     logger.debug("CompetitionCreation job: owner=%s; def=%s; job=%s.", owner.id, cdb.pk, job.pk)
     return Response({"token": job.pk}, status=status.HTTP_201_CREATED)