Skip to content
Snippets Groups Projects
Verified Commit 45a6509f authored by Nik | Klampfradler's avatar Nik | Klampfradler
Browse files

Make codepoint and colour properly configurable.

parent e0061719
No related branches found
No related tags found
No related merge requests found
...@@ -7,8 +7,17 @@ ...@@ -7,8 +7,17 @@
-->{% endfor %} -->{% endfor %}
</div> </div>
<link rel="stylesheet" href="{% static 'django_starfield.css' %}" /> <link rel="stylesheet" href="{% static 'django_starfield.css' %}" />
{% if codepoint %}
<style type="text/css"> <style type="text/css">
#django-starfield-{{ widget.name }} label::before { #django-starfield-{{ widget.name }} label::before {
content: '\{{ codepoint }}'; content: '\{{ codepoint }}';
} }
</style> </style>
{% endif %}
{% if colour %}
<style type="text/css">
#django-starfield-{{ widget.name }} label {
color: {{ colour }};
}
</style>
{% endif %}
from django.config import settings
from django.forms.widgets import Widget from django.forms.widgets import Widget
from . import defaults
settings.configure(default_settings=defaults)
class Stars(Widget): class Stars(Widget):
template_name = 'django_starfield/stars.html' 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) 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): def get_context(self, name, value, attrs):
context = super(Stars, self).get_context(name, value, attrs) context = super(Stars, self).get_context(name, value, attrs)
context['stars'] = range(self.stars, 0, -1) 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 return context
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment