Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from django.db import models
- from django.db.models import QuerySet
- from django.utils import timezone
- from crm.models import Project
- from crm.models import get_base_record_for_project
- from .user import User
- from misc.generic_models.meta_mixin import MetaMixin
- class UserAccess(models.Model, MetaMixin):
- """Cоздаем возможность добавлять разные типы доступов"""
- _id_meta = [MetaMixin.FieldTags.PKField, MetaMixin.FieldTags.NotForLog]
- name = models.CharField(verbose_name='Название доступа', max_length=255, null=False, blank=False)
- url = models.SlugField(verbose_name='URL Адрес ресурса', max_length=999, null=True, blank=True)
- comment = models.TextField(verbose_name='Комментарий', null=True, blank=True)
- project = models.ForeignKey(
- Project, verbose_name='проект',
- on_delete=models.PROTECT,
- default=get_base_record_for_project,
- blank=True,
- )
- _project_meta = [MetaMixin.FieldTags.ProjectField]
- def __str__(self):
- return self.name
- __repr__ = __str__
- class Meta:
- verbose_name = 'Доступы'
- verbose_name_plural = 'Доступы'
- class ConnectingUserToAccess(models.Model, MetaMixin):
- """Подключение сотрудника к доступам"""
- _id_meta = [MetaMixin.FieldTags.PKField, MetaMixin.FieldTags.NotForLog]
- transfer_date = models.DateTimeField('Дата передачи', null=False, blank=False, default=timezone.now)
- return_date = models.DateTimeField('Дата возврата', null=True, blank=True)
- comment = models.TextField(verbose_name='Комментарий', null=True, blank=True)
- user_access = models.ForeignKey(
- UserAccess,
- verbose_name='Назначение доступа сотруднику',
- related_name='access',
- on_delete=models.CASCADE,
- null=False,
- blank=False,
- )
- _id_meta = [MetaMixin.FieldTags.PKField, MetaMixin.FieldTags.NotForLog]# Мета данные поля id
- user = models.ForeignKey(
- User,
- verbose_name='Ответственный сотрудник по возврату данных',
- related_name='employee_access',
- on_delete=models.CASCADE,
- null=False,
- blank=False,
- )
- _user_meta = [MetaMixin.FieldTags.UserField]
- project = models.ForeignKey(
- Project, verbose_name='проект',
- on_delete=models.PROTECT,
- default=get_base_record_for_project,
- blank=True,
- )
- _project_meta = [MetaMixin.FieldTags.ProjectField]
- def check_accesses_are_open(self) -> bool:
- """Проверка на открытые доступы у сотрудника"""
- if self.return_date:
- return False
- return True
- def __str__(self):
- return self.employee
- __repr__ = __str__
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement