Author: adrian
Date: 2007-01-23 14:26:35 -0600 (Tue, 23 Jan 2007)
New Revision: 4405
Removed:
django/branches/newforms-admin/django/contrib/admin/templates/widget/date_time.html
Modified:
django/branches/newforms-admin/django/contrib/admin/options.py
django/branches/newforms-admin/django/contrib/admin/widgets.py
Log:
newforms-admin: DateTimeFields are now properly split into two widgets in the
admin interface, using the new SplitDateTimeField and SplitDateTimeWidget
Modified: django/branches/newforms-admin/django/contrib/admin/options.py
===================================================================
--- django/branches/newforms-admin/django/contrib/admin/options.py
2007-01-23 20:24:20 UTC (rev 4404)
+++ django/branches/newforms-admin/django/contrib/admin/options.py
2007-01-23 20:26:35 UTC (rev 4405)
@@ -207,6 +207,10 @@
if isinstance(db_field, models.ManyToManyField) and
db_field.rel.filter_interface:
widget = widgets.FilteredSelectMultiple(db_field.verbose_name,
db_field.rel.filter_interface-1)
return db_field.formfield(widget=widget, **kwargs)
+ # For DateTimeFields, use a special field and widget.
+ if isinstance(db_field, models.DateTimeField):
+ return forms.SplitDateTimeField(required=not db_field.blank,
+ widget=widgets.AdminSplitDateTime(),
label=capfirst(db_field.verbose_name), **kwargs)
return db_field.formfield(**kwargs)
def has_add_permission(self, request):
Deleted:
django/branches/newforms-admin/django/contrib/admin/templates/widget/date_time.html
===================================================================
---
django/branches/newforms-admin/django/contrib/admin/templates/widget/date_time.html
2007-01-23 20:24:20 UTC (rev 4404)
+++
django/branches/newforms-admin/django/contrib/admin/templates/widget/date_time.html
2007-01-23 20:26:35 UTC (rev 4405)
@@ -1,5 +0,0 @@
-{% load i18n %}
-<p class="datetime">
- {% trans "Date:" %} {{ bound_field.form_fields.0 }}<br />
- {% trans "Time:" %} {{ bound_field.form_fields.1 }}
-</p>
Modified: django/branches/newforms-admin/django/contrib/admin/widgets.py
===================================================================
--- django/branches/newforms-admin/django/contrib/admin/widgets.py
2007-01-23 20:24:20 UTC (rev 4404)
+++ django/branches/newforms-admin/django/contrib/admin/widgets.py
2007-01-23 20:26:35 UTC (rev 4405)
@@ -3,6 +3,7 @@
"""
from django import newforms as forms
+import datetime
class FilteredSelectMultiple(forms.SelectMultiple):
"""
@@ -19,9 +20,24 @@
def render(self, name, value, attrs=None, choices=()):
from django.conf import settings
output = [super(FilteredSelectMultiple, self).render(name, value,
attrs, choices)]
- output.append('<script type="text/javascript">addEvent(window, "load",
function(e) {')
+ output.append(u'<script type="text/javascript">addEvent(window,
"load", function(e) {')
# TODO: "id_" is hard-coded here. This should instead use the correct
# API to determine the ID dynamically.
- output.append('SelectFilter.init("id_%s", "%s", %s, "%s");
});</script>\n' % \
+ output.append(u'SelectFilter.init("id_%s", "%s", %s, "%s");
});</script>\n' % \
(name, self.verbose_name.replace('"', '\\"'),
int(self.is_stacked), settings.ADMIN_MEDIA_PREFIX))
- return ''.join(output)
+ return u''.join(output)
+
+class AdminSplitDateTime(forms.SplitDateTimeWidget):
+ """
+ A SplitDateTime Widget that has some admin-specific styling.
+ """
+ def __init__(self, attrs=None):
+ widgets = [forms.TextInput(attrs={'class': 'vDateField', 'size':
'10'}),
+ forms.TextInput(attrs={'class': 'vTimeField', 'size': '8'})]
+ # Note that we're calling MultiWidget, not SplitDateTimeWidget, because
+ # we want to define widgets.
+ forms.MultiWidget.__init__(self, widgets, attrs)
+
+ def format_output(self, rendered_widgets):
+ return u'<p class="datetime">%s %s<br />%s %s</p>' % \
+ (_('Date:'), rendered_widgets[0], _('Time:'), rendered_widgets[1])
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Django updates" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at
http://groups.google.com/group/django-updates?hl=en
-~----------~----~----~----~------~----~------~--~---