Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Fixed #8163 -- Restore oldforms admin styling on input fields. Also c…

…leaned up some styles for both tabular and stacked inlines. Thanks Nathan Borror for the patch.

git-svn-id: http://code.djangoproject.com/svn/django/trunk@8240 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information...
commit 5d199ba90113c47caf142e79151315ba2dc02b4b 1 parent 5fb9599
Brian Rosner authored August 08, 2008
22  django/contrib/admin/media/css/forms.css
@@ -58,19 +58,21 @@ fieldset.monospace textarea { font-family:"Bitstream Vera Sans Mono",Monaco,"Cou
58 58
 .vLargeTextField, .vXMLLargeTextField { width:48em; }
59 59
 .flatpages-flatpage #id_content { height:40.2em; }
60 60
 .module table .vPositiveSmallIntegerField { width:2.2em; }
  61
+.vTextField { width:20em; }
  62
+.vIntegerField { width:5em; }
61 63
 
62 64
 /* x unsorted */
63  
-.inline-group {padding:10px; padding-bottom:5px; background:#eee; margin:10px 0;}
64  
-.inline-group h3.header {margin:-5px -10px 5px -10px; background:#bbb; color:#fff; padding:2px 5px 3px 5px; font-size:11px}
65  
-.inline-related {margin-bottom:15px; position:relative;}
66  
-.last-related {margin-bottom:0px;}
67  
-.inline-related h2 { margin:0; padding:2px 5px 3px 5px; font-size:11px; text-align:left; font-weight:bold;  color:#888; }
68  
-.inline-related h2 b {font-weight:normal; color:#aaa;}
69  
-.inline-related h2 span.delete {padding-left:20px; position:absolute; top:0px; right:5px;}
70  
-.inline-related h2 span.delete label {margin-left:2px; padding-top:1px;}
71  
-.inline-related fieldset {background:#fbfbfb;}
72  
-.inline-related fieldset.module h2 { margin:0; padding:2px 5px 3px 5px; font-size:11px; text-align:left; font-weight:bold; background:#bcd; color:#fff; }
  65
+.inline-group {padding:0; border:1px solid #ccc; margin:10px 0;}
  66
+.inline-group .aligned label { width: 7em; }
  67
+
  68
+.inline-related {position:relative;}
  69
+.inline-related h3 {margin: 0; color:#666; padding:3px 5px; font-size:11px; background:#e1e1e1 url(../img/admin/nav-bg.gif) top left repeat-x; border-bottom:1px solid #ddd;}
  70
+.inline-related h3 span.delete {padding-left:20px; position:absolute; top:2px; right:10px;}
  71
+.inline-related h3 span.delete label {margin-left:2px; font-size: 11px;}
  72
+.inline-related fieldset {margin: 0; background:#fff; border: none; }
  73
+.inline-related fieldset.module h3 { margin:0; padding:2px 5px 3px 5px; font-size:11px; text-align:left; font-weight:bold; background:#bcd; color:#fff; }
73 74
 .inline-related.tabular fieldset.module table {width:100%;}
  75
+.last-related fieldset {border: none;}
74 76
 
75 77
 .inline-group .tabular tr.has_original td {padding-top:2em;}
76 78
 .inline-group .tabular tr td.original { padding:2px 0 0 0; width:0; _position:relative; }
2  django/contrib/admin/media/css/global.css
@@ -97,7 +97,7 @@ input[type=submit].default:active { background-image:url(../img/admin/default-bg
97 97
 .module blockquote { margin-left:12px; }
98 98
 .module ul, .module ol { margin-left:1.5em; }
99 99
 .module h3 { margin-top:.6em; }
100  
-.module h2, .module caption { margin:0; padding:2px 5px 3px 5px; font-size:11px; text-align:left; font-weight:bold; background:#7CA0C7 url(../img/admin/default-bg.gif) top left repeat-x; color:white; }
  100
+.module h2, .module caption, .inline-group h2 { margin:0; padding:2px 5px 3px 5px; font-size:11px; text-align:left; font-weight:bold; background:#7CA0C7 url(../img/admin/default-bg.gif) top left repeat-x; color:white; }
101 101
 .module table { border-collapse: collapse; }
102 102
 
103 103
 /* MESSAGES & ERRORS */
21  django/contrib/admin/options.py
@@ -145,6 +145,7 @@ def formfield_for_dbfield(self, db_field, **kwargs):
145 145
                         'class': get_ul_class(self.radio_fields[db_field.name]),
146 146
                     }
147 147
                 )
  148
+                return db_field.formfield(**kwargs)
148 149
             else:
149 150
                 # Otherwise, use the default select widget.
150 151
                 return db_field.formfield(**kwargs)
@@ -164,7 +165,27 @@ def formfield_for_dbfield(self, db_field, **kwargs):
164 165
         if isinstance(db_field, models.TimeField):
165 166
             kwargs['widget'] = widgets.AdminTimeWidget
166 167
             return db_field.formfield(**kwargs)
  168
+        
  169
+        # For TextFields, add a custom CSS class.
  170
+        if isinstance(db_field, models.TextField):
  171
+            kwargs['widget'] = widgets.AdminTextareaWidget
  172
+            return db_field.formfield(**kwargs)
  173
+        
  174
+        # For URLFields, add a custom CSS class.
  175
+        if isinstance(db_field, models.URLField):
  176
+            kwargs['widget'] = widgets.AdminURLFieldWidget
  177
+            return db_field.formfield(**kwargs)
  178
+        
  179
+        # For IntegerFields, add a custom CSS class.
  180
+        if isinstance(db_field, models.IntegerField):
  181
+            kwargs['widget'] = widgets.AdminIntegerFieldWidget
  182
+            return db_field.formfield(**kwargs)
167 183
 
  184
+        # For TextInputs, add a custom CSS class.
  185
+        if isinstance(db_field, models.CharField):
  186
+            kwargs['widget'] = widgets.AdminTextInputWidget
  187
+            return db_field.formfield(**kwargs)
  188
+    
168 189
         # For FileFields and ImageFields add a link to the current file.
169 190
         if isinstance(db_field, models.ImageField) or isinstance(db_field, models.FileField):
170 191
             kwargs['widget'] = widgets.AdminFileWidget
6  django/contrib/admin/templates/admin/edit_inline/stacked.html
... ...
@@ -1,14 +1,14 @@
1 1
 {% load i18n %}
2 2
 <div class="inline-group">
  3
+  <h2>{{ inline_admin_formset.opts.verbose_name_plural|title }}</h2>
3 4
 {{ inline_admin_formset.formset.management_form }}
4  
-{# <h3 class="header">{{ inline_admin_formset.opts.verbose_name_plural|title }}</h3> #}
5 5
 {{ inline_admin_formset.formset.non_form_errors }}
6 6
 
7 7
 {% for inline_admin_form in inline_admin_formset %}
8 8
 <div class="inline-related {% if forloop.last %}last-related{% endif %}">
9  
-  <h2><b>{{ inline_admin_formset.opts.verbose_name|title }}:</b>&nbsp;{% if inline_admin_form.original %}{{ inline_admin_form.original }}{% else %} #{{ forloop.counter }}{% endif %}
  9
+  <h3><b>{{ inline_admin_formset.opts.verbose_name|title }}:</b>&nbsp;{% if inline_admin_form.original %}{{ inline_admin_form.original }}{% else %} #{{ forloop.counter }}{% endif %}
10 10
     {% if inline_admin_formset.formset.can_delete and inline_admin_form.original %}<span class="delete">{{ inline_admin_form.deletion_field.field }} {{ inline_admin_form.deletion_field.label_tag }}</span>{% endif %}
11  
-    </h2>
  11
+  </h3>
12 12
   {% if inline_admin_form.show_url %}
13 13
   <p><a href="/r/{{ inline_admin_form.original.content_type_id }}/{{ inline_admin_form.original.id }}/">View on site</a></p>
14 14
   {% endif %}
7  django/contrib/admin/templates/admin/edit_inline/tabular.html
@@ -19,7 +19,8 @@
19 19
                    
20 20
         <tr class="{% cycle row1,row2 %} {% if inline_admin_form.original or inline_admin_form.show_url %}has_original{% endif %}">
21 21
 
22  
-        <td class="original">{% if inline_admin_form.original or inline_admin_form.show_url %}<p>
  22
+        <td class="original">
  23
+          {% if inline_admin_form.original or inline_admin_form.show_url %}<p>
23 24
           {% if inline_admin_form.original %} {{ inline_admin_form.original }}{% endif %}
24 25
           {% if inline_admin_form.show_url %}<a href="/r/{{ inline_admin_form.original.content_type_id }}/{{ inline_admin_form.original.id }}/">View on site</a>{% endif %}
25 26
             </p>{% endif %}
@@ -46,7 +47,9 @@
46 47
           {% endfor %}
47 48
         {% endfor %}
48 49
                 
49  
-        {% if inline_admin_formset.formset.can_delete %}<td class="delete">{% if inline_admin_form.original %}{{ inline_admin_form.deletion_field.field }}{% endif %}</td>{% endif %}
  50
+        {% if inline_admin_formset.formset.can_delete %}
  51
+          <td class="delete">{% if inline_admin_form.original %}{{ inline_admin_form.deletion_field.field }}{% endif %}</td>
  52
+        {% endif %}
50 53
         
51 54
         </tr>
52 55
 
16  django/contrib/admin/widgets.py
@@ -208,3 +208,19 @@ def _has_changed(self, initial, data):
208 208
 
209 209
     def id_for_label(self, id_):
210 210
         return self.widget.id_for_label(id_)
  211
+
  212
+class AdminTextareaWidget(forms.Textarea):
  213
+    def __init__(self, attrs={}):
  214
+        super(AdminTextareaWidget, self).__init__(attrs={'class': 'vLargeTextField'})
  215
+
  216
+class AdminTextInputWidget(forms.TextInput):
  217
+    def __init__(self, attrs={}):
  218
+        super(AdminTextInputWidget, self).__init__(attrs={'class': 'vTextField'})
  219
+
  220
+class AdminURLFieldWidget(forms.TextInput):
  221
+    def __init__(self, attrs={}):
  222
+        super(AdminURLFieldWidget, self).__init__(attrs={'class': 'vURLField'})
  223
+
  224
+class AdminIntegerFieldWidget(forms.TextInput):
  225
+    def __init__(self, attrs={}):
  226
+        super(AdminIntegerFieldWidget, self).__init__(attrs={'class': 'vIntegerField'})

0 notes on commit 5d199ba

Please sign in to comment.
Something went wrong with that request. Please try again.