Skip to content
Browse files

Restyle the question layout.

  • Loading branch information...
1 parent 8749d00 commit dcc7b6014e6f9151584029db5022a2f4cb3ff169 @malcolmt committed Aug 16, 2010
Showing with 48 additions and 8 deletions.
  1. +25 −0 general/form_helpers.py
  2. +6 −2 minerva/forms.py
  3. +8 −6 minerva/templates/minerva/question.html
  4. +9 −0 static/css/style.layout.css
View
25 general/form_helpers.py
@@ -0,0 +1,25 @@
+from django.forms import widgets
+from django.utils.encoding import force_unicode
+from django.utils.safestring import mark_safe
+
+class RadioFieldRenderer(widgets.RadioFieldRenderer):
+ """
+ A version of the standard RadioFieldRenderer class that labels the rendered
+ list with an identifiable class (via the render_class attr). Usage is
+ something like:
+
+ forms.ChoiceField(...,
+ widget=forms.RadioSelect(renderer=RadioFieldRenderer,
+ attrs={"render_class": "multichoice"}))
+ """
+
+ def __init__(self, name, value, attrs, choices):
+ self.render_class = attrs.pop("render_class", "")
+ super(RadioFieldRenderer, self).__init__(name, value, attrs, choices)
+
+ def render(self):
+ return mark_safe(u'<ul class="%s">\n%s\n</ul>' %
+ (self.render_class,
+ u'\n'.join([u'<li>%s</li>' % force_unicode(w) for w in self])))
+
+
View
8 minerva/forms.py
@@ -1,10 +1,14 @@
from django import forms as dj_forms
+
+from general import form_helpers
from minerva.models import UserProfile, Language
class QuestionForm(dj_forms.Form):
meta = dj_forms.CharField(widget=dj_forms.HiddenInput)
- answer = dj_forms.ChoiceField(choices=((False, 'False'), (True, 'True')),
- widget=dj_forms.RadioSelect)
+ answer = dj_forms.ChoiceField(label="Meaning?", choices=(),
+ widget=dj_forms.RadioSelect(
+ renderer=form_helpers.RadioFieldRenderer,
+ attrs={"render_class": "multichoice"}))
def __init__(self, *args, **kwargs):
question = kwargs.pop("question", None)
View
14 minerva/templates/minerva/question.html
@@ -1,4 +1,5 @@
{% extends "base.html" %}
+{% load form_utils %}
{% block content %}
{% if prev_word %}
@@ -9,12 +10,13 @@
<form action="" method="post">
{% csrf_token %}
- <p><strong>Question:</strong> {{ question }}</p>
- {{ form.answer.errors }}
- {{ form.answer }}
- {{ form.meta.errors }}
- {{ form.meta }}
- <input type="submit" value="Submit" />
+ <table>
+ <tr><th></th><td class="centered">{{ question }}</td></tr>
+ {% form_layout form %}
+ <tr class="button_row"><td></td>
+ <td><input type="submit" value="Submit" /></td><td></td>
+ </tr>
+ </table>
</form>
{% endblock %}
View
9 static/css/style.layout.css
@@ -5,6 +5,10 @@
margin-bottom: 1em;
}
+.centered {
+ text-align: center;
+}
+
#wrapper {
width: 1000px;
margin: 0 auto;
@@ -74,6 +78,11 @@ form th {
font-weight: bold;
}
+.multichoice li {
+ list-style: none;
+ line-height: 2em;
+}
+
form table .errors {
border: none;
color: #f00;

0 comments on commit dcc7b60

Please sign in to comment.
Something went wrong with that request. Please try again.