feat: Add organization affiliation to user
This commit is contained in:
parent
5582538a70
commit
db94ec41ed
@ -0,0 +1,19 @@
|
|||||||
|
# Generated by Django 5.1.1 on 2024-11-14 06:42
|
||||||
|
|
||||||
|
import django.db.models.deletion
|
||||||
|
from django.db import migrations, models
|
||||||
|
|
||||||
|
|
||||||
|
class Migration(migrations.Migration):
|
||||||
|
|
||||||
|
dependencies = [
|
||||||
|
('fellchensammlung', '0016_rescueorganization_phone_number'),
|
||||||
|
]
|
||||||
|
|
||||||
|
operations = [
|
||||||
|
migrations.AddField(
|
||||||
|
model_name='user',
|
||||||
|
name='organization_affiliation',
|
||||||
|
field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.PROTECT, to='fellchensammlung.rescueorganization', verbose_name='Organisation'),
|
||||||
|
),
|
||||||
|
]
|
@ -34,86 +34,6 @@ class Language(models.Model):
|
|||||||
verbose_name_plural = _('Sprachen')
|
verbose_name_plural = _('Sprachen')
|
||||||
|
|
||||||
|
|
||||||
class User(AbstractUser):
|
|
||||||
"""
|
|
||||||
Model that holds a user's profile, including the django user model
|
|
||||||
|
|
||||||
The trust levels act as permission system and can be displayed as a badge for the user
|
|
||||||
"""
|
|
||||||
|
|
||||||
# Admins can perform all actions and have the highest trust associated with them
|
|
||||||
# Moderators can make moderation decisions regarding the deletion of content
|
|
||||||
# Coordinators can create adoption notices without them being checked
|
|
||||||
# Members can create adoption notices that must be activated
|
|
||||||
ADMIN = "admin"
|
|
||||||
MODERATOR = "Moderator"
|
|
||||||
COORDINATOR = "Koordinator*in"
|
|
||||||
MEMBER = "Mitglied"
|
|
||||||
TRUST_LEVEL = {
|
|
||||||
ADMIN: 4,
|
|
||||||
MODERATOR: 3,
|
|
||||||
COORDINATOR: 2,
|
|
||||||
MEMBER: 1,
|
|
||||||
}
|
|
||||||
|
|
||||||
preferred_language = models.ForeignKey(Language, on_delete=models.PROTECT, null=True, blank=True,
|
|
||||||
verbose_name=_('Bevorzugte Sprache'))
|
|
||||||
trust_level = models.IntegerField(choices=TRUST_LEVEL, default=TRUST_LEVEL[MEMBER])
|
|
||||||
updated_at = models.DateTimeField(auto_now=True)
|
|
||||||
|
|
||||||
class Meta:
|
|
||||||
verbose_name = _('Nutzer*in')
|
|
||||||
verbose_name_plural = _('Nutzer*innen')
|
|
||||||
|
|
||||||
def get_absolute_url(self):
|
|
||||||
return reverse("user-detail", args=[str(self.pk)])
|
|
||||||
|
|
||||||
def get_notifications_url(self):
|
|
||||||
return self.get_absolute_url()
|
|
||||||
|
|
||||||
def get_num_unread_notifications(self):
|
|
||||||
return BaseNotification.objects.filter(user=self, read=False).count()
|
|
||||||
|
|
||||||
@property
|
|
||||||
def adoption_notices(self):
|
|
||||||
return AdoptionNotice.objects.filter(owner=self)
|
|
||||||
|
|
||||||
@property
|
|
||||||
def owner(self):
|
|
||||||
return self
|
|
||||||
|
|
||||||
|
|
||||||
class Image(models.Model):
|
|
||||||
image = models.ImageField(upload_to='images')
|
|
||||||
alt_text = models.TextField(max_length=2000)
|
|
||||||
owner = models.ForeignKey(User, on_delete=models.CASCADE)
|
|
||||||
updated_at = models.DateTimeField(auto_now=True)
|
|
||||||
created_at = models.DateTimeField(auto_now_add=True)
|
|
||||||
|
|
||||||
def __str__(self):
|
|
||||||
return self.alt_text
|
|
||||||
|
|
||||||
@property
|
|
||||||
def as_html(self):
|
|
||||||
return f'<img src="{MEDIA_URL}/{self.image}" alt="{self.alt_text}">'
|
|
||||||
|
|
||||||
|
|
||||||
class Species(models.Model):
|
|
||||||
"""Model representing a species of animal."""
|
|
||||||
name = models.CharField(max_length=200, help_text=_('Name der Tierart'),
|
|
||||||
verbose_name=_('Name'))
|
|
||||||
updated_at = models.DateTimeField(auto_now=True)
|
|
||||||
created_at = models.DateTimeField(auto_now_add=True)
|
|
||||||
|
|
||||||
def __str__(self):
|
|
||||||
"""String for representing the Model object."""
|
|
||||||
return self.name
|
|
||||||
|
|
||||||
class Meta:
|
|
||||||
verbose_name = _('Tierart')
|
|
||||||
verbose_name_plural = _('Tierarten')
|
|
||||||
|
|
||||||
|
|
||||||
class Location(models.Model):
|
class Location(models.Model):
|
||||||
place_id = models.IntegerField()
|
place_id = models.IntegerField()
|
||||||
latitude = models.FloatField()
|
latitude = models.FloatField()
|
||||||
@ -193,6 +113,88 @@ class RescueOrganization(models.Model):
|
|||||||
comment = models.TextField(verbose_name=_("Kommentar"), null=True, blank=True, )
|
comment = models.TextField(verbose_name=_("Kommentar"), null=True, blank=True, )
|
||||||
|
|
||||||
|
|
||||||
|
class User(AbstractUser):
|
||||||
|
"""
|
||||||
|
Model that holds a user's profile, including the django user model
|
||||||
|
|
||||||
|
The trust levels act as permission system and can be displayed as a badge for the user
|
||||||
|
"""
|
||||||
|
|
||||||
|
# Admins can perform all actions and have the highest trust associated with them
|
||||||
|
# Moderators can make moderation decisions regarding the deletion of content
|
||||||
|
# Coordinators can create adoption notices without them being checked
|
||||||
|
# Members can create adoption notices that must be activated
|
||||||
|
ADMIN = "admin"
|
||||||
|
MODERATOR = "Moderator"
|
||||||
|
COORDINATOR = "Koordinator*in"
|
||||||
|
MEMBER = "Mitglied"
|
||||||
|
TRUST_LEVEL = {
|
||||||
|
ADMIN: 4,
|
||||||
|
MODERATOR: 3,
|
||||||
|
COORDINATOR: 2,
|
||||||
|
MEMBER: 1,
|
||||||
|
}
|
||||||
|
|
||||||
|
preferred_language = models.ForeignKey(Language, on_delete=models.PROTECT, null=True, blank=True,
|
||||||
|
verbose_name=_('Bevorzugte Sprache'))
|
||||||
|
trust_level = models.IntegerField(choices=TRUST_LEVEL, default=TRUST_LEVEL[MEMBER])
|
||||||
|
updated_at = models.DateTimeField(auto_now=True)
|
||||||
|
organization_affiliation = models.ForeignKey(RescueOrganization, on_delete=models.PROTECT, null=True, blank=True,
|
||||||
|
verbose_name=_('Organisation'))
|
||||||
|
|
||||||
|
class Meta:
|
||||||
|
verbose_name = _('Nutzer*in')
|
||||||
|
verbose_name_plural = _('Nutzer*innen')
|
||||||
|
|
||||||
|
def get_absolute_url(self):
|
||||||
|
return reverse("user-detail", args=[str(self.pk)])
|
||||||
|
|
||||||
|
def get_notifications_url(self):
|
||||||
|
return self.get_absolute_url()
|
||||||
|
|
||||||
|
def get_num_unread_notifications(self):
|
||||||
|
return BaseNotification.objects.filter(user=self, read=False).count()
|
||||||
|
|
||||||
|
@property
|
||||||
|
def adoption_notices(self):
|
||||||
|
return AdoptionNotice.objects.filter(owner=self)
|
||||||
|
|
||||||
|
@property
|
||||||
|
def owner(self):
|
||||||
|
return self
|
||||||
|
|
||||||
|
|
||||||
|
class Image(models.Model):
|
||||||
|
image = models.ImageField(upload_to='images')
|
||||||
|
alt_text = models.TextField(max_length=2000)
|
||||||
|
owner = models.ForeignKey(User, on_delete=models.CASCADE)
|
||||||
|
updated_at = models.DateTimeField(auto_now=True)
|
||||||
|
created_at = models.DateTimeField(auto_now_add=True)
|
||||||
|
|
||||||
|
def __str__(self):
|
||||||
|
return self.alt_text
|
||||||
|
|
||||||
|
@property
|
||||||
|
def as_html(self):
|
||||||
|
return f'<img src="{MEDIA_URL}/{self.image}" alt="{self.alt_text}">'
|
||||||
|
|
||||||
|
|
||||||
|
class Species(models.Model):
|
||||||
|
"""Model representing a species of animal."""
|
||||||
|
name = models.CharField(max_length=200, help_text=_('Name der Tierart'),
|
||||||
|
verbose_name=_('Name'))
|
||||||
|
updated_at = models.DateTimeField(auto_now=True)
|
||||||
|
created_at = models.DateTimeField(auto_now_add=True)
|
||||||
|
|
||||||
|
def __str__(self):
|
||||||
|
"""String for representing the Model object."""
|
||||||
|
return self.name
|
||||||
|
|
||||||
|
class Meta:
|
||||||
|
verbose_name = _('Tierart')
|
||||||
|
verbose_name_plural = _('Tierarten')
|
||||||
|
|
||||||
|
|
||||||
class AdoptionNotice(models.Model):
|
class AdoptionNotice(models.Model):
|
||||||
class Meta:
|
class Meta:
|
||||||
permissions = [
|
permissions = [
|
||||||
@ -240,7 +242,6 @@ class AdoptionNotice(models.Model):
|
|||||||
else:
|
else:
|
||||||
return "mixed"
|
return "mixed"
|
||||||
|
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def comments(self):
|
def comments(self):
|
||||||
return Comment.objects.filter(adoption_notice=self)
|
return Comment.objects.filter(adoption_notice=self)
|
||||||
|
Loading…
Reference in New Issue
Block a user