From: Charles Connell Date: Mon, 14 Apr 2014 15:44:44 +0000 (-0400) Subject: Improve form layout X-Git-Tag: release-20150131~145 X-Git-Url: https://git.librecmc.org/?a=commitdiff_plain;h=943c481f1b9f8ca6636adb4ba82abbf6599def4b;p=oweals%2Fkarmaworld.git Improve form layout --- diff --git a/karmaworld/apps/courses/forms.py b/karmaworld/apps/courses/forms.py index da68634..d15bcda 100644 --- a/karmaworld/apps/courses/forms.py +++ b/karmaworld/apps/courses/forms.py @@ -124,7 +124,7 @@ class CourseForm(NiceErrorModelForm, DependentModelForm): # insert honeypot into a random order on the form. idx = random.randint(0, len(self.fields)) self.fields.insert(idx, settings.HONEYPOT_FIELD_NAME, - CharField(required=False, label=settings.HONEYPOT_LABEL) + CharField(required=False, label=mark_safe(settings.HONEYPOT_LABEL)) ) class Meta: diff --git a/karmaworld/apps/courses/views.py b/karmaworld/apps/courses/views.py index e355525..0838047 100644 --- a/karmaworld/apps/courses/views.py +++ b/karmaworld/apps/courses/views.py @@ -4,7 +4,6 @@ """ Views for the KarmaNotes Courses app """ import json -g from django.conf import settings from django.core import serializers from django.core.exceptions import MultipleObjectsReturned @@ -51,6 +50,7 @@ class CourseListView(View): ret = self.get(request, *args, **kwargs) # Replace blank form with invalid form. ret.context_data['course_form'] = badform + ret.context_data['jump_to_form'] = True return ret diff --git a/karmaworld/assets/css/home.css b/karmaworld/assets/css/home.css index bec3a49..8b0be41 100644 --- a/karmaworld/assets/css/home.css +++ b/karmaworld/assets/css/home.css @@ -42,3 +42,27 @@ select.course-sort { padding: 5px 5px 5px 5px; } +#add-course-form p { + margin: 0 0 0 0; +} + +#add-course-form .results_on_deck { + margin-top: -10px; +} + +.required-field { + opacity: 0.5; +} + +ul.validation_error { + margin: 0 0 0 0; + list-style-type: none; +} + +label.validation_error { + color: #F04124; +} + +.add-course-field { + min-height: 100px; +} diff --git a/karmaworld/settings/common.py b/karmaworld/settings/common.py index 4556914..5792d31 100644 --- a/karmaworld/settings/common.py +++ b/karmaworld/settings/common.py @@ -387,7 +387,7 @@ TAGGIT_STOPWORDS = [u'a', u'an', u'and', u'be', u'from', u'of'] # https://github.com/sunlightlabs/django-honeypot HONEYPOT_FIELD_NAME = "instruction_url" # see that "_url"? bots gotta want that. HONEYPOT_VALUE = "" -HONEYPOT_LABEL = "Do not fill in this field (we need to make sure you're not a robot)" +HONEYPOT_LABEL = "Do not fill in this field (we need to make sure you're not a robot)" HONEYPOT_ERROR = "You did not follow directions." ########## END HONEYPOT CONFIGURATION diff --git a/karmaworld/templates/courses/course_list.html b/karmaworld/templates/courses/course_list.html index d817f90..230684d 100644 --- a/karmaworld/templates/courses/course_list.html +++ b/karmaworld/templates/courses/course_list.html @@ -13,10 +13,7 @@ {% block pagescripts %} diff --git a/karmaworld/templates/partial/add_course.html b/karmaworld/templates/partial/add_course.html index fc9327a..f109a48 100644 --- a/karmaworld/templates/partial/add_course.html +++ b/karmaworld/templates/partial/add_course.html @@ -4,8 +4,11 @@
× + +

Add a new course to KarmaNotes

+
- {% csrf_token %} + {% csrf_token %} {% if course_form.non_field_errors %}
@@ -17,7 +20,32 @@
{% endif %} - {{ course_form.as_p|safe }} + +
+ {% for form in course_form.get_forms.itervalues %} + {% for hidden in form.hidden_fields %} + {{ hidden }} + {% endfor %} + {% for field in form.visible_fields %} +
+ {{ field.errors|safe }} + + {{ field }} +
+ {% endfor %} + {% endfor %} + + {% for hidden in course_form.hidden_fields %} + {{ hidden }} + {% endfor %} + {% for field in course_form.visible_fields %} +
+ {{ field.errors|safe }} + + {{ field }} +
+ {% endfor %} +
diff --git a/karmaworld/utils/forms.py b/karmaworld/utils/forms.py index 4025870..5bb6b11 100644 --- a/karmaworld/utils/forms.py +++ b/karmaworld/utils/forms.py @@ -101,7 +101,7 @@ class DependentModelForm(ModelForm): self.dependent_modelforms_data = {} super(DependentModelForm, self).__init__(*args, **kwargs) - def _get_forms(self): + def get_forms(self): """ Memoize dependent form objects. """ # Determine if there is data. with_data = True if self.data else False @@ -128,7 +128,7 @@ class DependentModelForm(ModelForm): selfmedia = superself.media # search through each dependent form for media - for modelform in self._get_forms().itervalues(): + for modelform in self.get_forms().itervalues(): if inspect.ismethod(modelform.media): media = modelform.media() else: @@ -148,7 +148,7 @@ class DependentModelForm(ModelForm): """ Check all subforms for validity and then this form. """ all_valid = True # Perform validation and error checking for each ModelForm. - for attribute, modelform in self._get_forms().iteritems(): + for attribute, modelform in self.get_forms().iteritems(): if not modelform.is_valid(): all_valid = False @@ -172,7 +172,7 @@ class DependentModelForm(ModelForm): return # create foreign model object and associate it internally here - for attribute, modelform in self._get_forms().iteritems(): + for attribute, modelform in self.get_forms().iteritems(): # handle ManyToMany versus ForeignKey if not is_m2m(self, attribute): # Handle Foreign Key, assign object directly to attribute @@ -185,7 +185,7 @@ class DependentModelForm(ModelForm): # Check for and update any M2M model_fields if hasattr(self.instance, 'pk') and self.instance.pk: # objects were created during commit. associate M2M now. - for attribute, modelform in self._get_forms().iteritems(): + for attribute, modelform in self.get_forms().iteritems(): # handle ManyToMany versus ForeignKey if is_m2m(self, attribute): # use add() to create association between models. @@ -200,7 +200,7 @@ class DependentModelForm(ModelForm): # call "super" old_save_m2m() # associate M2M objects with self instance - for attribute, modelform in self._get_forms().iteritems(): + for attribute, modelform in self.get_forms().iteritems(): # ManyToMany contract test. # use add() to create association between models. objattr = getattr(instance, attribute, None) @@ -217,7 +217,7 @@ class DependentModelForm(ModelForm): """ Render dependent forms prior to rendering this form. """ html = '' # render each form - for modelform in self._get_forms().itervalues(): + for modelform in self.get_forms().itervalues(): html += getattr(modelform, method)(*args, **kwargs) # render this form supermethod = getattr(super(DependentModelForm, self), method)