mirror of
https://github.com/nottinghamtec/PyRIGS.git
synced 2026-01-17 21:42:14 +00:00
Percentage complete works
Ain't half slow though!
This commit is contained in:
@@ -191,21 +191,6 @@ def linkornone(target, namespace=None, autoescape=True):
|
||||
return "None"
|
||||
|
||||
|
||||
@register.simple_tag
|
||||
def user_has_qualification(user, item, depth):
|
||||
if tmodels.TrainingItem.user_has_qualification(item, user, depth) is not None:
|
||||
return mark_safe("<span class='fas fa-check text-success'></span>")
|
||||
else:
|
||||
return mark_safe("<span class='fas fa-hourglass-start text-warning'></span>")
|
||||
|
||||
@register.simple_tag
|
||||
def user_level_if_present(user, level):
|
||||
return tmodels.TrainingLevelQualification.objects.filter(trainee=user, level=level).first()
|
||||
|
||||
@register.simple_tag
|
||||
def percentage_complete(level, user):
|
||||
return level.percentage_complete(user)
|
||||
|
||||
@register.inclusion_tag('partials/button.html')
|
||||
def button(type, url=None, pk=None, clazz="", icon=None, text="", id=None, style=None):
|
||||
if type == 'edit':
|
||||
|
||||
@@ -18,7 +18,7 @@ class Trainee(Profile):
|
||||
return self.qualifications_obtained.filter(depth=depth)
|
||||
|
||||
def is_user_qualified_in(self, item, required_depth):
|
||||
qual = self.qualifications_obtained.get(item=item)
|
||||
qual = self.qualifications_obtained.filter(item=item).first() # this is a somewhat ghetto version of get_or_none
|
||||
return qual is not None and qual.depth >= required_depth
|
||||
|
||||
# Items
|
||||
@@ -114,9 +114,14 @@ class TrainingLevel(models.Model, RevisionMixin):
|
||||
|
||||
def percentage_complete(self, user): # FIXME
|
||||
needed_qualifications = self.requirements.all()
|
||||
relavant_qualifications = [x for x in user.qualifications_obtained.all() if x in self.requirements.all()]
|
||||
relavant_qualifications = 0.0
|
||||
# TODO Efficiency...
|
||||
for req in needed_qualifications:
|
||||
if user.is_user_qualified_in(req.item, req.depth):
|
||||
relavant_qualifications += 1.0
|
||||
|
||||
if len(needed_qualifications) > 0:
|
||||
return round(len(relavant_qualifications) / len(needed_qualifications))
|
||||
return int(relavant_qualifications / float(len(needed_qualifications)) * 100)
|
||||
else:
|
||||
return 0
|
||||
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
{% extends 'base_rigs.html' %}
|
||||
|
||||
{% load user_has_qualification from filters %}
|
||||
{% load percentage_complete from filters %}
|
||||
{% load user_level_if_present from filters %}
|
||||
{% load user_has_qualification from tags %}
|
||||
{% load percentage_complete from tags %}
|
||||
{% load user_level_if_present from tags %}
|
||||
|
||||
{% block content %}
|
||||
<div class="col-sm-12 text-right">
|
||||
@@ -22,7 +22,7 @@
|
||||
<div class="progress mb-2">
|
||||
{% percentage_complete level object as completion %}
|
||||
|
||||
<div class="progress-bar progress-bar-striped" role="progressbar" style="width: 25%" aria-valuenow="{{completion}}" aria-valuemin="0" aria-valuemax="100">{{completion}}% complete</div>
|
||||
<div class="progress-bar progress-bar-striped" role="progressbar" style="width: {{completion}}%" aria-valuenow="{{completion}}" aria-valuemin="0" aria-valuemax="100">{{completion}}% complete</div>
|
||||
</div>
|
||||
|
||||
<button class="btn btn-link p-0" type="button" data-toggle="collapse" data-target=".reqs_{{level.pk}}" aria-expanded="false" aria-controls="reqs_{{level.pk}}">
|
||||
|
||||
0
training/templatetags/__init__.py
Normal file
0
training/templatetags/__init__.py
Normal file
25
training/templatetags/tags.py
Normal file
25
training/templatetags/tags.py
Normal file
@@ -0,0 +1,25 @@
|
||||
from django import forms
|
||||
from django import template
|
||||
from django.utils.html import escape
|
||||
from django.utils.safestring import SafeData, mark_safe
|
||||
from django.utils.text import normalize_newlines
|
||||
|
||||
from training import models
|
||||
|
||||
register = template.Library()
|
||||
|
||||
@register.simple_tag
|
||||
def user_has_qualification(user, item, depth):
|
||||
if models.TrainingItem.user_has_qualification(item, user, depth) is not None:
|
||||
return mark_safe("<span class='fas fa-check text-success'></span>")
|
||||
else:
|
||||
return mark_safe("<span class='fas fa-hourglass-start text-warning'></span>")
|
||||
|
||||
@register.simple_tag
|
||||
def user_level_if_present(user, level):
|
||||
return models.TrainingLevelQualification.objects.filter(trainee=user, level=level).first()
|
||||
|
||||
@register.simple_tag
|
||||
def percentage_complete(level, user):
|
||||
return level.percentage_complete(user)
|
||||
|
||||
Reference in New Issue
Block a user