Beispiel #1
0
 def getProject(self):
   try:
     response = getJson('https://{}/resource/dataset/{}/project/{}/'.format(self.host, self.dataset_name, self.project_name))
     project_json = response.json()
     del project_json['user']
     del project_json['dataset']
     return NDProject.fromJson(self.dataset_name, json.dumps(project_json))
   except Exception as e:
     self.logger.error(e)
     raise e
Beispiel #2
0
 def post(self, request, dataset_name, project_name):
   try:
     pr = NDProject.fromJson(dataset_name, request.body)
     if request.user.is_authenticated():
       pr.user_id = request.user.id
     else:
       pr.user_id = User.objects.get(username='******').id
     pr.create()
     return HttpResponse(status=201)
   except Exception as e:
     return HttpResponseBadRequest()
Beispiel #3
0
 def post(self, request, dataset_name, project_name):
     try:
         pr = NDProject.fromJson(dataset_name, request.body)
         if request.user.is_authenticated():
             pr.user_id = request.user.id
         else:
             pr.user_id = User.objects.get(username='******').id
         pr.create()
         return HttpResponse(status=201)
     except Exception as e:
         return HttpResponseBadRequest()
Beispiel #4
0
 def getProject(self):
     try:
         response = getJson(
             'https://{}/resource/dataset/{}/project/{}/'.format(
                 self.host, self.dataset_name, self.project_name))
         project_json = response.json()
         del project_json['user']
         del project_json['dataset']
         return NDProject.fromJson(self.dataset_name,
                                   json.dumps(project_json))
     except Exception as e:
         self.logger.error(e)
         raise e
Beispiel #5
0
            else:
                logger.error(
                    "Dataset {} already exists and is different then the chosen dataset"
                    .format(ds.dataset_name))
                return HttpResponseBadRequest(json.dumps(
                    "Dataset {} already exists and is different then the chosen dataset. Please choose a different dataset name"
                    .format(ds.dataset_name)),
                                              content_type="application/json")
        else:
            ds.create()
            DATASET_CREATED = True
            # pr.dataset_id = ds.dataset_name

        # extracting project and token
        pr, tk = extractProjectDict(project_dict)
        pr = NDProject.fromJson(ds.dataset_name, pr)
        pr.user_id = 1
        pr.kvengine = REDIS

        # Checking if the posted project already exists
        # Setting the foreign key for project
        if Project.objects.filter(project_name=pr.project_name).exists():
            stored_pr = NDProject.fromName(pr.project_name)
            # Checking if the existing project is same as the posted one, here we compare their datasets since python behaves wierdly with sub-objects in other objects. this is not fool-proof but works as a good hack
            tk = NDToken.fromJson(pr.project_name, tk)
            tk.user_id = 1
            if compareModelObjects(stored_pr.datasetcfg, pr.datasetcfg):
                if Token.objects.filter(token_name=tk.token_name).exists():
                    stored_tk = NDToken.fromName(tk.token_name)
                    # tk.project_id = stored_pr.project_name
                    # Checking if the existing token is same as the posted one
Beispiel #6
0
    if Dataset.objects.filter(dataset_name = ds.dataset_name).exists():
      stored_ds = NDDataset.fromName(ds.dataset_name)
      if compareModelObjects(stored_ds, ds): 
        pass
        # pr.dataset_id = stored_ds.dataset_name
      else:
        logger.error("Dataset {} already exists and is different then the chosen dataset".format(ds.dataset_name))
        return HttpResponseBadRequest(json.dumps("Dataset {} already exists and is different then the chosen dataset. Please choose a different dataset name".format(ds.dataset_name)), content_type="application/json")
    else:
      ds.create()
      DATASET_CREATED = True
      # pr.dataset_id = ds.dataset_name

    # extracting project and token 
    pr, tk = extractProjectDict(project_dict)
    pr = NDProject.fromJson(ds.dataset_name, pr)
    pr.user_id = 1
    pr.kvengine = REDIS
    
    # Checking if the posted project already exists
    # Setting the foreign key for project
    if Project.objects.filter(project_name = pr.project_name).exists():
      stored_pr = NDProject.fromName(pr.project_name)
      # Checking if the existing project is same as the posted one, here we compare their datasets since python behaves wierdly with sub-objects in other objects. this is not fool-proof but works as a good hack
      tk = NDToken.fromJson(pr.project_name, tk)
      tk.user_id = 1
      if compareModelObjects(stored_pr.datasetcfg, pr.datasetcfg):
        if Token.objects.filter(token_name = tk.token_name).exists():
          stored_tk = NDToken.fromName(tk.token_name)
          # tk.project_id = stored_pr.project_name
          # Checking if the existing token is same as the posted one