From 45a6509f5c0291e10cb52b16eef98fd5103718e8 Mon Sep 17 00:00:00 2001 From: Dominik George <nik@naturalnet.de> Date: Thu, 2 Aug 2018 14:20:18 +0200 Subject: [PATCH] Make codepoint and colour properly configurable. --- .../templates/django_starfield/stars.html | 9 ++++++++ django_starfield/widgets.py | 21 +++++++++++++++---- 2 files changed, 26 insertions(+), 4 deletions(-) diff --git a/django_starfield/templates/django_starfield/stars.html b/django_starfield/templates/django_starfield/stars.html index 61b7d4b..f7ce347 100644 --- a/django_starfield/templates/django_starfield/stars.html +++ b/django_starfield/templates/django_starfield/stars.html @@ -7,8 +7,17 @@ -->{% endfor %} </div> <link rel="stylesheet" href="{% static 'django_starfield.css' %}" /> +{% if codepoint %} <style type="text/css"> #django-starfield-{{ widget.name }} label::before { content: '\{{ codepoint }}'; } </style> +{% endif %} +{% if colour %} +<style type="text/css"> + #django-starfield-{{ widget.name }} label { + color: {{ colour }}; + } +</style> +{% endif %} diff --git a/django_starfield/widgets.py b/django_starfield/widgets.py index c6886c7..4cdc30d 100644 --- a/django_starfield/widgets.py +++ b/django_starfield/widgets.py @@ -1,15 +1,28 @@ +from django.config import settings from django.forms.widgets import Widget +from . import defaults + +settings.configure(default_settings=defaults) + class Stars(Widget): template_name = 'django_starfield/stars.html' - def __init__(self, attrs=None, stars=5, codepoint='2605'): + def __init__(self, attrs=None, stars=None, codepoint=None, colour=None): super(Stars, self).__init__(attrs) - self.stars = 5 - self.codepoint = codepoint + + if stars is None: + self.stars = settings.STARFIELD_STARS + if codepoint is None: + self.codepoint = settings.STARFIELD_CODEPOINT + if colour is None: + self.colour = settings.STARFIELD_COLOUR def get_context(self, name, value, attrs): context = super(Stars, self).get_context(name, value, attrs) context['stars'] = range(self.stars, 0, -1) - context['codepoint'] = self.codepoint + if not self.codepoint == defaults.STARFIELD_CODEPOINT: + context['codepoint'] = self.codepoint + if not self.colour == defaults.STARFIELD_COLOUR: + contect['colour'] = self.colour return context -- GitLab