示例#1
0
def convert_form_initial_to_local(form):
    converted = form.initial.copy()
    for name, field in form.fields.iteritems():
        if not name in form.initial:
            continue
        value = form.initial[name]
        if isinstance(field, fields.DateTimeField) or isinstance(field, fields.TimeField):
            value = convert_initial_to_local(value, form.timezone)
        converted[name] = value
    form.initial = converted
示例#2
0
 def form_post_clean(form, *args, **kwargs):
     if form._errors:
         converted = form.data.copy()
         for name, field in form.fields.iteritems():
             if not name in form.data:
                 continue
             value = form.data[name]
             if isinstance(field, fields.DateTimeField) or isinstance(field, fields.TimeField):
                 value = convert_initial_to_local(value, form.timezone)
             converted[name] = value
         form.data = converted
     super(form_class, form)._post_clean(*args, **kwargs)