Exemple #1
0
 def pre_save(self, model_instance, add):
     value = getattr(model_instance, self.name)
     if value:
         return value
     if self.unique:
         values = model_instance.__class__.objects.values_list(self.name, flat=True)
     else:
         values = []
     value = randomic(self.max_length)
     while value in values:
         value = randomic(self.max_length)
     return value
Exemple #2
0
 def __init__(self, url=None, id_=None, attrs=None, show=True, help_text=None, 
              readonly=False, side_html=None, label_value=None, 
              search_fields=None, manager_name=None, qs_filter=None, **options):
     self.help_text = help_text
     self.show = show
     self.attrs = attrs and attrs.copy() or {}
     self.id_ = id_ or randomic()
     self.url = url
     self.readonly = readonly
     self.side_html = side_html
     
     options['extraParams'] = options.get('extraParams', {})
     if label_value:
         options['extraParams']['label_value'] = label_value
     if search_fields:
         if not isinstance(search_fields, (tuple, list)):
             raise ValueError('`search_fields` deve ser lista ou tupla')
         options['extraParams']['search_fields'] = u','.join(search_fields)
     if manager_name:
         if not isinstance(manager_name, basestring):
             raise ValueError('`manager_name` deve ser basestring')
         options['extraParams']['manager_name'] = manager_name
     if qs_filter:
         if not isinstance(qs_filter, basestring):
             raise ValueError('`qs_filter` deve ser basestring')
         options['extraParams']['qs_filter'] = qs_filter
     
     set_autocomplete_options(self, options)
     super(AutocompleteWidget, self).__init__(self.attrs)
Exemple #3
0
 def __init__(self, url=None, id_=None, attrs=None, show=True, help_text=None, readonly=False,
              side_html=None, label_value=None, **options):
     # TODO: o `label_value` poderia passar uma funcao como parametro, o que
     # retiraria a obrigação de fazer um método na classe de modelo.
     """
     ``id_``: autocomplete input id (default: randomic).
     ``url``: autocomplete search url (if not supplied, autocomplete will be 
              readonly); this url must return "<label>|<id>\n<label>|<id>..".
     """
     self.help_text = help_text
     self.show = show
     self.attrs = attrs and attrs.copy() or {}
     self.id_ = id_ or randomic()
     self.url = url
     self.readonly = readonly
     self.side_html = side_html
     if label_value:
         extraParams = options.get('extraParams', {})
         extraParams['label_value'] = label_value
         options['extraParams'] = extraParams
     set_autocomplete_options(self, options)
     super(AutocompleteWidget, self).__init__(self.attrs)
Exemple #4
0
 def __init__(self, id_=None, root_nodes=None, attrs={}):
     self.id_ = id_ or randomic()
     super(TreeWidget, self).__init__(attrs)
     self.root_nodes = root_nodes
Exemple #5
0
 def __init__(self, id_=None, root_nodes=None, attrs={}):
     self.id_ = id_ or randomic()
     super(TreeWidget, self).__init__(attrs)
     self.root_nodes = root_nodes