Commit 49912831 authored by apeshkov's avatar apeshkov

[BACK][VLN][master] fix, add task model, add tag model

parent 12691509
# Generated by Django 3.1.7 on 2021-03-19 18:27
# Generated by Django 3.1.7 on 2021-03-19 19:57
import uuid
......@@ -13,8 +13,8 @@ class Migration(migrations.Migration):
initial = True
dependencies = [
("tenants", "0001_initial"),
migrations.swappable_dependency(settings.AUTH_USER_MODEL),
("tenants", "0001_initial"),
]
operations = [
......@@ -37,16 +37,6 @@ class Migration(migrations.Migration):
size=None,
),
),
("phone_primary", models.CharField(max_length=16, verbose_name="Primary phone")),
(
"phone_extra",
django.contrib.postgres.fields.ArrayField(
base_field=models.CharField(max_length=16, verbose_name="Phone"),
blank=True,
null=True,
size=None,
),
),
(
"created_by",
models.ForeignKey(
......@@ -77,7 +67,9 @@ class Migration(migrations.Migration):
),
],
options={
"abstract": False,
"verbose_name": "Client",
"verbose_name_plural": "Clients",
"db_table": "clients",
},
),
]
......@@ -9,9 +9,13 @@ class Client(UUIDIDMixin, BaseAuditTrack):
position = models.CharField("Position", max_length=254, null=True, blank=True)
site = models.CharField("Site", max_length=254, null=True, blank=True)
email = ArrayField(models.EmailField("Email"), null=True, blank=True)
phone_primary = models.CharField("Primary phone", max_length=16)
phone_extra = ArrayField(models.CharField("Phone", max_length=16), null=True, blank=True)
tenant = models.ForeignKey("tenants.Tenant", related_name="clients", on_delete=models.CASCADE)
class Meta:
app_label = "clients"
db_table = "clients"
verbose_name = "Client"
verbose_name_plural = "Clients"
def __str__(self):
return f"{self.name}"
......@@ -59,7 +59,9 @@ INSTALLED_APPS = [
"corsheaders",
"mptt",
"tenants.apps.TenantsConfig",
"tags.apps.TagConfig",
"task_templates.apps.TaskTemplateConfig",
"tasks.apps.TasksConfig",
"clients.apps.ClientsConfig",
"users.apps.UsersConfig", # users should be last in this list, or permission update may fail
]
......
......@@ -19,19 +19,23 @@ from django.contrib.auth import views as auth_views
from django.urls import include, path
from main.auth.views import TokenObtainPairViewEx, TokenRefreshViewEx, TokenVerifyViewEx
from main.core.routers import VLNNestedRouter, VLNRouter
from tags.views import TenantTagViewSet
from task_templates.views import TenantTaskTemplateViewSet
from tasks.views import TaskViewSet
from tenants.views import TenantViewSet
from users.views import TenantUsersViewSet, UserViewSet
router = VLNRouter()
router.register("users", UserViewSet, basename="users")
router.register("tenants", TenantViewSet, basename="tenants")
router.register("tasks", TaskViewSet, basename="tasks")
# tenant sub-views
tenants_router = VLNNestedRouter(router, "tenants", lookup="tenant")
tenants_router.register("users", TenantUsersViewSet, basename="users")
tenants_router.register("task-templates", TenantTaskTemplateViewSet, basename="task-templates")
tenants_router.register("clients", TenantClientViewSet, basename="clients")
tenants_router.register("tags", TenantTagViewSet, basename="tags")
api_routes = [
path("", include(router.urls)),
......
from django.contrib import admin
from tags.models import Tag
class TagAdmin(admin.ModelAdmin):
search_fields = ["name"]
admin.site.register(Tag, TagAdmin)
from django.apps import AppConfig
class TagConfig(AppConfig):
name = "tags"
verbose_name = "Tags"
from django.db.models import TextChoices
class TagType(TextChoices):
CLIENT = ("CLIENT", "Client")
DID = ("DID", "DID")
CALL = ("CALL", "Call")
from django_filters.rest_framework import FilterSet
class TagFilter(FilterSet):
pass
# Generated by Django 3.1.7 on 2021-03-19 17:49
# Generated by Django 3.1.7 on 2021-03-19 19:57
import uuid
import django.core.serializers.json
import django.db.models.deletion
import task_templates.models
from django.db import migrations, models
......@@ -18,22 +16,16 @@ class Migration(migrations.Migration):
operations = [
migrations.CreateModel(
name="TaskTemplate",
name="Tag",
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,
),
),
("comment", models.CharField(blank=True, max_length=254, null=True, verbose_name="Company")),
(
"type",
models.CharField(
choices=[("TEXT", "Text"), ("VOICE", "Voice"), ("MISSING_CALL", "Missing_call")],
default="VOICE",
choices=[("CLIENT", "Client"), ("DID", "DID"), ("CALL", "Call")],
default="CLIENT",
max_length=32,
verbose_name="Type",
),
......@@ -41,12 +33,14 @@ class Migration(migrations.Migration):
(
"tenant",
models.ForeignKey(
on_delete=django.db.models.deletion.CASCADE, related_name="task_templates", to="tenants.tenant"
on_delete=django.db.models.deletion.CASCADE, related_name="tags", to="tenants.tenant"
),
),
],
options={
"abstract": False,
"verbose_name": "Tag",
"verbose_name_plural": "Tags",
"db_table": "tags",
},
),
]
from django.db import models
from main.core.models import UUIDIDMixin
from tags.constants import TagType
class Tag(UUIDIDMixin):
name = models.CharField("Name", max_length=254)
comment = models.CharField("Company", max_length=254, null=True, blank=True)
type = models.CharField("Type", max_length=32, choices=TagType.choices, default=TagType.CLIENT)
tenant = models.ForeignKey("tenants.Tenant", related_name="tags", on_delete=models.CASCADE)
class Meta:
app_label = "tags"
db_table = "tags"
verbose_name = "Tag"
verbose_name_plural = "Tags"
def __str__(self):
return f"{self.name}"
from main.core.serializers import NestedRouterForeignKeyDeserializerMixin
from rest_framework import serializers
from tags.models import Tag
class TagSerializer(serializers.ModelSerializer):
class Meta:
model = Tag
fields = "__all__"
class TenantTagSerializer(NestedRouterForeignKeyDeserializerMixin, TagSerializer):
router_lookups = ("tenant",)
from main.core.permissions import VLNModelPermissions
from main.core.views import VLNModelViewSet
from tags.filters import TagFilter
from tags.models import Tag
from tags.serializers import TagSerializer, TenantTagSerializer
class TagViewSet(VLNModelViewSet):
permission_classes = (VLNModelPermissions,)
serializer_class = TagSerializer
filterset_class = TagFilter
queryset = Tag.objects.all()
ordering = ["-id"]
class TenantTagViewSet(VLNModelViewSet):
serializer_class = TenantTagSerializer
pagination_class = None
......@@ -4,4 +4,4 @@ from django.db.models import TextChoices
class TaskTemplateType(TextChoices):
TEXT = ("TEXT", "Text")
VOICE = ("VOICE", "Voice")
MISSING_CALL = ("MISSING_CALL", "Missing_call")
MISSING_CALL = ("MISSING_CALL", "Missing call")
......@@ -15,5 +15,11 @@ class TaskTemplate(UUIDIDMixin):
tenant = models.ForeignKey("tenants.Tenant", related_name="task_templates", on_delete=models.CASCADE)
class Meta:
app_label = "tasks"
db_table = "task_templates"
verbose_name = "Task template"
verbose_name_plural = "Task templates"
def __str__(self):
return f"{self.name}"
from django.contrib import admin
from tasks.models import Task
class TaskAdmin(admin.ModelAdmin):
search_fields = ["name"]
admin.site.register(Task, TaskAdmin)
from django.apps import AppConfig
class TasksConfig(AppConfig):
name = "tasks"
verbose_name = "Tasks"
from django.db.models import TextChoices
class TaskType(TextChoices):
TEXT = ("TEXT", "Text")
VOICE = ("VOICE", "Voice")
MISSING_CALL = ("MISSING_CALL", "Missing call")
class TaskStatus(TextChoices):
NEW = ("NEW", "New")
IN_PROCESS = ("IN_PROCESS", "In process")
DONE = ("DONE", "Done")
CLOSED = ("CLOSED", "Closed")
from django_filters.rest_framework import FilterSet
class TaskFilter(FilterSet):
pass
# Generated by Django 3.1.7 on 2021-03-19 20:00
import uuid
import django.core.serializers.json
import django.db.models.deletion
import task_templates.models
import tasks.models
from django.conf import settings
from django.db import migrations, models
class Migration(migrations.Migration):
initial = True
dependencies = [
migrations.swappable_dependency(settings.AUTH_USER_MODEL),
("tenants", "0001_initial"),
("clients", "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={
"verbose_name": "Task template",
"verbose_name_plural": "Task templates",
"db_table": "task_templates",
},
),
migrations.CreateModel(
name="Task",
fields=[
("id", models.UUIDField(default=uuid.uuid4, editable=False, primary_key=True, serialize=False)),
("updated_at", models.DateTimeField(auto_now=True, null=True, verbose_name="Updated at")),
("created_at", models.DateTimeField(auto_now_add=True, null=True, verbose_name="Created at")),
(
"type",
models.CharField(
choices=[("TEXT", "Text"), ("VOICE", "Voice"), ("MISSING_CALL", "Missing call")],
default="VOICE",
max_length=32,
verbose_name="Type",
),
),
(
"status",
models.CharField(
choices=[("NEW", "New"), ("IN_PROCESS", "In process"), ("DONE", "Done"), ("CLOSED", "Closed")],
default="NEW",
max_length=32,
verbose_name="Status",
),
),
("recording_id", models.UUIDField(default=uuid.uuid4, editable=False, verbose_name="Record id")),
(
"meta_info",
models.JSONField(
default=tasks.models.get_default_task_meta,
encoder=django.core.serializers.json.DjangoJSONEncoder,
),
),
(
"assignee",
models.ForeignKey(
on_delete=django.db.models.deletion.CASCADE, related_name="tasks", to=settings.AUTH_USER_MODEL
),
),
(
"client",
models.ForeignKey(
on_delete=django.db.models.deletion.CASCADE, related_name="tasks", to="clients.client"
),
),
(
"created_by",
models.ForeignKey(
editable=False,
null=True,
on_delete=django.db.models.deletion.PROTECT,
related_name="tasks_created_task_set",
to=settings.AUTH_USER_MODEL,
verbose_name="Created by",
),
),
(
"task_template",
models.ForeignKey(
on_delete=django.db.models.deletion.CASCADE, related_name="tasks", to="tasks.tasktemplate"
),
),
(
"updated_by",
models.ForeignKey(
editable=False,
null=True,
on_delete=django.db.models.deletion.PROTECT,
related_name="tasks_updated_task_set",
to=settings.AUTH_USER_MODEL,
verbose_name="Updated by",
),
),
],
options={
"verbose_name": "Task",
"verbose_name_plural": "Task",
"db_table": "tasks",
},
),
]
import uuid
from django.conf import settings
from django.core.serializers.json import DjangoJSONEncoder
from django.db import models
from main.core.models import BaseAuditTrack, UUIDIDMixin
from tasks.constants import TaskStatus, TaskType
def get_default_task_meta():
return {}
class Task(UUIDIDMixin, BaseAuditTrack):
type = models.CharField("Type", max_length=32, choices=TaskType.choices, default=TaskType.VOICE)
status = models.CharField("Status", max_length=32, choices=TaskStatus.choices, default=TaskStatus.NEW)
recording_id = models.UUIDField("Record id", default=uuid.uuid4, editable=False)
meta_info = models.JSONField(default=get_default_task_meta, encoder=DjangoJSONEncoder)
task_template = models.ForeignKey("tasks.TaskTemplate", related_name="tasks", on_delete=models.CASCADE)
client = models.ForeignKey("clients.Client", related_name="tasks", on_delete=models.CASCADE)
assignee = models.ForeignKey(settings.AUTH_USER_MODEL, related_name="tasks", on_delete=models.CASCADE)
class Meta:
app_label = "tasks"
db_table = "tasks"
verbose_name = "Task"
verbose_name_plural = "Task"
def __str__(self):
return f"{self.name}"
from rest_framework import serializers
from tasks.models import Task
class TaskSerializer(serializers.ModelSerializer):
class Meta:
model = Task
fields = "__all__"
from main.core.permissions import VLNModelPermissions
from main.core.views import VLNModelViewSet
from tasks.filters import TaskFilter
from tasks.models import Task
from tasks.serializers import TaskSerializer
class TaskViewSet(VLNModelViewSet):
permission_classes = (VLNModelPermissions,)
serializer_class = TaskSerializer
filterset_class = TaskFilter
queryset = Task.objects.all()
ordering = ["-id"]
# Generated by Django 3.1.7 on 2021-03-19 15:10
# Generated by Django 3.1.7 on 2021-03-19 19:57
import uuid
......@@ -30,7 +30,9 @@ class Migration(migrations.Migration):
),
],
options={
"abstract": False,
"verbose_name": "Tenant",
"verbose_name_plural": "Tenants",
"db_table": "tenants",
},
),
]
......@@ -9,5 +9,11 @@ class Tenant(UUIDIDMixin):
country = models.CharField("Country", max_length=254)
state = models.CharField("State", max_length=32, choices=TenantState.choices, default=TenantState.ACTIVE)
class Meta:
app_label = "tenants"
db_table = "tenants"
verbose_name = "Tenant"
verbose_name_plural = "Tenants"
def __str__(self):
return f"{self.name}"
# Generated by Django 3.1.7 on 2021-03-19 15:10
# Generated by Django 3.1.7 on 2021-03-19 19:57
import django.db.models.deletion
from django.db import migrations, models
......
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