diff --git a/django_starfield/templates/django_starfield/stars.html b/django_starfield/templates/django_starfield/stars.html index 61b7d4bdcee79be37f45e1ad502e656bd2527fbe..f7ce3470078a7757237861f8a2dc63353fde5acd 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 c6886c7fad70a517f00aafd4fbd7fd3d4609f53e..4cdc30d550b06b1eca45d7de45a73b99a5fbea45 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