diff --git a/RIGS/models.py b/RIGS/models.py index 5d2b821b..9fe2ef38 100644 --- a/RIGS/models.py +++ b/RIGS/models.py @@ -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): diff --git a/training/management/commands/generateSampleTrainingData.py b/training/management/commands/generateSampleTrainingData.py index e456b90c..f44bdbc6 100644 --- a/training/management/commands/generateSampleTrainingData.py +++ b/training/management/commands/generateSampleTrainingData.py @@ -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()) diff --git a/training/templates/partials/add_qualification.html b/training/templates/partials/add_qualification.html index 96cb5b42..94011354 100644 --- a/training/templates/partials/add_qualification.html +++ b/training/templates/partials/add_qualification.html @@ -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 %} Add New Training Record diff --git a/training/views.py b/training/views.py index fd7ee5c6..67216f3e 100644 --- a/training/views.py +++ b/training/views.py @@ -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 diff --git a/users/views.py b/users/views.py index 42d37ebe..1def6045 100644 --- a/users/views.py +++ b/users/views.py @@ -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