From a184bbfa2654c86eb2eab6398a130d7ab00e6920 Mon Sep 17 00:00:00 2001 From: FreneticScribbler Date: Fri, 22 Oct 2021 15:57:20 +0100 Subject: [PATCH] Much template wrangling --- .../commands/generateSampleTrainingData.py | 19 +++++++++---- training/models.py | 27 ++++++++++-------- training/templates/level_list.html | 7 ++--- .../templates/partials/add_qualification.html | 5 ++++ training/templates/trainee_detail.html | 4 +-- training/templatetags/tags.py | 4 --- training/urls.py | 22 +++++++-------- training/views.py | 2 +- users/templates/profile_detail.html | 28 +++++++++++++------ users/views.py | 2 ++ 10 files changed, 71 insertions(+), 49 deletions(-) create mode 100644 training/templates/partials/add_qualification.html diff --git a/training/management/commands/generateSampleTrainingData.py b/training/management/commands/generateSampleTrainingData.py index fa8bbb35..e456b90c 100644 --- a/training/management/commands/generateSampleTrainingData.py +++ b/training/management/commands/generateSampleTrainingData.py @@ -51,11 +51,11 @@ class Command(BaseCommand): def setup_levels(self): items = self.items.copy() - ta = models.TrainingLevel.objects.create(level=models.TrainingLevel.TA, description="Passion will hatred faithful evil suicide noble battle. Truth aversion gains grandeur noble. Dead play gains prejudice god ascetic grandeur zarathustra dead good. Faithful ultimate justice overcome love will mountains inexpedient.") + ta = models.TrainingLevel.objects.create(level=models.TrainingLevel.TA, description="Passion will hatred faithful evil suicide noble battle. Truth aversion gains grandeur noble. Dead play gains prejudice god ascetic grandeur zarathustra dead good. Faithful ultimate justice overcome love will mountains inexpedient.", icon="address-card") self.levels.append(ta) - tech_ccs = models.TrainingLevel.objects.create(level=models.TrainingLevel.TECHNICIAN, description="Technician Common Competencies. Spirit abstract endless insofar horror sexuality depths war decrepit against strong aversion revaluation free. Christianity reason joy sea law mountains transvaluation. Sea battle aversion dead ultimate morality self. Faithful morality.") + tech_ccs = models.TrainingLevel.objects.create(level=models.TrainingLevel.TECHNICIAN, description="Technician Common Competencies. Spirit abstract endless insofar horror sexuality depths war decrepit against strong aversion revaluation free. Christianity reason joy sea law mountains transvaluation. Sea battle aversion dead ultimate morality self. Faithful morality.", icon="book-reader") tech_ccs.prerequisite_levels.add(ta) - super_ccs = models.TrainingLevel.objects.create(level=models.TrainingLevel.SUPERVISOR, description="Depths disgust hope faith of against hatred will victorious. Law...") + super_ccs = models.TrainingLevel.objects.create(level=models.TrainingLevel.SUPERVISOR, description="Depths disgust hope faith of against hatred will victorious. Law...", icon="user-graduate") for i in range(0, 5): if len(items) == 0: break @@ -65,10 +65,17 @@ class Command(BaseCommand): models.TrainingLevelRequirement.objects.create(level=tech_ccs, item=item, depth=random.choice(models.TrainingItemQualification.CHOICES)[0]) else: models.TrainingLevelRequirement.objects.create(level=super_ccs, item=item, depth=random.choice(models.TrainingItemQualification.CHOICES)[0]) + icons = { + models.TrainingLevel.SOUND: ('microphone', 'microphone-alt'), + models.TrainingLevel.LIGHTING: ('lightbulb', 'traffic-light'), + models.TrainingLevel.POWER: ('plug', 'bolt'), + models.TrainingLevel.RIGGING: ('link', 'pallet'), + models.TrainingLevel.HAULAGE: ('truck', 'route'), + } for i,name in models.TrainingLevel.DEPARTMENTS: - technician = models.TrainingLevel.objects.create(level=models.TrainingLevel.TECHNICIAN, department=i, description="Moral pinnacle derive ultimate war dead. Strong fearful joy contradict battle christian faithful enlightenment prejudice zarathustra moral.") + technician = models.TrainingLevel.objects.create(level=models.TrainingLevel.TECHNICIAN, department=i, description="Moral pinnacle derive ultimate war dead. Strong fearful joy contradict battle christian faithful enlightenment prejudice zarathustra moral.", icon=icons[i][0]) technician.prerequisite_levels.add(tech_ccs) - supervisor = models.TrainingLevel.objects.create(level=models.TrainingLevel.SUPERVISOR, department=i, description="Spirit holiest merciful mountains inexpedient reason value. Suicide ultimate hope.") + supervisor = models.TrainingLevel.objects.create(level=models.TrainingLevel.SUPERVISOR, department=i, description="Spirit holiest merciful mountains inexpedient reason value. Suicide ultimate hope.", icon=icons[i][1]) supervisor.prerequisite_levels.add(super_ccs, technician) for i in range(0, 30): @@ -87,7 +94,7 @@ class Command(BaseCommand): supervisor = models.Profile.objects.create(username="supervisor", first_name="Super", last_name="Visor", initials="SV", email="supervisor@example.com", is_active=True, - is_staff=True) + is_staff=True, is_approved=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).exclude(department__isnull=True).first(), confirmed_on=timezone.now()) diff --git a/training/models.py b/training/models.py index eba3d399..8327f00c 100644 --- a/training/models.py +++ b/training/models.py @@ -42,8 +42,6 @@ class Trainee(Profile, RevisionMixin): def get_absolute_url(self): return reverse('trainee_detail', kwargs={'pk': self.pk}) -# Items - class TrainingCategory(models.Model): reference_number = models.CharField(max_length=3) @@ -134,12 +132,16 @@ class TrainingLevel(models.Model, RevisionMixin): (TECHNICIAN, 'Technician'), (SUPERVISOR, 'Supervisor'), ) + SOUND = 0 + LIGHTING = 1 + POWER = 2 + RIGGING = 3 HAULAGE = 4 DEPARTMENTS = ( - (0, 'Sound'), - (1, 'Lighting'), - (2, 'Power'), - (3, 'Rigging'), + (SOUND, 'Sound'), + (LIGHTING, 'Lighting'), + (POWER, 'Power'), + (RIGGING, 'Rigging'), (HAULAGE, 'Haulage'), ) department = models.IntegerField(choices=DEPARTMENTS, null=True) # N.B. Technical Assistant does not have a department @@ -147,16 +149,17 @@ class TrainingLevel(models.Model, RevisionMixin): prerequisite_levels = models.ManyToManyField('self', related_name='prerequisites', symmetrical=False, blank=True) icon = models.CharField(null=True, blank=True, max_length=20) - def get_department_colour(self): - if self.department == 0: + @property + def department_colour(self): + if self.department == self.SOUND: return "info" - elif self.department == 1: + elif self.department == self.LIGHTING: return "dark" - elif self.department == 2: + elif self.department == self.POWER: return "danger" - elif self.department == 3: + elif self.department == self.RIGGING: return "warning" - elif self.department == 4: + elif self.department == self.HAULAGE: return "light" else: return "primary" diff --git a/training/templates/level_list.html b/training/templates/level_list.html index f4d0f4a2..9e76064a 100644 --- a/training/templates/level_list.html +++ b/training/templates/level_list.html @@ -1,11 +1,10 @@ {% extends 'base_training.html' %} -{% load colour_from_level from tags %} {% block css %}