<section id="add-course-form" class="reveal-modal" data-reveal>
<a class="close-reveal-modal">×</a>
+
+ <h2>Add a new course to KarmaNotes</h2>
+
<form method="POST" action="{% url 'home' %}">
- {% csrf_token %}
+ {% csrf_token %}
{% if course_form.non_field_errors %}
<div class="row">
</div>
{% endif %}
- {{ course_form.as_p|safe }}
+
+ <div class="row">
+ {% for form in course_form.get_forms.itervalues %}
+ {% for hidden in form.hidden_fields %}
+ {{ hidden }}
+ {% endfor %}
+ {% for field in form.visible_fields %}
+ <div class="small-6 columns add-course-field">
+ {{ field.errors|safe }}
+ <label for="{{ field.id_for_label }}">{{ field.label }}:</label>
+ {{ field }}
+ </div>
+ {% endfor %}
+ {% endfor %}
+
+ {% for hidden in course_form.hidden_fields %}
+ {{ hidden }}
+ {% endfor %}
+ {% for field in course_form.visible_fields %}
+ <div class="small-6 columns end add-course-field">
+ {{ field.errors|safe }}
+ <label for="{{ field.id_for_label }}">{{ field.label }}:</label>
+ {{ field }}
+ </div>
+ {% endfor %}
+ </div>
<div class="row">
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
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:
""" 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
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
# 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.
# 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)
""" 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)