begin work on perms

This commit is contained in:
2021-10-22 16:13:08 +01:00
parent a184bbfa26
commit 280a1d9604
5 changed files with 10 additions and 7 deletions

View File

@@ -20,7 +20,7 @@ from reversion.models import Version
@reversion.register
class Profile(AbstractUser):
class Profile(AbstractUser): # TODO move to versioning - currently get import errors with that
initials = models.CharField(max_length=5, unique=True, null=True, blank=False)
phone = models.CharField(max_length=13, blank=True, default='')
api_key = models.CharField(max_length=40, blank=True, editable=False, default='')
@@ -66,7 +66,10 @@ class Profile(AbstractUser):
def __str__(self):
return self.name
# TODO move to versioning - currently get import errors with that
@property
def as_trainee(self):
from training.models import Trainee
return Trainee.objects.get(pk=self.pk)
class RevisionMixin(object):

View File

@@ -96,5 +96,6 @@ class Command(BaseCommand):
email="supervisor@example.com", is_active=True,
is_staff=True, is_approved=True)
supervisor.set_password('supervisor')
supervisor.groups.add(Group.objects.get(name="Keyholders"))
supervisor.save()
models.TrainingLevelQualification.objects.create(trainee=supervisor, level=models.TrainingLevel.objects.filter(level__gte=models.TrainingLevel.SUPERVISOR).exclude(department=models.TrainingLevel.HAULAGE).exclude(department__isnull=True).first(), confirmed_on=timezone.now())
models.TrainingLevelQualification.objects.create(trainee=supervisor, level=models.TrainingLevel.objects.filter(level__gte=models.TrainingLevel.SUPERVISOR).exclude(department=models.TrainingLevel.HAULAGE).exclude(department__isnull=True).first(), confirmed_on=timezone.now(), confirmed_by=models.Trainee.objects.first())

View File

@@ -1,4 +1,4 @@
{% if request.user.is_supervisor or perms.training.add_trainingitemqualification %}
{% if request.user.as_trainee.is_supervisor or perms.training.add_trainingitemqualification %}
<a type="button" class="btn btn-success" href="{% url 'add_qualification' object.pk %}" id="add_record">
<span class="fas fa-plus"></span> Add New Training Record
</a>

View File

@@ -83,7 +83,7 @@ class TraineeList(generic.ListView):
def get_context_data(self, **kwargs):
context = super().get_context_data(**kwargs)
context["page_title"] = "Profile List"
context["page_title"] = "Training Profile List"
return context

View File

@@ -5,7 +5,6 @@ from django.views import generic
from django.views.decorators.csrf import csrf_exempt
from RIGS import models
from training.models import Trainee
# This view should be exempt from requiring CSRF token.
@@ -43,7 +42,7 @@ class ProfileDetail(generic.DetailView):
def get_context_data(self, **kwargs):
context = super(ProfileDetail, self).get_context_data(**kwargs)
context['page_title'] = "Profile: {}".format(self.object)
context["completed_levels"] = Trainee.objects.get(pk=self.object.pk).level_qualifications()
context["completed_levels"] = self.object.as_trainee.level_qualifications()
return context