Commit ab5e47b8 authored by apeshkov's avatar apeshkov

[BACK][VLN][master] add task template

parent 94c85d8a
...@@ -58,7 +58,8 @@ INSTALLED_APPS = [ ...@@ -58,7 +58,8 @@ INSTALLED_APPS = [
"django_cron", "django_cron",
"corsheaders", "corsheaders",
"mptt", "mptt",
"tenants.apps.TenantsConfig", "tenants",
"task_templates",
"users.apps.UsersConfig", # users should be last in this list, or permission update may fail "users.apps.UsersConfig", # users should be last in this list, or permission update may fail
] ]
......
...@@ -18,6 +18,7 @@ from django.contrib.auth import views as auth_views ...@@ -18,6 +18,7 @@ from django.contrib.auth import views as auth_views
from django.urls import include, path from django.urls import include, path
from main.auth.views import TokenObtainPairViewEx, TokenRefreshViewEx, TokenVerifyViewEx from main.auth.views import TokenObtainPairViewEx, TokenRefreshViewEx, TokenVerifyViewEx
from main.core.routers import VLNNestedRouter, VLNRouter from main.core.routers import VLNNestedRouter, VLNRouter
from task_templates.views import TenantTaskTemplateViewSet
from tenants.views import TenantViewSet from tenants.views import TenantViewSet
from users.views import TenantUsersViewSet, UserViewSet from users.views import TenantUsersViewSet, UserViewSet
...@@ -28,6 +29,7 @@ router.register("tenants", TenantViewSet, basename="tenants") ...@@ -28,6 +29,7 @@ router.register("tenants", TenantViewSet, basename="tenants")
# tenant sub-views # tenant sub-views
tenants_router = VLNNestedRouter(router, "tenants", lookup="tenant") tenants_router = VLNNestedRouter(router, "tenants", lookup="tenant")
tenants_router.register("users", TenantUsersViewSet, basename="users") tenants_router.register("users", TenantUsersViewSet, basename="users")
tenants_router.register("task-templates", TenantTaskTemplateViewSet, basename="task-templates")
api_routes = [ api_routes = [
path("", include(router.urls)), path("", include(router.urls)),
......
from django.contrib import admin
from task_templates.models import TaskTemplate
class TaskTemplateAdmin(admin.ModelAdmin):
search_fields = ["name"]
admin.site.register(TaskTemplate, TaskTemplateAdmin)
from django.apps import AppConfig
class TaskTemplateConfig(AppConfig):
name = "task_templates"
verbose_name = "Task template"
from django.db.models import TextChoices
class TaskTemplateType(TextChoices):
TEXT = ("TEXT", "Text")
VOICE = ("VOICE", "Voice")
MISSING_CALL = ("MISSING_CALL", "Missing_call")
from django_filters.rest_framework import FilterSet
class TaskTemplateFilter(FilterSet):
pass
# Generated by Django 3.1.7 on 2021-03-19 17:49
import uuid
import django.core.serializers.json
import django.db.models.deletion
import task_templates.models
from django.db import migrations, models
class Migration(migrations.Migration):
initial = True
dependencies = [
("tenants", "0001_initial"),
]
operations = [
migrations.CreateModel(
name="TaskTemplate",
fields=[
("id", models.UUIDField(default=uuid.uuid4, editable=False, primary_key=True, serialize=False)),
("name", models.CharField(max_length=254, verbose_name="Name")),
(
"meta_info",
models.JSONField(
default=task_templates.models.get_default_task_template_meta,
encoder=django.core.serializers.json.DjangoJSONEncoder,
),
),
(
"type",
models.CharField(
choices=[("TEXT", "Text"), ("VOICE", "Voice"), ("MISSING_CALL", "Missing_call")],
default="VOICE",
max_length=32,
verbose_name="Type",
),
),
(
"tenant",
models.ForeignKey(
on_delete=django.db.models.deletion.CASCADE, related_name="task_templates", to="tenants.tenant"
),
),
],
options={
"abstract": False,
},
),
]
from django.core.serializers.json import DjangoJSONEncoder
from django.db import models
from main.core.models import UUIDIDMixin
from task_templates.constants import TaskTemplateType
def get_default_task_template_meta():
return {}
class TaskTemplate(UUIDIDMixin):
name = models.CharField("Name", max_length=254)
meta_info = models.JSONField(default=get_default_task_template_meta, encoder=DjangoJSONEncoder)
type = models.CharField("Type", max_length=32, choices=TaskTemplateType.choices, default=TaskTemplateType.VOICE)
tenant = models.ForeignKey("tenants.Tenant", related_name="task_templates", on_delete=models.CASCADE)
def __str__(self):
return f"{self.name}"
from main.core.serializers import NestedRouterForeignKeyDeserializerMixin
from rest_framework import serializers
from task_templates.models import TaskTemplate
class TaskTemplateSerializer(serializers.ModelSerializer):
class Meta:
model = TaskTemplate
fields = "__all__"
class TenantTaskTemplateSerializer(NestedRouterForeignKeyDeserializerMixin, TaskTemplateSerializer):
router_lookups = ("tenant",)
from main.core.permissions import VLNModelPermissions
from main.core.views import VLNModelViewSet
from task_templates.filters import TaskTemplateFilter
from task_templates.models import TaskTemplate
from task_templates.serializers import (
TaskTemplateSerializer,
TenantTaskTemplateSerializer,
)
class TaskTemplateViewSet(VLNModelViewSet):
permission_classes = (VLNModelPermissions,)
serializer_class = TaskTemplateSerializer
filterset_class = TaskTemplateFilter
queryset = TaskTemplate.objects.all()
ordering = ["-id"]
class TenantTaskTemplateViewSet(VLNModelViewSet):
serializer_class = TenantTaskTemplateSerializer
pagination_class = None
...@@ -37,7 +37,7 @@ ipython = "^7.21.0" ...@@ -37,7 +37,7 @@ ipython = "^7.21.0"
[tool.black] [tool.black]
line-length = 120 line-length = 120
include = '\.pyi?$' include = '\.pyi?$'
exclude = '/( \.git | \.venv | docs | static )/' exclude = '/( \.git | \.venv | docs | static | migrations )/'
[tool.isort] [tool.isort]
profile = "black" profile = "black"
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment