mirror of
https://github.com/django/django.git
synced 2025-10-27 23:56:08 +00:00
@@ -104,6 +104,7 @@ class Media(object):
|
||||
getattr(combined, 'add_' + name)(getattr(other, '_' + name, None))
|
||||
return combined
|
||||
|
||||
|
||||
def media_property(cls):
|
||||
def _media(self):
|
||||
# Get the media property of the superclass, if it exists
|
||||
@@ -131,6 +132,7 @@ def media_property(cls):
|
||||
return base
|
||||
return property(_media)
|
||||
|
||||
|
||||
class MediaDefiningClass(type):
|
||||
"""
|
||||
Metaclass for classes that can have media definitions.
|
||||
@@ -162,6 +164,7 @@ class SubWidget(object):
|
||||
args.append(self.choices)
|
||||
return self.parent_widget.render(*args)
|
||||
|
||||
|
||||
class Widget(six.with_metaclass(MediaDefiningClass)):
|
||||
is_hidden = False # Determines whether this corresponds to an <input type="hidden">.
|
||||
needs_multipart_form = False # Determines does this widget need multipart form
|
||||
@@ -224,6 +227,7 @@ class Widget(six.with_metaclass(MediaDefiningClass)):
|
||||
"""
|
||||
return id_
|
||||
|
||||
|
||||
class Input(Widget):
|
||||
"""
|
||||
Base class for all <input> widgets (except type='checkbox' and
|
||||
@@ -279,10 +283,12 @@ class PasswordInput(TextInput):
|
||||
value = None
|
||||
return super(PasswordInput, self).render(name, value, attrs)
|
||||
|
||||
|
||||
class HiddenInput(Input):
|
||||
input_type = 'hidden'
|
||||
is_hidden = True
|
||||
|
||||
|
||||
class MultipleHiddenInput(HiddenInput):
|
||||
"""
|
||||
A widget that handles <input type="hidden"> for fields that have a list
|
||||
@@ -313,6 +319,7 @@ class MultipleHiddenInput(HiddenInput):
|
||||
return data.getlist(name)
|
||||
return data.get(name, None)
|
||||
|
||||
|
||||
class FileInput(Input):
|
||||
input_type = 'file'
|
||||
needs_multipart_form = True
|
||||
@@ -327,6 +334,7 @@ class FileInput(Input):
|
||||
|
||||
FILE_INPUT_CONTRADICTION = object()
|
||||
|
||||
|
||||
class ClearableFileInput(FileInput):
|
||||
initial_text = ugettext_lazy('Currently')
|
||||
input_text = ugettext_lazy('Change')
|
||||
@@ -379,7 +387,8 @@ class ClearableFileInput(FileInput):
|
||||
def value_from_datadict(self, data, files, name):
|
||||
upload = super(ClearableFileInput, self).value_from_datadict(data, files, name)
|
||||
if not self.is_required and CheckboxInput().value_from_datadict(
|
||||
data, files, self.clear_checkbox_name(name)):
|
||||
data, files, self.clear_checkbox_name(name)):
|
||||
|
||||
if upload:
|
||||
# If the user contradicts themselves (uploads a new file AND
|
||||
# checks the "clear" checkbox), we return a unique marker
|
||||
@@ -389,6 +398,7 @@ class ClearableFileInput(FileInput):
|
||||
return False
|
||||
return upload
|
||||
|
||||
|
||||
class Textarea(Widget):
|
||||
def __init__(self, attrs=None):
|
||||
# The 'rows' and 'cols' attributes are required for HTML correctness.
|
||||
@@ -515,6 +525,7 @@ class Select(Widget):
|
||||
output.append(self.render_option(selected_choices, option_value, option_label))
|
||||
return '\n'.join(output)
|
||||
|
||||
|
||||
class NullBooleanSelect(Select):
|
||||
"""
|
||||
A Select Widget intended to be used with NullBooleanField.
|
||||
@@ -849,6 +860,7 @@ class SplitDateTimeWidget(MultiWidget):
|
||||
return [value.date(), value.time().replace(microsecond=0)]
|
||||
return [None, None]
|
||||
|
||||
|
||||
class SplitHiddenDateTimeWidget(SplitDateTimeWidget):
|
||||
"""
|
||||
A Widget that splits datetime input into two <input type="hidden"> inputs.
|
||||
|
||||
Reference in New Issue
Block a user