diff --git a/colleges/templates/colleges/potentialfellowship_list.html b/colleges/templates/colleges/potentialfellowship_list.html index fbe6de2540a977fb9173710ecc625750c4635278..0fa8ce291258052c86a14a6dc9d20599693b536f 100644 --- a/colleges/templates/colleges/potentialfellowship_list.html +++ b/colleges/templates/colleges/potentialfellowship_list.html @@ -1,6 +1,7 @@ {% extends 'colleges/base.html' %} {% load scipost_extras %} +{% load colleges_extras %} {% load bootstrap %} @@ -69,7 +70,7 @@ $(document).ready(function($) { <div class="single d-inline" data-specialization="{{expertise|lower}}" data-toggle="tooltip" data-placement="bottom" title="{{expertise|get_specialization_display}}">{{expertise|get_specialization_code}}</div> {% endfor %} </td> - <td>{{ potfel.get_status_display }}</td> + <td style="color: #ffffff; background-color:{{ potfel.status|potfelstatuscolor }};">{{ potfel.get_status_display }}</td> </tr> {% empty %} <tr> diff --git a/colleges/templatetags/colleges_extras.py b/colleges/templatetags/colleges_extras.py new file mode 100644 index 0000000000000000000000000000000000000000..d0a10eceb9560daad8525c3d9e6be8ebda4c75ef --- /dev/null +++ b/colleges/templatetags/colleges_extras.py @@ -0,0 +1,48 @@ +__copyright__ = "Copyright 2016-2018, Stichting SciPost (SciPost Foundation)" +__license__ = "AGPL v3" + + +from django import template + +from ..constants import ( + POTENTIAL_FELLOWSHIP_IDENTIFIED, POTENTIAL_FELLOWSHIP_INVITED, POTENTIAL_FELLOWSHIP_REINVITED, + POTENTIAL_FELLOWSHIP_MULTIPLY_REINVITED, POTENTIAL_FELLOWSHIP_DECLINED, + POTENTIAL_FELLOWSHIP_UNRESPONSIVE, POTENTIAL_FELLOWSHIP_RETIRED, POTENTIAL_FELLOWSHIP_DECEASED, + POTENTIAL_FELLOWSHIP_INTERESTED, POTENTIAL_FELLOWSHIP_REGISTERED, + POTENTIAL_FELLOWSHIP_ACTIVE_IN_COLLEGE, POTENTIAL_FELLOWSHIP_SCIPOST_EMERITUS + ) + +from common.utils import hslColorWheel + + +register = template.Library() + + +@register.filter(name='potfelstatuscolor') +def potfelstatuscolor(status): + color = '#333333' + if status == POTENTIAL_FELLOWSHIP_IDENTIFIED: + color = hslColorWheel(12, 8) + elif status == POTENTIAL_FELLOWSHIP_INVITED: + color = hslColorWheel(12, 9) + elif status == POTENTIAL_FELLOWSHIP_REINVITED: + color = hslColorWheel(12, 10) + elif status == POTENTIAL_FELLOWSHIP_MULTIPLY_REINVITED: + color = hslColorWheel(12, 11) + elif status == POTENTIAL_FELLOWSHIP_DECLINED: + color = hslColorWheel(12, 0) + elif status == POTENTIAL_FELLOWSHIP_UNRESPONSIVE: + color = hslColorWheel(12, 1) + elif status == POTENTIAL_FELLOWSHIP_RETIRED: + color = hslColorWheel(12, 1, 75) + elif status == POTENTIAL_FELLOWSHIP_DECEASED: + color = hslColorWheel(12, 1, 10) + elif status == POTENTIAL_FELLOWSHIP_INTERESTED: + color = hslColorWheel(12, 2) + elif status == POTENTIAL_FELLOWSHIP_REGISTERED: + color = hslColorWheel(12, 3) + elif status == POTENTIAL_FELLOWSHIP_ACTIVE_IN_COLLEGE: + color = hslColorWheel(12, 4) + elif status == POTENTIAL_FELLOWSHIP_SCIPOST_EMERITUS: + color = hslColorWheel(12, 4, 40, 40) + return color diff --git a/common/utils.py b/common/utils.py index cdbb65c174398fa1f5b1df176cd9c9a534d23240..0edde7a732a107ba3beb620cbd66ed9ff8b64c43 100644 --- a/common/utils.py +++ b/common/utils.py @@ -7,6 +7,22 @@ from django.core.mail import EmailMultiAlternatives from django.template import loader +def hslColorWheel(N=10, index=0, saturation=50, lightness=50): + """ + Distributes colors into N values around a color wheel, + according to hue-saturation-lightness (HSL). + + index takes values from 0 to N-1. + """ + hue = int(index * 360/N % 360) + saturation = max(saturation, 0) + saturation = min(saturation, 100) + lightness = max(lightness, 0) + lightness = min(lightness, 100) + + return 'hsl(%s, %s%%, %s%%)' % (str(hue), str(saturation), str(lightness)) + + def workdays_between(datetime_from, datetime_until): """Return number of complete workdays.