Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from typing import Optional, Union
- from django.contrib.auth.decorators import login_required
- from django.contrib.auth.models import User
- from django.db.models import QuerySet
- from django.http import HttpRequest
- from django.utils.decorators import method_decorator
- from rest_framework import permissions
- from rest_framework.decorators import permission_classes
- from rest_framework.request import Request
- from rest_framework.response import Response
- from misc.to_int import safe_to_int
- from misc.views.generic_api_single_view import GenericApiSingleView
- from misc.views.generic_api_view import GenericApiView
- from misc.views.generic_filters import GenericFilters
- from misc.views.generic_responces import get_status_response
- from misc.views.table_style import TableStyle
- from crm_softphone.models import Trunk, TrunkLVProject
- from partners.models import LVProject
- @permission_classes((permissions.AllowAny,))
- class TrunkLVProjectTableView(GenericApiView):
- """Определяет структуру и содержание ответа на запросы к данным таблицы LVProject."""
- table_name = 'TrunkLVProject'
- table_style = TableStyle.get_table_style(hide_multiple_table_add=True)
- class Filters(GenericFilters):
- pass
- FIELDS_FILTERS = [
- GenericApiView.get_filter(
- filter_name='id_field', field_name='id',
- filer_method=Filters.generic_int_equal_filter
- ),
- GenericApiView.get_filter(
- filter_name='trunks_field', field_name='trunks_id',
- filer_method=Filters.generic_int_equal_filter
- ),
- ]
- PERMISSIONS = {
- 'create': 'partners.crm_partners_lvproject_add',
- 'view': 'partners.crm_partners_lvproject_view',
- # 'edit': 'partners.crm_partners_lvproject_edit',
- 'delete': 'partners.crm_partners_lvproject_delete',
- }
- def get_empty_item_prefilled_fields(self, context: dict) -> dict:
- """Возвращает список предзаполненных полей для пустого элемента."""
- trunks_field = context.get('trunks_field')
- prefilled_fields = {
- 'trunks_field': trunks_field,
- }
- return prefilled_fields
- @classmethod
- def get_field_dict(cls, context: dict, user: User) -> dict:
- """Распаковывает ответ и возвращает словарь со значениями полей"""
- print(context)
- print(
- context.get('trunks_field'),
- context.get('lv_project_field'),
- TrunkLVProjectTableView.get_unpack_value(context.get('trunks_field')),
- TrunkLVProjectTableView.get_unpack_value(context.get('lv_project_field')),
- )
- trunks_id_field = TrunkLVProjectTableView.get_unpack_value(context.get('trunks_field'))
- trunks_id_field = safe_to_int(trunks_id_field, -1)
- trunks = Trunk.objects.filter(id=trunks_id_field).first()
- lv_project_id_field = TrunkLVProjectTableView.get_unpack_value(context.get('lv_project_field'))
- lv_project_id_field = safe_to_int(lv_project_id_field, -1)
- lv_project = LVProject.objects.filter(id=lv_project_id_field).first()
- data = {
- 'lv_project': lv_project,
- 'trunks': trunks
- }
- print(data)
- return data
- def get_queryset(self, context: dict, user: User) -> QuerySet:
- """Возвращает базовый (до фильтрации и пагинации) QuerySet для таблицы."""
- return TrunkLVProject.objects.all().select_related('lv_project')
- @permission_classes((permissions.AllowAny,))
- class TrunkLVProjectElementView(GenericApiSingleView):
- """Определяет структуру и содержание ответа на запросы к данным элемента LVProject."""
- table_name = 'TrunkLVProject'
- element_verbose = 'Проект LV'
- table_view_model = TrunkLVProjectTableView
- PERMISSIONS = {
- 'create': 'partners.crm_partners_lvproject_add',
- 'view': 'partners.crm_partners_lvproject_view',
- 'edit': 'partners.crm_partners_lvproject_edit',
- 'delete': 'partners.crm_partners_lvproject_delete',
- }
- def get_queryset(self, context: dict, user: User) -> QuerySet:
- """Возвращает базовый (до фильтрации и пагинации) QuerySet."""
- return TrunkLVProject.objects.all()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement