Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from django.urls import reverse
- from rest_framework import serializers
- from misc.views.generic_serializer import GenericSerializer, GenericSerializerField
- from users.models import SubmissionRequest
- class SubmissionRequestSerializer(GenericSerializer):
- """
- Отвечает за сериализацию данных модели SubmissionRequest (табличное представление), оправляемых в ответе на запрос.
- """
- readonly_field = [
- 'id_field',
- 'user_field',
- 'supervisor_field',
- 'comment_user_field',
- 'comment_field',
- 'status_field',
- 'access_field',
- 'property_field',
- 'name_request_field',
- 'comment_resource_field',
- 'resource_field',
- 'request_period_from_field',
- 'request_period_to_field',
- 'request_processed_field',
- 'request_period_from_field',
- 'request_period_to_field',
- 'request_processed_field',
- ]
- mandatory_fields = [
- 'id_field',
- 'user_field',
- 'supervisor_field',
- 'comment_user_field',
- 'comment_field',
- 'status_field',
- 'access_field',
- 'property_field',
- 'name_request_field',
- 'comment_resource_field',
- 'resource_field',
- 'request_period_from_field',
- 'request_period_to_field',
- 'request_processed_field',
- 'request_period_from_field',
- 'request_period_to_field',
- 'request_processed_field',
- ]
- create_field = []
- id_field = GenericSerializerField(
- model_field_name='id'
- )
- user_field = GenericSerializerField(
- model_field_name='user_id',
- model_field_verbose='user__get_full_name',
- field_verbose_is_method=True,
- )
- supervisor_field = GenericSerializerField(
- model_field_name='supervisor_id',
- model_field_verbose='supervisor__get_full_name',
- field_verbose_is_method=True,
- )
- request_period_from_field = GenericSerializerField(
- model_field_name='request_period_from',
- )
- request_period_to_field = GenericSerializerField(
- model_field_name='request_period_to',
- )
- request_processed_field = GenericSerializerField(
- model_field_name='request_processed',
- )
- comment_user_field = GenericSerializerField(
- model_field_name="comment_user"
- )
- comment_field = GenericSerializerField(
- model_field_name='comment'
- )
- status_field = GenericSerializerField(
- model_field_name='status'
- )
- access_field = GenericSerializerField(
- model_field_name="access_id",
- )
- property_field = GenericSerializerField(
- model_field_name="property_id",
- )
- name_request_field = GenericSerializerField(
- model_field_name='get_name_request',
- field_is_method=True,
- model_field_verbose='get_name_request',
- field_verbose_is_method=True,
- )
- comment_resource_field = GenericSerializerField(
- model_field_name='get_comment_resource',
- field_is_method=True,
- model_field_verbose='get_comment_resource',
- field_verbose_is_method=True,
- )
- resource_field = GenericSerializerField(
- model_field_name='get_resource',
- field_is_method=True,
- model_field_verbose='get_resource',
- field_verbose_is_method=True,
- )
- status_request_change_access_btn_field = serializers.SerializerMethodField()
- status_request_change_property_btn_field = serializers.SerializerMethodField()
- # delete_btn_field = serializers.SerializerMethodField()
- fields_information = {
- 'id_field': GenericSerializer.get_field_information(
- model_name='id',
- field_verbose='ID',
- ),
- 'user_field': GenericSerializer.get_field_information(
- model_name='user_id',
- field_verbose='Сотрудник запрашиваемый доступы или имущество',
- ),
- 'supervisor_field': GenericSerializer.get_field_information(
- model_name='supervisor_id',
- field_verbose='Руководитель',
- ),
- 'comment_user_field': GenericSerializer.get_field_information(
- model_name="comment_user",
- field_verbose='Комментарий сотрудника',
- ),
- 'comment_field': GenericSerializer.get_field_information(
- model_name='comment',
- field_verbose='Комментарий руководителя',
- ),
- 'status_field': GenericSerializer.get_field_information(
- model_name='status',
- field_verbose='Статус заявки',
- ),
- 'access_field': GenericSerializer.get_field_information(
- model_name="access__name",
- field_verbose='Название доступа',
- ),
- 'property_field': GenericSerializer.get_field_information(
- model_name="property__name",
- field_verbose="Название запроса",
- ),
- 'name_request_field': GenericSerializer.get_field_information(
- field_verbose="Название ресурса",
- ),
- 'comment_resource_field': GenericSerializer.get_field_information(
- field_verbose="Комментарий ресурса",
- ),
- 'resource_field': GenericSerializer.get_field_information(
- field_verbose="Ресурс",
- ),
- 'request_period_from_field': GenericSerializer.get_field_information(
- model_name='request_period_from',
- ),
- 'request_period_to_field': GenericSerializer.get_field_information(
- model_name='request_period_to',
- ),
- 'request_processed_field': GenericSerializer.get_field_information(
- model_name='request_processed',
- ),
- 'status_request_change_access_btn_field': GenericSerializer.get_field_information(),
- 'status_request_change_property_btn_field': GenericSerializer.get_field_information(),
- # 'delete_btn_field': GenericSerializer.get_field_information(),
- }
- class Meta:
- model = SubmissionRequest
- fields = [
- 'id_field',
- 'user_field',
- 'supervisor_field',
- 'comment_user_field',
- 'comment_field',
- 'status_field',
- 'access_field',
- 'property_field',
- 'name_request_field',
- 'comment_resource_field',
- 'resource_field',
- 'request_period_from_field',
- 'request_period_to_field',
- 'request_processed_field',
- 'request_period_from_field',
- 'request_period_to_field',
- 'request_processed_field',
- 'status_request_change_access_btn_field',
- 'status_request_change_property_btn_field'
- # 'delete_btn_field'
- ]
- def get_status_request_change_access_btn_field(self, obj) -> dict:
- """Определяет возвращаемое значение для поля кнопки перехода к событию."""
- url = reverse('submission_requests_access_retrieve', args=[obj.id])
- verbose = 'Принять заявку'
- return self.get_button_field(
- action=GenericSerializer.ButtonActions.REDIRECT,
- url=url,
- verbose=verbose
- )
- def get_status_request_change_property_btn_field(self, obj) -> dict:
- """Определяет возвращаемое значение для поля кнопки перехода к событию."""
- url = reverse('submission_requests_property_retrieve', args=[obj.id])
- verbose = 'Принять заявку'
- return self.get_button_field(
- action=GenericSerializer.ButtonActions.REDIRECT,
- url=url,
- verbose=verbose
- )
- def get_delete_btn_field(self, obj) -> dict:
- """Определяет возвращаемое значение для поля кнопки удаления."""
- pass
- # url = reverse('user_property_delete', args=[obj.id])
- # return self.get_button_field(
- # action=GenericSerializer.ButtonActions.DELETE,
- # url=url,
- # verbose='',
- # icon='CloseCircle',
- # )
- class SingleSubmissionRequestSerializer(GenericSerializer):
- create_field = [
- 'comment_user_field',
- 'access_field',
- 'property_field',
- 'request_period_from_field',
- 'request_period_to_field',
- ]
- readonly_field = [
- 'id_field',
- 'user_field',
- 'supervisor_field',
- 'comment_field',
- 'name_request_field',
- 'comment_resource_field',
- 'resource_field',
- 'request_processed_field',
- ]
- mandatory_fields = [
- 'id_field',
- ]
- id_field = GenericSerializerField(
- model_field_name='id'
- )
- user_field = GenericSerializerField(
- model_field_name='user_id',
- model_field_verbose='user__get_full_name',
- field_verbose_is_method=True,
- )
- supervisor_field = GenericSerializerField(
- model_field_name='supervisor_id',
- model_field_verbose='supervisor__get_full_name',
- field_verbose_is_method=True,
- )
- access_field = GenericSerializerField(
- model_field_name="access__name",
- )
- property_field = GenericSerializerField(
- model_field_name="property__name",
- )
- comment_user_field = GenericSerializerField(
- model_field_name="comment_user"
- )
- comment_field = GenericSerializerField(
- model_field_name='comment'
- )
- request_period_from_field = GenericSerializerField(
- model_field_name='request_period_from',
- )
- request_period_to_field = GenericSerializerField(
- model_field_name='request_period_to',
- )
- fields_information = {
- 'id_field': GenericSerializer.get_field_information(
- model_name='id',
- field_verbose='ID',
- ),
- 'comment_user_field': GenericSerializer.get_field_information(
- model_name="comment_user",
- field_verbose='Комментарий сотрудника',
- ),
- 'comment_field': GenericSerializer.get_field_information(
- model_name='comment',
- field_verbose='Комментарий руководителя',
- ),
- 'access_field': GenericSerializer.get_field_information(
- model_name="access__name",
- field_verbose='Название доступа',
- ),
- 'property_field': GenericSerializer.get_field_information(
- model_name="property__name",
- field_verbose="Название запроса",
- ),
- 'request_period_from_field': GenericSerializer.get_field_information(
- model_name='request_period_from',
- ),
- 'request_period_to_field': GenericSerializer.get_field_information(
- model_name='request_period_to',
- ),
- }
- class Meta:
- model = SubmissionRequest
- depth = 1
- fields = [
- 'id_field',
- 'user_field',
- 'supervisor_field',
- 'access_field',
- 'property_field',
- 'comment_user_field',
- 'comment_field',
- 'request_period_from_field',
- 'request_period_to_field',
- ]
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement