From c6388b04b2c32d49f7f261d7d0091c5d2c92e088 Mon Sep 17 00:00:00 2001 From: emmatveev Date: Fri, 11 Oct 2024 16:28:40 +0300 Subject: [PATCH 1/9] Update .deploy/deploy-prod.yaml --- .deploy/deploy-prod.yaml | 2 -- 1 file changed, 2 deletions(-) diff --git a/.deploy/deploy-prod.yaml b/.deploy/deploy-prod.yaml index 7dddbcb..edeb484 100644 --- a/.deploy/deploy-prod.yaml +++ b/.deploy/deploy-prod.yaml @@ -18,7 +18,6 @@ services: RABBITMQ_PASSWORD: $RABBITMQ_PASSWORD_PROD VK_SERVICE_TOKEN: $VK_SERVICE_TOKEN YANDEX_SERVICE_TOKEN: $YANDEX_SERVICE_TOKEN - TELEGRAM_TOKEN: $TELEGRAM_TOKEN PLATFORM_SECURITY_TOKEN: $PLATFORM_SECURITY_TOKEN command: runserver 0.0.0.0:1238 healthcheck: @@ -69,7 +68,6 @@ services: DB_PASSWORD: $DB_PASSWORD_PROD MINIO_HOST: "minio.sprinthub.ru" MINIO_SECRET_KEY: $MINIO _SECRET_KEY_PROD - TELEGRAM_TOKEN: $TELEGRAM_TOKEN command: migrate deploy: mode: replicated -- 2.49.1 From ed33722449c6c4e41c0e5a514f6c65cfa050f871 Mon Sep 17 00:00:00 2001 From: emmatveev Date: Wed, 27 Nov 2024 02:26:44 +0300 Subject: [PATCH 2/9] fix --- .deploy/deploy-prod.yaml | 4 ---- 1 file changed, 4 deletions(-) diff --git a/.deploy/deploy-prod.yaml b/.deploy/deploy-prod.yaml index 6b5df94..2ef6689 100644 --- a/.deploy/deploy-prod.yaml +++ b/.deploy/deploy-prod.yaml @@ -31,10 +31,6 @@ services: mode: replicated restart_policy: condition: any - placement: - constraints: - - node.role == worker - - node.labels.zone == ru update_config: parallelism: 1 order: start-first -- 2.49.1 From 7238b50ee6854e60ae49a357deeafe84acba56cc Mon Sep 17 00:00:00 2001 From: emmatveev Date: Mon, 2 Dec 2024 15:13:32 +0300 Subject: [PATCH 3/9] Update stats/management/commands/fetch_stats.py --- stats/management/commands/fetch_stats.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/stats/management/commands/fetch_stats.py b/stats/management/commands/fetch_stats.py index ab9801d..9e4a108 100644 --- a/stats/management/commands/fetch_stats.py +++ b/stats/management/commands/fetch_stats.py @@ -24,6 +24,8 @@ class Command(BaseCommand): if response.status_code != 200: continue Snapshot.objects.create(project=project, data=response.json()) + if not project.stats_cron: + continue cron = croniter.croniter(project.stats_cron, timezone.now()) next_date = cron.get_next(datetime.datetime) project.next_stats_fetch_time = next_date -- 2.49.1 From 8fb349d74bb3721a74d14018bc83b1f4cbb716ac Mon Sep 17 00:00:00 2001 From: emmatveev Date: Sun, 8 Dec 2024 15:16:43 +0300 Subject: [PATCH 4/9] fix --- Platform/settings.py | 3 +- Platform/urls.py | 1 + schemas/__init__.py | 0 schemas/admin.py | 6 ++ schemas/apps.py | 6 ++ schemas/migrations/0001_initial.py | 28 +++++++++ schemas/migrations/0002_alter_schema_data.py | 18 ++++++ schemas/migrations/0003_alter_schema_data.py | 18 ++++++ schemas/migrations/__init__.py | 0 schemas/models.py | 14 +++++ schemas/tests.py | 3 + schemas/urls.py | 9 +++ schemas/views.py | 46 ++++++++++++++ templates/includes/sidebar.html | 8 +++ templates/schemas.html | 61 +++++++++++++++++++ ..._project_next_stats_fetch_time_and_more.py | 28 +++++++++ web/models/project.py | 6 +- 17 files changed, 251 insertions(+), 4 deletions(-) create mode 100644 schemas/__init__.py create mode 100644 schemas/admin.py create mode 100644 schemas/apps.py create mode 100644 schemas/migrations/0001_initial.py create mode 100644 schemas/migrations/0002_alter_schema_data.py create mode 100644 schemas/migrations/0003_alter_schema_data.py create mode 100644 schemas/migrations/__init__.py create mode 100644 schemas/models.py create mode 100644 schemas/tests.py create mode 100644 schemas/urls.py create mode 100644 schemas/views.py create mode 100644 templates/schemas.html create mode 100644 web/migrations/0008_alter_project_next_stats_fetch_time_and_more.py diff --git a/Platform/settings.py b/Platform/settings.py index d2ed674..954b998 100644 --- a/Platform/settings.py +++ b/Platform/settings.py @@ -48,7 +48,8 @@ INSTALLED_APPS = [ 'web.apps.WebConfig', 'configs.apps.ConfigsConfig', 'experiments.apps.ExperimentsConfig', - 'stats.apps.StatsConfig' + 'stats.apps.StatsConfig', + 'schemas.apps.SchemasConfig', ] MIDDLEWARE = [ diff --git a/Platform/urls.py b/Platform/urls.py index 36f9857..01f40ff 100644 --- a/Platform/urls.py +++ b/Platform/urls.py @@ -21,5 +21,6 @@ urlpatterns = [ path('configs/', include('configs.urls')), path('experiments/', include('experiments.urls')), path('stats/', include('stats.urls')), + path('schemas/', include('schemas.urls')), path('', include('web.urls')) ] diff --git a/schemas/__init__.py b/schemas/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/schemas/admin.py b/schemas/admin.py new file mode 100644 index 0000000..b4dfc3f --- /dev/null +++ b/schemas/admin.py @@ -0,0 +1,6 @@ +from django.contrib import admin + +# Register your models here. +from .models import Schema + +admin.site.register(Schema) \ No newline at end of file diff --git a/schemas/apps.py b/schemas/apps.py new file mode 100644 index 0000000..6abc083 --- /dev/null +++ b/schemas/apps.py @@ -0,0 +1,6 @@ +from django.apps import AppConfig + + +class SchemasConfig(AppConfig): + default_auto_field = 'django.db.models.BigAutoField' + name = 'schemas' diff --git a/schemas/migrations/0001_initial.py b/schemas/migrations/0001_initial.py new file mode 100644 index 0000000..760060d --- /dev/null +++ b/schemas/migrations/0001_initial.py @@ -0,0 +1,28 @@ +# Generated by Django 5.1.4 on 2024-12-08 11:56 + +import django.db.models.deletion +from django.db import migrations, models + + +class Migration(migrations.Migration): + + initial = True + + dependencies = [ + ('web', '0007_customuser_telegram_id_customuser_telegram_username'), + ] + + operations = [ + migrations.CreateModel( + name='Schema', + fields=[ + ('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), + ('name', models.TextField()), + ('data', models.BinaryField(blank=True, null=True)), + ('project', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='web.project')), + ], + options={ + 'indexes': [models.Index(fields=['project'], name='schemas_sch_project_18fee8_idx')], + }, + ), + ] diff --git a/schemas/migrations/0002_alter_schema_data.py b/schemas/migrations/0002_alter_schema_data.py new file mode 100644 index 0000000..a1ffac2 --- /dev/null +++ b/schemas/migrations/0002_alter_schema_data.py @@ -0,0 +1,18 @@ +# Generated by Django 5.1.4 on 2024-12-08 12:05 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('schemas', '0001_initial'), + ] + + operations = [ + migrations.AlterField( + model_name='schema', + name='data', + field=models.TextField(blank=True, null=True), + ), + ] diff --git a/schemas/migrations/0003_alter_schema_data.py b/schemas/migrations/0003_alter_schema_data.py new file mode 100644 index 0000000..e8c8da3 --- /dev/null +++ b/schemas/migrations/0003_alter_schema_data.py @@ -0,0 +1,18 @@ +# Generated by Django 5.1.4 on 2024-12-08 12:15 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('schemas', '0002_alter_schema_data'), + ] + + operations = [ + migrations.AlterField( + model_name='schema', + name='data', + field=models.TextField(blank=True, default=''), + ), + ] diff --git a/schemas/migrations/__init__.py b/schemas/migrations/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/schemas/models.py b/schemas/models.py new file mode 100644 index 0000000..fbb4e3b --- /dev/null +++ b/schemas/models.py @@ -0,0 +1,14 @@ +from django.db import models + +# Create your models here. + + +class Schema(models.Model): + project = models.ForeignKey('web.Project', on_delete=models.CASCADE) + name = models.TextField() + data = models.TextField(default='', blank=True) + + class Meta: + indexes = [ + models.Index(fields=['project']) + ] diff --git a/schemas/tests.py b/schemas/tests.py new file mode 100644 index 0000000..7ce503c --- /dev/null +++ b/schemas/tests.py @@ -0,0 +1,3 @@ +from django.test import TestCase + +# Create your tests here. diff --git a/schemas/urls.py b/schemas/urls.py new file mode 100644 index 0000000..1526e59 --- /dev/null +++ b/schemas/urls.py @@ -0,0 +1,9 @@ +from django.contrib import admin +from django.urls import path + +from .views import * + +urlpatterns = [ + path(*SchemasView.as_path()), + path('get', get_schemas) +] diff --git a/schemas/views.py b/schemas/views.py new file mode 100644 index 0000000..1218d8b --- /dev/null +++ b/schemas/views.py @@ -0,0 +1,46 @@ +from json import loads + +from django.http import HttpResponse, JsonResponse + +from BaseLib.BaseView import BaseView +from BaseLib.configurator import * +from Platform import settings +from schemas.models import Schema + + +# Create your views here. + + +class SchemasView(BaseView): + required_login = True + endpoint = '' + view_file = 'schemas.html' + + def pre_handle(self): + self.context['schemas'] = Schema.objects.filter(project=self.request.user.selected_project) + + def post_create_schema(self): + Schema.objects.create(project=self.request.user.selected_project, name=self.request.POST['name']) + return '/schemas' + + def post_delete(self): + Schema.objects.get(id=self.request.POST['schema']).delete() + return '/schemas' + + + def post_save(self): + schema = Schema.objects.get(id=self.request.POST['schema']) + schema.data = self.request.POST['data'] + schema.save() + return '/schemas' + + +def get_schemas(request): + project = request.GET.get('project') + if project is None: + return HttpResponse('', status=400) + data = { + schema.name: schema.data + for schema in Schema.objects.filter(project__name=project) + } + return JsonResponse(data, safe=False) diff --git a/templates/includes/sidebar.html b/templates/includes/sidebar.html index 5690a48..575958e 100644 --- a/templates/includes/sidebar.html +++ b/templates/includes/sidebar.html @@ -98,6 +98,14 @@ Статистика +