54 lines
1.7 KiB
Python
54 lines
1.7 KiB
Python
# frontend/models.py
|
|
from django.db import models
|
|
from django.contrib.auth.models import User
|
|
from lib.db import BaseModel, SearchableMixin
|
|
from django.db.models import Q
|
|
|
|
def default_settings():
|
|
return {
|
|
'dashboard_view': 'list',
|
|
}
|
|
class UserProfile(models.Model):
|
|
user = models.OneToOneField(User, on_delete=models.CASCADE, related_name='profile')
|
|
ldap_uid = models.CharField(max_length=100, unique=True)
|
|
settings = models.JSONField(default=default_settings)
|
|
|
|
def __str__(self):
|
|
return f"{self.user.username} - {self.ldap_uid}"
|
|
|
|
@property
|
|
def user_group(self):
|
|
if self.user.groups.filter(name='root').exists():
|
|
return 'root'
|
|
elif self.user.groups.filter(name='intern').exists():
|
|
return 'intern'
|
|
elif self.user.groups.filter(name='extern').exists():
|
|
return 'extern'
|
|
return None
|
|
|
|
def is_external(self):
|
|
return self.user_group == 'extern'
|
|
|
|
def is_internal(self):
|
|
return self.user_group in ['intern', 'root']
|
|
|
|
def is_root(self):
|
|
return self.user_group == 'root'
|
|
|
|
|
|
class FAQ(BaseModel, SearchableMixin):
|
|
title = models.CharField(max_length=200, help_text='FAQ Question/Title')
|
|
content = models.TextField(help_text='FAQ Answer/Content')
|
|
order = models.IntegerField(default=0, help_text='Order for display (lower numbers first)')
|
|
|
|
class Meta:
|
|
ordering = ['order', 'title']
|
|
verbose_name = 'FAQ'
|
|
verbose_name_plural = 'FAQs'
|
|
|
|
def __str__(self):
|
|
return self.title
|
|
|
|
@classmethod
|
|
def term_filter(cls, search_string):
|
|
return Q(title__icontains=search_string) | Q(content__icontains=search_string) |