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.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 TrunkLVProject
- @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 = [
- ]
- 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',
- }
- @classmethod
- def get_field_dict(cls, context: dict, user: User) -> dict:
- """Распаковывает ответ и возвращает словарь со значениями полей"""
- data = {
- 'name': cls.get_unpack_value(context.get('name_field')) or '',
- 'api_domain': cls.get_unpack_value(context.get('api_domain_field')) or '',
- 'api_key': cls.get_unpack_value(context.get('api_key_field')) or '',
- 'is_active': cls.get_unpack_value(context.get('is_active_field')),
- # Пользователь отправивший запрос
- 'user': user,
- }
- 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