From fba06976d4f60497640aa0f158784685ec2eae32 Mon Sep 17 00:00:00 2001 From: emmatveev Date: Sun, 24 Nov 2024 22:49:23 +0300 Subject: [PATCH] fix --- BaseLib/configurator.py | 2 +- experiments/views.py | 42 +++++++++++++++++++++++++++++------------ 2 files changed, 31 insertions(+), 13 deletions(-) diff --git a/BaseLib/configurator.py b/BaseLib/configurator.py index b96a506..aca5724 100644 --- a/BaseLib/configurator.py +++ b/BaseLib/configurator.py @@ -3,7 +3,7 @@ from json import dumps URL_CONFIGS = 'http://configurator/api/v1/configs' -URL_EXPERIMENTS = 'http://configurator/api/v1/configs' +URL_EXPERIMENTS = 'http://configurator/api/v1/experiments' def get_configs(project, stage): diff --git a/experiments/views.py b/experiments/views.py index a788b73..709b55e 100644 --- a/experiments/views.py +++ b/experiments/views.py @@ -1,6 +1,7 @@ from django.http import HttpResponse, JsonResponse from BaseLib.BaseView import BaseView +from BaseLib.configurator import * from Platform import settings from experiments.models import Experiment @@ -17,31 +18,48 @@ class ExperimentsView(BaseView): self.context['stage'] = self.stage def get(self): - self.context['experiments'] = Experiment.objects.filter(project=self.request.user.selected_project, - stage=self.stage).order_by('name') + # self.context['experiments'] = Experiment.objects.filter(project=self.request.user.selected_project, + # stage=self.stage).order_by('name') + self.context['experiments'] = get_experiments(self.request.user.selected_project.name, self.stage) def post_create(self): - Experiment.objects.create(project=self.request.user.selected_project, stage=self.stage, name=self.request.POST['name']) + # Experiment.objects.create(project=self.request.user.selected_project, stage=self.stage, name=self.request.POST['name']) + create_experiment(self.request.user.selected_project.name, self.stage, self.request.POST['name']) return '/experiments/?stage=' + self.stage def post_delete(self): - Experiment.objects.get(id=self.request.POST['experiment_id']).delete() + # Experiment.objects.get(id=self.request.POST['experiment_id']).delete() + delete_experiment(self.request.POST['experiment_id']) return '/experiments/?stage=' + self.stage + def post_change(self): - exp = Experiment.objects.get(id=self.request.POST['experiment_id']) - exp.enabled = 'enabled' in self.request.POST + # exp = Experiment.objects.get(id=self.request.POST['experiment_id']) + # exp.enabled = 'enabled' in self.request.POST + # condition = self.request.POST['condition_select'] + # if condition == 'Другое (только для техлидов)': + # exp.condition = self.request.POST['condition'] + # elif condition == 'Никому': + # exp.condition = 'False' + # elif condition == 'Только админам': + # exp.condition = 'user.is_superuser' + # elif condition == 'Только сотрудникам': + # exp.condition = 'user.platform_staff' + # else: + # exp.condition = 'True' + # exp.save() + enabled = 'enabled' in self.request.POST condition = self.request.POST['condition_select'] if condition == 'Другое (только для техлидов)': - exp.condition = self.request.POST['condition'] + condition = self.request.POST['condition'] elif condition == 'Никому': - exp.condition = 'False' + condition = 'False' elif condition == 'Только админам': - exp.condition = 'user.is_superuser' + condition = 'user.is_superuser' elif condition == 'Только сотрудникам': - exp.condition = 'user.platform_staff' + condition = 'user.platform_staff' else: - exp.condition = 'True' - exp.save() + condition = 'True' + update_experiment(self.request.POST['experiment_id'], enabled, condition) return '/experiments/?stage=' + self.stage