mirror of
https://github.com/nottinghamtec/PyRIGS.git
synced 2026-01-29 03:12:15 +00:00
pep8
This commit is contained in:
@@ -1,4 +1,5 @@
|
|||||||
from PyRIGS.decorators import user_passes_test_with_403
|
from PyRIGS.decorators import user_passes_test_with_403
|
||||||
|
|
||||||
|
|
||||||
def has_perm_or_supervisor(perm, login_url=None, oembed_view=None):
|
def has_perm_or_supervisor(perm, login_url=None, oembed_view=None):
|
||||||
return user_passes_test_with_403(lambda u: (hasattr(u, 'as_trainee') and u.as_trainee.is_supervisor) or u.has_perm(perm), login_url=login_url, oembed_view=oembed_view)
|
return user_passes_test_with_403(lambda u: (hasattr(u, 'as_trainee') and u.as_trainee.is_supervisor) or u.has_perm(perm), login_url=login_url, oembed_view=oembed_view)
|
||||||
|
|||||||
@@ -35,19 +35,27 @@ class Command(BaseCommand):
|
|||||||
def setup_groups(self):
|
def setup_groups(self):
|
||||||
self.committee_group = Group.objects.create(name='Committee')
|
self.committee_group = Group.objects.create(name='Committee')
|
||||||
|
|
||||||
perms = ["add_trainingitemqualification", "change_trainingitemqualification", "delete_trainingitemqualification", "add_traininglevelqualification", "change_traininglevelqualification", "delete_traininglevelqualification", "add_traininglevelrequirement", "change_traininglevelrequirement", "delete_traininglevelrequirement"]
|
perms = [
|
||||||
|
"add_trainingitemqualification",
|
||||||
|
"change_trainingitemqualification",
|
||||||
|
"delete_trainingitemqualification",
|
||||||
|
"add_traininglevelqualification",
|
||||||
|
"change_traininglevelqualification",
|
||||||
|
"delete_traininglevelqualification",
|
||||||
|
"add_traininglevelrequirement",
|
||||||
|
"change_traininglevelrequirement",
|
||||||
|
"delete_traininglevelrequirement"]
|
||||||
|
|
||||||
for permId in perms:
|
for permId in perms:
|
||||||
self.committee_group.permissions.add(Permission.objects.get(codename=permId))
|
self.committee_group.permissions.add(Permission.objects.get(codename=permId))
|
||||||
|
|
||||||
self.committee_group.save()
|
self.committee_group.save()
|
||||||
|
|
||||||
|
|
||||||
def setup_useful_profiles(self):
|
def setup_useful_profiles(self):
|
||||||
supervisor = Profile.objects.create(username="supervisor", first_name="Super", last_name="Visor",
|
supervisor = Profile.objects.create(username="supervisor", first_name="Super", last_name="Visor",
|
||||||
initials="SV",
|
initials="SV",
|
||||||
email="supervisor@example.com", is_active=True,
|
email="supervisor@example.com", is_active=True,
|
||||||
is_staff=True, is_approved=True)
|
is_staff=True, is_approved=True)
|
||||||
supervisor.set_password('supervisor')
|
supervisor.set_password('supervisor')
|
||||||
supervisor.groups.add(Group.objects.get(name="Keyholders"))
|
supervisor.groups.add(Group.objects.get(name="Keyholders"))
|
||||||
supervisor.save()
|
supervisor.save()
|
||||||
@@ -61,8 +69,8 @@ class Command(BaseCommand):
|
|||||||
confirmed_by=models.Trainee.objects.first())
|
confirmed_by=models.Trainee.objects.first())
|
||||||
|
|
||||||
committee_user = Profile.objects.create(username="committee", first_name="Committee", last_name="Member",
|
committee_user = Profile.objects.create(username="committee", first_name="Committee", last_name="Member",
|
||||||
initials="CM",
|
initials="CM",
|
||||||
email="committee@example.com", is_active=True, is_approved=True)
|
email="committee@example.com", is_active=True, is_approved=True)
|
||||||
committee_user.groups.add(self.committee_group)
|
committee_user.groups.add(self.committee_group)
|
||||||
supervisor.groups.add(Group.objects.get(name="Keyholders"))
|
supervisor.groups.add(Group.objects.get(name="Keyholders"))
|
||||||
committee_user.set_password('committee')
|
committee_user.set_password('committee')
|
||||||
|
|||||||
@@ -124,7 +124,7 @@ class Command(BaseCommand):
|
|||||||
for child in root:
|
for child in root:
|
||||||
depths = [("Training_Started", models.TrainingItemQualification.STARTED),
|
depths = [("Training_Started", models.TrainingItemQualification.STARTED),
|
||||||
("Training_Complete", models.TrainingItemQualification.COMPLETE),
|
("Training_Complete", models.TrainingItemQualification.COMPLETE),
|
||||||
("Competency_Assessed", models.TrainingItemQualification.PASSED_OUT),]
|
("Competency_Assessed", models.TrainingItemQualification.PASSED_OUT), ]
|
||||||
|
|
||||||
for (depth, depth_index) in depths:
|
for (depth, depth_index) in depths:
|
||||||
if child.find('{}_Date'.format(depth)) is not None:
|
if child.find('{}_Date'.format(depth)) is not None:
|
||||||
|
|||||||
@@ -19,10 +19,9 @@ class Trainee(Profile, RevisionMixin):
|
|||||||
@property
|
@property
|
||||||
def is_technician(self):
|
def is_technician(self):
|
||||||
return self.level_qualifications.exclude(confirmed_on=None).select_related('level') \
|
return self.level_qualifications.exclude(confirmed_on=None).select_related('level') \
|
||||||
.filter(level__level=TrainingLevel.TECHNICIAN) \
|
.filter(level__level=TrainingLevel.TECHNICIAN) \
|
||||||
.exclude(level__department=TrainingLevel.HAULAGE) \
|
.exclude(level__department=TrainingLevel.HAULAGE) \
|
||||||
.exclude(level__department__isnull=True).exists()
|
.exclude(level__department__isnull=True).exists()
|
||||||
|
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def is_supervisor(self):
|
def is_supervisor(self):
|
||||||
|
|||||||
@@ -12,7 +12,7 @@ urlpatterns = [
|
|||||||
path('trainee/<int:pk>/',
|
path('trainee/<int:pk>/',
|
||||||
has_perm_or_supervisor('RIGS.view_profile')(views.TraineeDetail.as_view()),
|
has_perm_or_supervisor('RIGS.view_profile')(views.TraineeDetail.as_view()),
|
||||||
name='trainee_detail'),
|
name='trainee_detail'),
|
||||||
path('trainee/<int:pk>/history', has_perm_or_supervisor('RIGS.view_profile')(VersionHistory.as_view()), name='trainee_history', kwargs={'model': models.Trainee, 'app': 'training'}), # Not picked up automatically because proxy model (I think)
|
path('trainee/<int:pk>/history', has_perm_or_supervisor('RIGS.view_profile')(VersionHistory.as_view()), name='trainee_history', kwargs={'model': models.Trainee, 'app': 'training'}), # Not picked up automatically because proxy model (I think)
|
||||||
path('trainee/<int:pk>/add_qualification/', has_perm_or_supervisor('training.add_trainingitemqualificaiton')(views.AddQualification.as_view()),
|
path('trainee/<int:pk>/add_qualification/', has_perm_or_supervisor('training.add_trainingitemqualificaiton')(views.AddQualification.as_view()),
|
||||||
name='add_qualification'),
|
name='add_qualification'),
|
||||||
path('trainee/<int:pk>/edit_qualification/', has_perm_or_supervisor('training.change_trainingitemqualification')(views.EditQualification.as_view()),
|
path('trainee/<int:pk>/edit_qualification/', has_perm_or_supervisor('training.change_trainingitemqualification')(views.EditQualification.as_view()),
|
||||||
|
|||||||
Reference in New Issue
Block a user