Advertisement
Mochinov

Untitled

May 23rd, 2022
286
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.29 KB | None | 0 0
  1. from typing import Optional, Union
  2.  
  3. from django.contrib.auth.decorators import login_required
  4. from django.contrib.auth.models import User
  5. from django.db.models import QuerySet
  6. from django.http import HttpRequest
  7. from django.utils.decorators import method_decorator
  8. from rest_framework import permissions
  9. from rest_framework.decorators import permission_classes
  10. from rest_framework.request import Request
  11. from rest_framework.response import Response
  12.  
  13.  
  14. from misc.views.generic_api_single_view import GenericApiSingleView
  15. from misc.views.generic_api_view import GenericApiView
  16. from misc.views.generic_filters import GenericFilters
  17. from misc.views.generic_responces import get_status_response
  18. from misc.views.table_style import TableStyle
  19. from crm_softphone.models import TrunkLVProject
  20.  
  21.  
  22. @permission_classes((permissions.AllowAny,))
  23. class TrunkLVProjectTableView(GenericApiView):
  24. """Определяет структуру и содержание ответа на запросы к данным таблицы LVProject."""
  25.  
  26. table_name = 'TrunkLVProject'
  27. table_style = TableStyle.get_table_style(hide_multiple_table_add=True)
  28.  
  29. class Filters(GenericFilters):
  30. pass
  31.  
  32. FIELDS_FILTERS = [
  33. ]
  34.  
  35. PERMISSIONS = {
  36. 'create': 'partners.crm_partners_lvproject_add',
  37. 'view': 'partners.crm_partners_lvproject_view',
  38. # 'edit': 'partners.crm_partners_lvproject_edit',
  39. 'delete': 'partners.crm_partners_lvproject_delete',
  40. }
  41.  
  42. @classmethod
  43. def get_field_dict(cls, context: dict, user: User) -> dict:
  44. """Распаковывает ответ и возвращает словарь со значениями полей"""
  45.  
  46. data = {
  47. 'name': cls.get_unpack_value(context.get('name_field')) or '',
  48. 'api_domain': cls.get_unpack_value(context.get('api_domain_field')) or '',
  49. 'api_key': cls.get_unpack_value(context.get('api_key_field')) or '',
  50. 'is_active': cls.get_unpack_value(context.get('is_active_field')),
  51.  
  52. # Пользователь отправивший запрос
  53. 'user': user,
  54. }
  55.  
  56. return data
  57.  
  58. def get_queryset(self, context: dict, user: User) -> QuerySet:
  59. """Возвращает базовый (до фильтрации и пагинации) QuerySet для таблицы."""
  60.  
  61.  
  62. return TrunkLVProject.objects.all().select_related('lv_project')
  63.  
  64.  
  65. @permission_classes((permissions.AllowAny,))
  66. class TrunkLVProjectElementView(GenericApiSingleView):
  67. """Определяет структуру и содержание ответа на запросы к данным элемента LVProject."""
  68.  
  69. table_name = 'TrunkLVProject'
  70. element_verbose = 'Проект LV'
  71. table_view_model = TrunkLVProjectTableView
  72.  
  73. PERMISSIONS = {
  74. 'create': 'partners.crm_partners_lvproject_add',
  75. 'view': 'partners.crm_partners_lvproject_view',
  76. 'edit': 'partners.crm_partners_lvproject_edit',
  77. 'delete': 'partners.crm_partners_lvproject_delete',
  78. }
  79.  
  80. def get_queryset(self, context: dict, user: User) -> QuerySet:
  81. """Возвращает базовый (до фильтрации и пагинации) QuerySet."""
  82.  
  83. return TrunkLVProject.objects.all()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement