changeset 951:5366c29d6dce

Django's SortedDict is gone. Use OrderedDict instead. For Django 1.7.8 upgrade.
author Brian Neal <bgneal@gmail.com>
date Sat, 16 May 2015 18:51:12 -0500
parents c614edb5b51e
children 0a2f23d5bec4 8647a669edb4
files forums/forms.py
diffstat 1 files changed, 12 insertions(+), 4 deletions(-) [+]
line wrap: on
line diff
--- a/forums/forms.py	Sat May 16 15:06:52 2015 -0500
+++ b/forums/forms.py	Sat May 16 18:51:12 2015 -0500
@@ -2,6 +2,8 @@
 Forms for the forums application.
 
 """
+from collections import OrderedDict
+
 from django import forms
 from django.conf import settings
 
@@ -161,10 +163,16 @@
         topic_name = kwargs.pop('topic_name', None)
         super(PostForm, self).__init__(*args, **kwargs)
 
-        if topic_name is not None:  # this is a "first post"
-            self.fields.insert(0, 'name', forms.CharField(label='Subject',
-                    max_length=255,
-                    widget=forms.TextInput(attrs={'size': 64})))
+        if topic_name is not None:
+            # this is a "first post", add a field for a topic name
+            new_fields = OrderedDict(name=forms.CharField(
+                            label='Subject', max_length=255,
+                            widget=forms.TextInput(attrs={
+                                'class': 'title',
+                                'style': 'width: 90%',
+                            })))
+            new_fields.update(self.fields)
+            self.fields = new_fields
             self.initial['name'] = topic_name
 
         attachments = args[0].getlist('attachment') if len(args) else []