Top

telemeta.forms.boolean_form module

from django import forms

class BooleanSearch(forms.Form):

    def get_brackets(dir):
        list = []
        for i in range(4):
            brackets = ""
            for j in range(i):
                if dir=="left":
                    brackets+="( "
                elif dir=="right":
                    brackets+=") "
            list.append((brackets,brackets))
        return list

    boolean = forms.ChoiceField(choices=[('ET', 'ET',), ('OU', 'OU',)], label='', required=False)
    start_bracket = forms.ChoiceField(label='', choices=get_brackets('left'), required=False)
    text_field = forms.CharField(label='', widget=forms.TextInput(attrs={'required': ''}))
    end_bracket = forms.ChoiceField(label='', choices=get_brackets('right'), required=False)

Classes

class BooleanSearch

class BooleanSearch(forms.Form):

    def get_brackets(dir):
        list = []
        for i in range(4):
            brackets = ""
            for j in range(i):
                if dir=="left":
                    brackets+="( "
                elif dir=="right":
                    brackets+=") "
            list.append((brackets,brackets))
        return list

    boolean = forms.ChoiceField(choices=[('ET', 'ET',), ('OU', 'OU',)], label='', required=False)
    start_bracket = forms.ChoiceField(label='', choices=get_brackets('left'), required=False)
    text_field = forms.CharField(label='', widget=forms.TextInput(attrs={'required': ''}))
    end_bracket = forms.ChoiceField(label='', choices=get_brackets('right'), required=False)

Ancestors (in MRO)

  • BooleanSearch
  • django.forms.forms.Form
  • django.forms.forms.BaseForm
  • __builtin__.object

Class variables

var base_fields

var boolean

var end_bracket

var start_bracket

var text_field

Instance variables

var changed_data

var errors

Returns an ErrorDict for the data provided for the form

var media

Methods

def __init__(

self, data=None, files=None, auto_id=u'id_%s', prefix=None, initial=None, error_class=<class 'django.forms.util.ErrorList'>, label_suffix=None, empty_permitted=False)

def __init__(self, data=None, files=None, auto_id='id_%s', prefix=None,
             initial=None, error_class=ErrorList, label_suffix=None,
             empty_permitted=False):
    self.is_bound = data is not None or files is not None
    self.data = data or {}
    self.files = files or {}
    self.auto_id = auto_id
    self.prefix = prefix
    self.initial = initial or {}
    self.error_class = error_class
    # Translators: This is the default suffix added to form field labels
    self.label_suffix = label_suffix if label_suffix is not None else _(':')
    self.empty_permitted = empty_permitted
    self._errors = None # Stores the errors after clean() has been called.
    self._changed_data = None
    # The base_fields class attribute is the *class-wide* definition of
    # fields. Because a particular *instance* of the class might want to
    # alter self.fields, we create self.fields here by copying base_fields.
    # Instances should always modify self.fields; they should not modify
    # self.base_fields.
    self.fields = copy.deepcopy(self.base_fields)

def add_initial_prefix(

self, field_name)

Add a 'initial' prefix for checking dynamic initial values

def add_initial_prefix(self, field_name):
    """
    Add a 'initial' prefix for checking dynamic initial values
    """
    return 'initial-%s' % self.add_prefix(field_name)

def add_prefix(

self, field_name)

Returns the field name with a prefix appended, if this Form has a prefix set.

Subclasses may wish to override.

def add_prefix(self, field_name):
    """
    Returns the field name with a prefix appended, if this Form has a
    prefix set.
    Subclasses may wish to override.
    """
    return '%s-%s' % (self.prefix, field_name) if self.prefix else field_name

def as_p(

self)

Returns this form rendered as HTML

s.

def as_p(self):
    "Returns this form rendered as HTML <p>s."
    return self._html_output(
        normal_row = '<p%(html_class_attr)s>%(label)s %(field)s%(help_text)s</p>',
        error_row = '%s',
        row_ender = '</p>',
        help_text_html = ' <span class="helptext">%s</span>',
        errors_on_separate_row = True)

def as_table(

self)

Returns this form rendered as HTML s -- excluding the

.

def as_table(self):
    "Returns this form rendered as HTML <tr>s -- excluding the <table></table>."
    return self._html_output(
        normal_row = '<tr%(html_class_attr)s><th>%(label)s</th><td>%(errors)s%(field)s%(help_text)s</td></tr>',
        error_row = '<tr><td colspan="2">%s</td></tr>',
        row_ender = '</td></tr>',
        help_text_html = '<br /><span class="helptext">%s</span>',
        errors_on_separate_row = False)

def as_ul(

self)

Returns this form rendered as HTML

  • s -- excluding the
      .

    • def as_ul(self):
          "Returns this form rendered as HTML <li>s -- excluding the <ul></ul>."
          return self._html_output(
              normal_row = '<li%(html_class_attr)s>%(errors)s%(label)s %(field)s%(help_text)s</li>',
              error_row = '<li>%s</li>',
              row_ender = '</li>',
              help_text_html = ' <span class="helptext">%s</span>',
              errors_on_separate_row = False)
      

      def clean(

      self)

      Hook for doing any extra form-wide cleaning after Field.clean() been called on every field. Any ValidationError raised by this method will not be associated with a particular field; it will have a special-case association with the field named 'all'.

      def clean(self):
          """
          Hook for doing any extra form-wide cleaning after Field.clean() been
          called on every field. Any ValidationError raised by this method will
          not be associated with a particular field; it will have a special-case
          association with the field named '__all__'.
          """
          return self.cleaned_data
      

      def full_clean(

      self)

      Cleans all of self.data and populates self._errors and self.cleaned_data.

      def full_clean(self):
          """
          Cleans all of self.data and populates self._errors and
          self.cleaned_data.
          """
          self._errors = ErrorDict()
          if not self.is_bound: # Stop further processing.
              return
          self.cleaned_data = {}
          # If the form is permitted to be empty, and none of the form data has
          # changed from the initial data, short circuit any validation.
          if self.empty_permitted and not self.has_changed():
              return
          self._clean_fields()
          self._clean_form()
          self._post_clean()
      

      def get_brackets(

      dir)

      def get_brackets(dir):
          list = []
          for i in range(4):
              brackets = ""
              for j in range(i):
                  if dir=="left":
                      brackets+="( "
                  elif dir=="right":
                      brackets+=") "
              list.append((brackets,brackets))
          return list
      

      def has_changed(

      self)

      Returns True if data differs from initial.

      def has_changed(self):
          """
          Returns True if data differs from initial.
          """
          return bool(self.changed_data)
      

      def hidden_fields(

      self)

      Returns a list of all the BoundField objects that are hidden fields. Useful for manual form layout in templates.

      def hidden_fields(self):
          """
          Returns a list of all the BoundField objects that are hidden fields.
          Useful for manual form layout in templates.
          """
          return [field for field in self if field.is_hidden]
      

      def is_multipart(

      self)

      Returns True if the form needs to be multipart-encoded, i.e. it has FileInput. Otherwise, False.

      def is_multipart(self):
          """
          Returns True if the form needs to be multipart-encoded, i.e. it has
          FileInput. Otherwise, False.
          """
          for field in self.fields.values():
              if field.widget.needs_multipart_form:
                  return True
          return False
      

      def is_valid(

      self)

      Returns True if the form has no errors. Otherwise, False. If errors are being ignored, returns False.

      def is_valid(self):
          """
          Returns True if the form has no errors. Otherwise, False. If errors are
          being ignored, returns False.
          """
          return self.is_bound and not bool(self.errors)
      

      def non_field_errors(

      self)

      Returns an ErrorList of errors that aren't associated with a particular field -- i.e., from Form.clean(). Returns an empty ErrorList if there are none.

      def non_field_errors(self):
          """
          Returns an ErrorList of errors that aren't associated with a particular
          field -- i.e., from Form.clean(). Returns an empty ErrorList if there
          are none.
          """
          return self.errors.get(NON_FIELD_ERRORS, self.error_class())
      

      def visible_fields(

      self)

      Returns a list of BoundField objects that aren't hidden fields. The opposite of the hidden_fields() method.

      def visible_fields(self):
          """
          Returns a list of BoundField objects that aren't hidden fields.
          The opposite of the hidden_fields() method.
          """
          return [field for field in self if not field.is_hidden]