Create Author mixin

This commit is contained in:
Ross
2024-02-05 09:34:47 +00:00
parent 1e16386e1e
commit 9e06cb45ca
5 changed files with 35 additions and 59 deletions
+8 -32
View File
@@ -27,6 +27,7 @@ from django.contrib.auth.models import User
from django.db.models.signals import post_save
from django.dispatch import receiver
from generic.mixins import AuthorMixin
from helpers.images import get_image_hash, pretty_print_dicom
from rad.settings import REMOTE_URL
from django.utils.html import format_html
@@ -37,6 +38,7 @@ from easy_thumbnails.exceptions import InvalidImageFormatError
import pydicom
import dicognito.anonymizer
from django.contrib.auth.models import User
def findMiddle(input_list):
@@ -47,6 +49,8 @@ def findMiddle(input_list):
return input_list[int(middle)]
class Modality(models.Model):
modality = models.CharField(max_length=200, unique=True)
short_code = models.CharField(max_length=5, unique=True, null=True)
@@ -152,7 +156,7 @@ class Site(models.Model):
return self.short_code
class QuestionBase(models.Model):
class QuestionBase(models.Model, AuthorMixin):
authors_only = models.BooleanField(
help_text="If true only question authors will be able to view.",
default=False,
@@ -181,11 +185,6 @@ class QuestionBase(models.Model):
"""If this makes sense in the question/answer context override"""
return None
def get_author_objects(self):
"""Returns a comma seperated text list of authors"""
authors = [i for i in self.author.all()]
return authors
class SeriesImageBase(models.Model):
"""
@@ -519,7 +518,7 @@ class SeriesBase(models.Model):
pass
class ExamOrCollectionGenericBase(models.Model):
class ExamOrCollectionGenericBase(models.Model, AuthorMixin):
"""Holds functions that relate to both case and other exams
e.g. user management
@@ -556,18 +555,6 @@ class ExamOrCollectionGenericBase(models.Model):
class Meta:
abstract = True
def get_authors(self):
"""Returns a comma seperated text list of authors"""
authors = ", ".join([i.username for i in self.author.all()])
if not authors:
return "None"
return authors
def get_author_objects(self):
"""Returns a comma seperated text list of authors"""
authors = [i for i in self.author.all()]
return authors
def check_user_can_edit(self, user: User):
if user.is_superuser:
return True
@@ -1518,7 +1505,7 @@ def create_user_profile(sender, instance, created, **kwargs):
def save_user_profile(sender, instance, **kwargs):
instance.userprofile.save()
class ExamCollection(models.Model):
class ExamCollection(models.Model, AuthorMixin):
name = models.CharField(max_length=255)
date = models.DateField(blank=True,null=True)
@@ -1531,15 +1518,4 @@ class ExamCollection(models.Model):
def __str__(self):
return f"{self.name} [{self.date}]"
def get_author_objects(self):
"""Returns a comma seperated text list of authors"""
authors = [i for i in self.author.all()]
return authors
def get_authors(self):
"""Returns a comma seperated text list of authors"""
authors = ", ".join([i.username for i in self.author.all()])
if not authors:
return "None"
return authors