Python google.appengine.ext.db.StringProperty() Examples
The following are 9
code examples of google.appengine.ext.db.StringProperty().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
google.appengine.ext.db
, or try the search function
.
Example #1
Source File: prefix.py From personfinder with Apache License 2.0 | 6 votes |
def add_prefix_properties(model_class, *properties): """Adds indexable properties to a model class to support prefix queries. All properties ending in '_' are extra properties. The 'properties' arguments should be names of existing string properties on the class.""" for property in properties: # This property contains a copy of the entire string normalized. setattr(model_class, property + '_n_', db.StringProperty()) # This property contains just the first character, normalized. setattr(model_class, property + '_n1_', db.StringProperty()) # This property contains just the first two characters, normalized. setattr(model_class, property + '_n2_', db.StringProperty()) # Record the prefix properties. if not hasattr(model_class, '_prefix_properties'): model_class._prefix_properties = [] model_class._prefix_properties += list(properties) # Update the model class. db._initialize_properties( model_class, model_class.__name__, model_class.__bases__, model_class.__dict__)
Example #2
Source File: db.py From jbox with MIT License | 5 votes |
def get_TextField(kwargs): """ Returns a ``TextField``, applying the ``db.StringProperty`` length limit of 500 bytes. """ kwargs['validators'].append(validators.length(max=500)) return f.TextField(**kwargs)
Example #3
Source File: db.py From jbox with MIT License | 5 votes |
def convert_StringProperty(model, prop, kwargs): """Returns a form field for a ``db.StringProperty``.""" if prop.multiline: kwargs['validators'].append(validators.length(max=500)) return f.TextAreaField(**kwargs) else: return get_TextField(kwargs)
Example #4
Source File: db.py From RSSNewsGAE with Apache License 2.0 | 5 votes |
def get_TextField(kwargs): """ Returns a ``TextField``, applying the ``db.StringProperty`` length limit of 500 bytes. """ kwargs['validators'].append(validators.length(max=500)) return f.TextField(**kwargs)
Example #5
Source File: db.py From RSSNewsGAE with Apache License 2.0 | 5 votes |
def convert_StringProperty(model, prop, kwargs): """Returns a form field for a ``db.StringProperty``.""" if prop.multiline: kwargs['validators'].append(validators.length(max=500)) return f.TextAreaField(**kwargs) else: return get_TextField(kwargs)
Example #6
Source File: db.py From googleapps-message-recall with Apache License 2.0 | 5 votes |
def get_TextField(kwargs): """ Returns a ``TextField``, applying the ``db.StringProperty`` length limit of 500 bytes. """ kwargs['validators'].append(validators.length(max=500)) return f.TextField(**kwargs)
Example #7
Source File: db.py From googleapps-message-recall with Apache License 2.0 | 5 votes |
def convert_StringProperty(model, prop, kwargs): """Returns a form field for a ``db.StringProperty``.""" if prop.multiline: kwargs['validators'].append(validators.length(max=500)) return f.TextAreaField(**kwargs) else: return get_TextField(kwargs)
Example #8
Source File: djangoforms.py From python-compat-runtime with Apache License 2.0 | 5 votes |
def get_form_field(self, **kwargs): """Return a Django form field appropriate for a string property. This sets the widget default to forms.Textarea if the property's multiline attribute is set. """ defaults = {} if self.multiline: defaults['widget'] = forms.Textarea defaults.update(kwargs) return super(StringProperty, self).get_form_field(**defaults)
Example #9
Source File: djangoforms.py From python-compat-runtime with Apache License 2.0 | 4 votes |
def save(self, commit=True): """Save this form's cleaned data into a model instance. Args: commit: optional bool, default True; if true, the model instance is also saved to the datastore. Returns: A model instance. If a model instance was already associated with this form instance (either passed to the constructor with instance=... or by a previous save() call), that same instance is updated and returned; if no instance was associated yet, one is created by this call. Raises: ValueError if the data couldn't be validated. """ if not self.is_bound: raise ValueError('Cannot save an unbound form') opts = self._meta instance = self.instance if instance is None: fail_message = 'created' else: fail_message = 'updated' if self.errors: raise ValueError("The %s could not be %s because the data didn't " 'validate.' % (opts.model.kind(), fail_message)) cleaned_data = self._cleaned_data() converted_data = {} propiter = itertools.chain( opts.model.properties().iteritems(), iter([('key_name', StringProperty(name='key_name'))]) ) for name, prop in propiter: value = cleaned_data.get(name) if value is not None: converted_data[name] = prop.make_value_from_form(value) try: if instance is None: instance = opts.model(**converted_data) self.instance = instance else: for name, value in converted_data.iteritems(): if name == 'key_name': continue setattr(instance, name, value) except db.BadValueError, err: raise ValueError('The %s could not be %s (%s)' % (opts.model.kind(), fail_message, err))