Beispiel #1
0
    def __init__(self,
                 queryset,
                 empty_label=u"---------",
                 cache_choices=False,
                 required=True,
                 widget=None,
                 label=None,
                 initial=None,
                 help_text=None,
                 to_field_name=None,
                 *args,
                 **kwargs):
        if required and (initial is not None):
            self.empty_label = None
        else:
            self.empty_label = empty_label
        self.cache_choices = cache_choices

        # Call Field instead of ChoiceField __init__() because we don't need
        # ChoiceField.__init__().
        Field.__init__(self, required, widget, label, initial, help_text,
                       *args, **kwargs)
        self.queryset = queryset
        self.choice_cache = None
        self.to_field_name = to_field_name
Beispiel #2
0
    def __init__(
        self,
        queryset,
        empty_label=u"---------",
        cache_choices=False,
        required=True,
        widget=None,
        label=None,
        initial=None,
        help_text=None,
        to_field_name=None,
        *args,
        **kwargs
    ):
        if required and (initial is not None):
            self.empty_label = None
        else:
            self.empty_label = empty_label
        self.cache_choices = cache_choices

        # Call Field instead of ChoiceField __init__() because we don't need
        # ChoiceField.__init__().
        Field.__init__(self, required, widget, label, initial, help_text, *args, **kwargs)
        self.queryset = queryset
        self.choice_cache = None
        self.to_field_name = to_field_name
Beispiel #3
0
    def __init__(self, to, to_field=None, rel_class=ListRelation, **kwargs):
        contains_built_in_type = False
        try:
            to_name = to._meta.object_name.lower()
        except AttributeError: # to._meta doesn't exist, so it must be RECURSIVE_RELATIONSHIP_CONSTANT
            # to._meta doesn't exist is it a basic type
            if is_accepted_type(to):
                contains_built_in_type = True
                
            #assert isinstance(to, basestring), "%s(%r) is invalid. First parameter to ForeignKey must be either a model, a model name, or the string %r" % (self.__class__.__name__, to, RECURSIVE_RELATIONSHIP_CONSTANT)
        else:
            #assert not to._meta.abstract, "%s cannot define a relation with abstract class %s" % (self.__class__.__name__, to._meta.object_name)
            # For backwards compatibility purposes, we need to *try* and set
            # the to_field during FK construction. It won't be guaranteed to
            # be correct until contribute_to_class is called. Refs #12190.
            to_field = to_field 
        kwargs['verbose_name'] = kwargs.get('verbose_name', None)


        kwargs['rel'] = rel_class(self, to, to_field,
            related_name=kwargs.pop('related_name', None),
            limit_choices_to=kwargs.pop('limit_choices_to', None),
            lookup_overrides=kwargs.pop('lookup_overrides', None),
            parent_link = False,
            xml_element_name = kwargs.get('xml_element_name', 'item'),
            contains_built_in_type = contains_built_in_type)
        Field.__init__(self, **kwargs)
        if self.min_length is not None:
            self.validators.append(MinListLengthValidator(self.min_length))
        if self.max_length is not None:
            self.validators.append(MaxListLengthValidator(self.max_length))
Beispiel #4
0
 def __init__(self):
     Field.__init__(self)
     scriptList.register(self)
     from kivy.app import App
     def inner(*args):
         self.stack = App.get_running_app().root.ids['deck'].ids['stack']
     from kivy.clock import Clock
     Clock.schedule_once(inner,1)
Beispiel #5
0
 def __init__(self, queryset, empty_label=u"---------", cache_choices=False,
         required=True, widget=Select, label=None, initial=None, help_text=None):
     self.queryset = queryset
     self.empty_label = empty_label
     self.cache_choices = cache_choices
     # Call Field instead of ChoiceField __init__() because we don't need
     # ChoiceField.__init__().
     Field.__init__(self, required, widget, label, initial, help_text)
     self.widget.choices = self.choices
Beispiel #6
0
 def __init__(self,
              queryset,
              empty_label=u"---------",
              cache_choices=False,
              required=True,
              widget=Select,
              label=None,
              initial=None,
              help_text=None):
     self.queryset = queryset
     self.empty_label = empty_label
     self.cache_choices = cache_choices
     # Call Field instead of ChoiceField __init__() because we don't need
     # ChoiceField.__init__().
     Field.__init__(self, required, widget, label, initial, help_text)
     self.widget.choices = self.choices
Beispiel #7
0
    def __init__(self, to, to_field=None, rel_class=OneOnOneRelation, **kwargs):
        try:
            to_name = to._meta.object_name.lower()
        except AttributeError: # to._meta doesn't exist, so it must be RECURSIVE_RELATIONSHIP_CONSTANT
            if is_accepted_type_one_of(to):
                contains_built_in_type = True
            else:    
                assert isinstance(to, basestring), "%s(%r) is invalid. First parameter to related object must be either a model, a model name, or the string %r" % (self.__class__.__name__, to, RECURSIVE_RELATIONSHIP_CONSTANT)
        else:
            #assert not to._meta.abstract, "%s cannot define a relation with abstract class %s" % (self.__class__.__name__, to._meta.object_name)
            # For backwards compatibility purposes, we need to *try* and set
            # the to_field during FK construction. It won't be guaranteed to
            # be correct until contribute_to_class is called. Refs #12190.
            to_field = to_field
        kwargs['verbose_name'] = kwargs.get('verbose_name', None)

        kwargs['rel'] = rel_class(self,to, to_field,
            related_name=kwargs.pop('related_name', None),
            limit_choices_to=kwargs.pop('limit_choices_to', None),
            lookup_overrides=kwargs.pop('lookup_overrides', None),
            parent_link=kwargs.pop('parent_link', False))
        Field.__init__(self, **kwargs)