mirror of
https://github.com/nottinghamtec/PyRIGS.git
synced 2026-01-18 05:52:15 +00:00
Common competencies also do not count for being a supervisor
This commit is contained in:
@@ -5,6 +5,7 @@ from datetime import date
|
||||
from training import models
|
||||
from RIGS.models import Profile
|
||||
|
||||
|
||||
class SessionLogForm(forms.Form):
|
||||
pass
|
||||
|
||||
@@ -34,6 +35,7 @@ class QualificationForm(forms.ModelForm):
|
||||
raise forms.ValidationError('Selected supervisor must actually *be* a supervisor...')
|
||||
return supervisor
|
||||
|
||||
|
||||
class RequirementForm(forms.ModelForm):
|
||||
depth = forms.ChoiceField(choices=models.TrainingItemQualification.CHOICES)
|
||||
|
||||
|
||||
@@ -90,4 +90,4 @@ class Command(BaseCommand):
|
||||
is_staff=True)
|
||||
supervisor.set_password('supervisor')
|
||||
supervisor.save()
|
||||
models.TrainingLevelQualification.objects.create(trainee=supervisor, level=models.TrainingLevel.objects.filter(level__gte=models.TrainingLevel.SUPERVISOR).exclude(department=models.TrainingLevel.HAULAGE).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())
|
||||
|
||||
@@ -5,7 +5,9 @@ from reversion import revisions as reversion
|
||||
from django.urls import reverse
|
||||
|
||||
# 'shim' overtop the profile model to neatly contain all training related fields etc
|
||||
@reversion.register # profile is already registered, but this triggers my custom versioning logic
|
||||
|
||||
|
||||
@reversion.register # profile is already registered, but this triggers my custom versioning logic
|
||||
class Trainee(Profile):
|
||||
class Meta:
|
||||
proxy = True
|
||||
@@ -21,7 +23,10 @@ class Trainee(Profile):
|
||||
|
||||
@property
|
||||
def is_supervisor(self):
|
||||
return self.level_qualifications(True).filter(level__gte=TrainingLevel.SUPERVISOR).exclude(level__department=TrainingLevel.HAULAGE).exists()
|
||||
return self.level_qualifications(True) \
|
||||
.filter(level__gte=TrainingLevel.SUPERVISOR) \
|
||||
.exclude(level__department=TrainingLevel.HAULAGE) \
|
||||
.exclude(level__department__isnull=True).exists()
|
||||
|
||||
@property
|
||||
def is_driver(self):
|
||||
@@ -38,6 +43,8 @@ class Trainee(Profile):
|
||||
return reverse('trainee_detail', kwargs={'pk': self.pk})
|
||||
|
||||
# Items
|
||||
|
||||
|
||||
class TrainingCategory(models.Model):
|
||||
reference_number = models.CharField(max_length=3)
|
||||
name = models.CharField(max_length=50)
|
||||
@@ -95,7 +102,7 @@ class TrainingItemQualification(models.Model):
|
||||
|
||||
def save(self, *args, **kwargs):
|
||||
super().save()
|
||||
for level in TrainingLevel.objects.all(): # Mm yes efficiency FIXME
|
||||
for level in TrainingLevel.objects.all(): # Mm yes efficiency FIXME
|
||||
if level.user_has_requirements(self.trainee):
|
||||
with reversion.create_revision():
|
||||
level_qualification = TrainingLevelQualification.objects.get_or_create(trainee=self.trainee, level=level)
|
||||
@@ -135,7 +142,7 @@ class TrainingLevel(models.Model, RevisionMixin):
|
||||
(3, 'Rigging'),
|
||||
(HAULAGE, 'Haulage'),
|
||||
)
|
||||
department = models.IntegerField(choices=DEPARTMENTS, null=True) # N.B. Technical Assistant does not have a department
|
||||
department = models.IntegerField(choices=DEPARTMENTS, null=True) # N.B. Technical Assistant does not have a department
|
||||
level = models.IntegerField(choices=CHOICES)
|
||||
prerequisite_levels = models.ManyToManyField('self', related_name='prerequisites', symmetrical=False, blank=True)
|
||||
icon = models.CharField(null=True, blank=True, max_length=20)
|
||||
@@ -157,6 +164,10 @@ class TrainingLevel(models.Model, RevisionMixin):
|
||||
def get_requirements_of_depth(self, depth):
|
||||
return self.requirements.filter(depth=depth)
|
||||
|
||||
@property
|
||||
def is_common_competencies(self):
|
||||
return self.department is None and self.level > 0
|
||||
|
||||
@property
|
||||
def started_requirements(self):
|
||||
return self.get_requirements_of_depth(TrainingItemQualification.STARTED)
|
||||
@@ -169,7 +180,7 @@ class TrainingLevel(models.Model, RevisionMixin):
|
||||
def passed_out_requirements(self):
|
||||
return self.get_requirements_of_depth(TrainingItemQualification.PASSED_OUT)
|
||||
|
||||
def percentage_complete(self, user): # FIXME
|
||||
def percentage_complete(self, user): # FIXME
|
||||
needed_qualifications = self.requirements.all().select_related()
|
||||
relavant_qualifications = 0.0
|
||||
# TODO Efficiency...
|
||||
@@ -227,6 +238,8 @@ class TrainingLevelQualification(models.Model):
|
||||
reversion_hide = True
|
||||
|
||||
def __str__(self):
|
||||
if self.level.is_common_competencies:
|
||||
return "{} is qualified in the {}".format(self.trainee, self.level)
|
||||
return "{} is qualified as a {}".format(self.trainee, self.level)
|
||||
|
||||
class Meta:
|
||||
|
||||
@@ -10,6 +10,7 @@ from django.db import transaction
|
||||
|
||||
from users import views
|
||||
|
||||
|
||||
class ItemList(generic.ListView):
|
||||
template_name = "item_list.html"
|
||||
model = models.TrainingItem
|
||||
@@ -36,7 +37,7 @@ class TraineeDetail(views.ProfileDetail, ModalURLMixin):
|
||||
context["categories"] = models.TrainingCategory.objects.all().prefetch_related('items')
|
||||
choices = models.TrainingItemQualification.CHOICES
|
||||
context["depths"] = choices
|
||||
for i in [x for x,_ in choices]:
|
||||
for i in [x for x, _ in choices]:
|
||||
context[str(i)] = self.object.get_records_of_depth(i)
|
||||
return context
|
||||
|
||||
@@ -64,7 +65,7 @@ class LevelList(generic.ListView):
|
||||
def get_context_data(self, **kwargs):
|
||||
context = super().get_context_data(**kwargs)
|
||||
context["page_title"] = "All Training Levels"
|
||||
context["levels"] = models.TrainingLevel.objects.all().order_by('level','department')
|
||||
context["levels"] = models.TrainingLevel.objects.all().order_by('level', 'department')
|
||||
return context
|
||||
|
||||
|
||||
@@ -105,7 +106,7 @@ class AddQualification(generic.CreateView):
|
||||
return context
|
||||
|
||||
def get_success_url(self):
|
||||
return reverse_lazy('trainee_detail', kwargs={"pk": self.object.pk })
|
||||
return reverse_lazy('trainee_detail', kwargs={"pk": self.object.pk})
|
||||
|
||||
def get_form_kwargs(self):
|
||||
kwargs = super(AddQualification, self).get_form_kwargs()
|
||||
|
||||
Reference in New Issue
Block a user