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 ConnectingUserToAccess
- class ConnectingUserToAccessSerializer(GenericSerializer):
- """
- Отвечает за сериализацию данных модели ConnectingUserToAccessSerializer
- (табличное представление), оправляемых в ответе на запрос.
- """
- readonly_field = ['id_field', 'user_field', 'user_access_field']
- mandatory_fields = ['id_field', 'user_field', 'user_access_field']
- create_field = ['user_field', 'user_access_field', 'transfer_date_field', 'return_date_field', 'comment_field',]
- id_field = GenericSerializerField(
- model_field_name='id',
- )
- user_field = GenericSerializerField(
- model_field_name='user_id',
- )
- user_access_field = GenericSerializerField(
- model_field_name='user_access_id',
- )
- transfer_date_field = GenericSerializerField(
- model_field_name="transfer_date",
- )
- return_date_field = GenericSerializerField(
- model_field_name='return_date',
- )
- comment_field = GenericSerializerField(
- model_field_name='comment_field',
- )
- user_access_name_field = GenericSerializerField(
- model_field_name='user_access__name',
- )
- user_access_url_field = GenericSerializerField(
- model_field_name='user_access__url',
- )
- user_access_comment_field = GenericSerializerField(
- model_field_name='user_access__comment',
- )
- 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='Ответственный сотрудник по возврату данных',
- ),
- 'user_access_field' : GenericSerializer.get_field_information(
- model_name='user_access_id',
- field_verbose='Доступ выданный сотруднику',
- ),
- 'transfer_date_field' : GenericSerializer.get_field_information(
- model_name="transfer_dated",
- field_verbose='Дата передачи',
- ),
- 'return_date_field' : GenericSerializer.get_field_information(
- model_name='return_date',
- field_verbose='Дата возврата',
- ),
- 'comment_field' : GenericSerializer.get_field_information(
- model_name='comment',
- field_verbose='Комментарий',
- ),
- 'user_access_name_field' : GenericSerializer.get_field_information(
- model_name='user_access__name',
- field_verbose='Название доступа',
- ),
- 'user_access_url_field' : GenericSerializer.get_field_information(
- model_name='user_access__url',
- field_verbose='URL Адрес ресурса',
- ),
- 'user_access_comment_field' : GenericSerializer.get_field_information(
- model_name='user_access__comment',
- field_verbose='Комментарий доступа',
- ),
- 'delete_btn_field': GenericSerializer.get_field_information(),
- }
- class Meta:
- model = ConnectingUserToAccess
- fields = [
- 'id_field',
- 'user_field',
- 'user_access_field',
- 'transfer_date_field',
- 'return_date_field',
- 'comment_field',
- 'user_access_name_field',
- 'user_access_url_field',
- 'user_access_comment_field',
- 'delete_btn_field',
- ]
- def get_delete_btn_field(self, obj) -> dict:
- """Определяет возвращаемое значение для поля кнопки удаления."""
- url = reverse('user_access_delete', args=[obj.id])
- return self.get_button_field(
- action=GenericSerializer.ButtonActions.DELETE,
- url=url,
- verbose='',
- icon='CloseCircle'
- )
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement