Upgrade to Pro — share decks privately, control downloads, hide ads and more …

“Forms are static” – “No, they aren't”

Markus H
June 02, 2015

“Forms are static” – “No, they aren't”

My talk from DjangoCon Europe 2015 in Cardiff, Wales

Markus H

June 02, 2015
Tweet

More Decks by Markus H

Other Decks in Technology

Transcript

  1. Hi, I’m Markus Holtermann • Django Core Developer • CS

    MSc Student @m_holtermann • github.com/MarkusH • markusholtermann.eu
  2. def modelform_factory(model, …): attrs = { ‘fields’: fields_for_model(model), ‘model’: model,

    } Meta = type(str('Meta'), (object,), attrs) class_attrs = {‘Meta’: Meta} class_name = model.__name__ + str('Form') return type( class_name, ModelForm, class_attrs )
  3. @formmodel_action('Send to admins') def send_admins(form_model, form, request): # label →

    value mapped_data = form.get_mapped_data() # construct message message = render_to_string( 'dynamic_forms/email.txt', { 'form': form_model, 'data': mapped_data}) # send data via mail mail_admins( “New form submission”, message )
  4. @dynamic_form_field class IntegerField(BaseDynamicFormField): cls = 'django.forms.EmailField' display_label = 'Email' class

    Meta: # attribute = [type, default, class] max_value = [int, None, forms.IntegerField] min_value = [int, None, forms.IntegerField]