config
This commit is contained in:
parent
d027e9b91c
commit
fb299a7908
@ -6,7 +6,8 @@ services:
|
||||
platform-nginx:
|
||||
image: mathwave/sprint-repo:platform
|
||||
networks:
|
||||
- common-infra-nginx
|
||||
- common-infra-nginx-development
|
||||
- configurator-devlopment
|
||||
environment:
|
||||
DB_HOST: "pg.develop.sprinthub.ru"
|
||||
DB_PASSWORD: $DB_PASSWORD_DEV
|
||||
@ -74,5 +75,7 @@ services:
|
||||
order: start-first
|
||||
|
||||
networks:
|
||||
common-infra-nginx:
|
||||
common-infra-nginx-development:
|
||||
external: true
|
||||
configurator-development:
|
||||
external: true
|
@ -7,6 +7,7 @@ services:
|
||||
image: mathwave/sprint-repo:platform
|
||||
networks:
|
||||
- common-infra-nginx
|
||||
- configurator
|
||||
environment:
|
||||
DB_HOST: "pg.sprinthub.ru"
|
||||
DB_PASSWORD: $DB_PASSWORD_PROD
|
||||
@ -82,3 +83,5 @@ services:
|
||||
networks:
|
||||
common-infra-nginx:
|
||||
external: true
|
||||
configurator:
|
||||
external: true
|
||||
|
43
BaseLib/configurator.py
Normal file
43
BaseLib/configurator.py
Normal file
@ -0,0 +1,43 @@
|
||||
from requests import get, put, post, delete
|
||||
|
||||
|
||||
URL_CONFIGS = 'http://configurator/api/v1/configs'
|
||||
URL_EXPERIMENTS = 'http://configurator/api/v1/configs'
|
||||
|
||||
|
||||
def get_configs(project, stage):
|
||||
response = get(URL_CONFIGS, params={'project': project, 'stage': stage})
|
||||
if response.status_code != 200:
|
||||
return []
|
||||
return response.json()
|
||||
|
||||
|
||||
def create_config(project, stage, name):
|
||||
post(URL_CONFIGS, json={'project': project, 'stage': stage, 'name': name})
|
||||
|
||||
|
||||
def update_config(id, value):
|
||||
put(URL_CONFIGS, json={'id': id, 'value': value})
|
||||
|
||||
|
||||
def delete_config(id):
|
||||
delete(URL_CONFIGS, json={'id': id})
|
||||
|
||||
|
||||
def get_experiments(project, stage):
|
||||
response = get(URL_EXPERIMENTS, params={'project': project, 'stage': stage})
|
||||
if response.status_code != 200:
|
||||
return []
|
||||
return response.json()
|
||||
|
||||
|
||||
def create_experiment(project, stage, name):
|
||||
post(URL_EXPERIMENTS, json={'project': project, 'stage': stage, 'name': name})
|
||||
|
||||
|
||||
def update_experiment(id, enabled, condition):
|
||||
put(URL_EXPERIMENTS, json={'id': id, 'enabled': enabled, 'condition': condition})
|
||||
|
||||
|
||||
def delete_experiment(id):
|
||||
delete(URL_CONFIGS, json={'id': id})
|
@ -3,6 +3,7 @@ from json import loads
|
||||
from django.http import HttpResponse, JsonResponse
|
||||
|
||||
from BaseLib.BaseView import BaseView
|
||||
from BaseLib.configurator import *
|
||||
from Platform import settings
|
||||
from configs.models import Config
|
||||
|
||||
@ -20,31 +21,35 @@ class ConfigsView(BaseView):
|
||||
return '/configs/?stage=production'
|
||||
self.stage = self.request.GET['stage']
|
||||
self.context['stage'] = self.stage
|
||||
self.context['configs'] = Config.objects.filter(project=self.request.user.selected_project,
|
||||
stage=self.stage).order_by('name')
|
||||
# self.context['configs'] = Config.objects.filter(project=self.request.user.selected_project,
|
||||
# stage=self.stage).order_by('name')
|
||||
self.context['configs'] = get_configs(self.request.user.selected_project.name, self.stage)
|
||||
|
||||
def post_create_config(self):
|
||||
Config.objects.create(name=self.request.POST['name'], project=self.request.user.selected_project, stage=self.stage)
|
||||
create_config(self.request.user.selected_project.name, self.stage, self.request.POST['name'])
|
||||
# Config.objects.create(name=self.request.POST['name'], project=self.request.user.selected_project, stage=self.stage)
|
||||
return '/configs/?stage=' + self.stage
|
||||
|
||||
def post_delete(self):
|
||||
config = Config.objects.get(id=self.request.POST['config'])
|
||||
config.delete()
|
||||
return '/configs/?stage=' + config.stage
|
||||
# config = Config.objects.get(id=self.request.POST['config'])
|
||||
# config.delete()
|
||||
delete_config(self.request.POST['config'])
|
||||
return '/configs/?stage=' + self.stage
|
||||
|
||||
def post_save(self):
|
||||
data = self.request.POST['data']
|
||||
config = Config.objects.get(id=self.request.POST['config'])
|
||||
# config = Config.objects.get(id=self.request.POST['config'])
|
||||
try:
|
||||
data = loads(data)
|
||||
except:
|
||||
self.context['incorrect_config'] = config
|
||||
self.context['incorrect_config'] = self.request.POST['config']
|
||||
self.context['incorrect_data'] = data
|
||||
self.context['error'] = True
|
||||
return
|
||||
config.data = data
|
||||
config.save()
|
||||
return '/configs/?stage=' + config.stage
|
||||
update_config(self.request.POST['config'], data)
|
||||
# config.data = data
|
||||
# config.save()
|
||||
return '/configs/?stage=' + self.stage
|
||||
|
||||
|
||||
def get_config(request):
|
||||
|
@ -28,7 +28,7 @@
|
||||
</div>
|
||||
{% if error %}
|
||||
<div class="alert alert-danger" role="alert">
|
||||
Конфиг {{ incorrect_config.name }} не имеет вид JSON!
|
||||
Конфиг не имеет вид JSON!
|
||||
</div>
|
||||
{% endif %}
|
||||
<table class="table">
|
||||
@ -52,7 +52,7 @@
|
||||
<button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
|
||||
</div>
|
||||
<div class="modal-body">
|
||||
<textarea style="width: 100%; height: 800px;{% if config.id == incorrect_config.id %}border: 1px solid #f00;{% endif %}" name="data">{% if config.id == incorrect_config.id %}{{ incorrect_data }}{% else %}{{ config.data_pretty }}{% endif %}</textarea>
|
||||
<textarea style="width: 100%; height: 800px;{% if config.id == incorrect_config %}border: 1px solid #f00;{% endif %}" name="data">{% if config.id == incorrect_config.id %}{{ incorrect_data }}{% else %}{{ config.data_pretty }}{% endif %}</textarea>
|
||||
</div>
|
||||
<div class="modal-footer">
|
||||
<button type="submit" name="action" value="save" class="btn btn-secondary">Сохранить</button>
|
||||
|
Loading…
Reference in New Issue
Block a user