def __init__(self, network, id, core): self.manager = core.manager self.events = core.events if self.need_vbox_init: # make sure we don't call this an extra time when mutating Gtk.VBox.__init__(self, False) self.need_vbox_init = False if hasattr(self, "buffer"): self.output = widgets.TextOutput(core, self, self.buffer) else: self.output = widgets.TextOutput(core, self) self.buffer = self.output.get_buffer() if hasattr(self, "input"): if self.input.parent: self.input.parent.remove(self.input) else: self.input = widgets.TextInput(self, core) self.network = network self.rawid = id self.__activity = set()
class BaseField(object): ''' Simple container class which ancestors represents various parts of Form. Encapsulates converter, various fields attributes, methods for data access control ''' #: :class:`FieldPerm` instance determining field's access permissions. #: Can be set by field inheritance or throught constructor. perm_getter = FieldPerm() # defaults conv = convs.Char widget = widgets.TextInput() label = None media = FormMedia() def __init__(self, name, conv=None, parent=None, **kwargs): kwargs.update( dict( parent=parent, name=name, conv=(conv or self.conv)(field=self), widget=(kwargs.get('widget') or self.widget)(field=self), )) self._init_kwargs = kwargs self.__dict__.update(kwargs) def __call__(self, **kwargs): ''' Creates current object's copy with extra constructor arguments passed. ''' params = dict(self._init_kwargs, **kwargs) return self.__class__(**params) @property def multiple(self): return self.conv.multiple @property def env(self): return self.parent.env @property def form(self): return self.parent.form @property def input_name(self): ''' Name of field's input element generated in account to possible nesting of fields. The input name is to be used in templates as value of Input (Select, etc) element's Name attribute and Label element's For attribute. ''' if self.name is None: return self.parent.input_name return self.parent.prefix + self.name @property def error(self): return self.form.errors.get(self.input_name) @property def clean_value(self): ''' Current field's converted value from form's python_data. ''' return self.parent.python_data[self.name] @cached_property def _relative_id(self): # XXX what is this? return self.form.get_field_id(self) @property def id(self): # We use template names in list to replace, so we must use it here to # insure unique IDs. return '%s-%s' % (self.form.id, self.input_name) def to_python(self, value): return self.conv.to_python(value) def from_python(self, value): return self.conv.from_python(value) @cached_property def permissions(self): ''' Returns field's access permissions ''' return self.perm_getter.get_perms(self) @cached_property def writable(self): return 'w' in self.permissions @cached_property def readable(self): return 'r' in self.permissions @property def render_type(self): return self.widget.render_type def render(self): return self.widget.render(self.raw_value) def get_media(self): media = FormMedia(self.media) media += self.widget.get_media() return media
class TextField(wtforms.fields.TextField): widget = widgets.TextInput()
class IntegerField(wtforms.fields.IntegerField): widget = widgets.TextInput()
class DecimalField(wtforms.fields.DecimalField): widget = widgets.TextInput()
class DateTimeField(wtforms.fields.DateTimeField): widget = widgets.TextInput(uniform_extra_classes=['dateTimeInput'])