我们从Python开源项目中,提取了以下26个代码示例,用于说明如何使用google.appengine.ext.ndb.DateTimeProperty()。
def from_json(self, request_data): """ Update entity with new data from json. check for data to transform, if needed, perform operations and assign values to respective properties in entity. :param request_data: :return: """ for property, value in request_data.iteritems(): prop_type = self._properties.get(property) if prop_type: prop_value = value if isinstance(prop_type, (ndb.DateProperty, ndb.DateTimeProperty, ndb.TimeProperty)): prop_value = utils.date_from_str(prop_type, prop_value) elif isinstance(prop_type, ndb.KeyProperty): prop_value = ndb.Key(urlsafe=prop_value) setattr(self, property, prop_value)
def convert_DateTimeProperty(self, model, prop, kwargs): """Returns a form field for a ``ndb.DateTimeProperty``.""" if prop._auto_now or prop._auto_now_add: return None return f.DateTimeField(format='%Y-%m-%d %H:%M:%S', **kwargs)
def _get_for_dict(self, entity): value = super(DateTimeProperty, self)._get_for_dict(entity) if not value: return None return value.isoformat()
def date_from_str(prop_type, str_date): if isinstance(prop_type, ndb.DateProperty): return main_datetime.datetime.strptime(str_date, DATE_FORMAT) elif isinstance(prop_type, ndb.DateTimeProperty): return main_datetime.datetime.strptime(str_date, DATE_TIME_FORMAT) else: return main_datetime.datetime.strptime(str_date, TIME_FORMAT)
def convert_DateTimeProperty(self, model, prop, kwargs): """Returns a form field for a ``ndb.DateTimeProperty``.""" if prop._auto_now or prop._auto_now_add: return None kwargs.setdefault('format', '%Y-%m-%d %H:%M:%S') return f.DateTimeField(**kwargs)
def testDateTimeProperty_shouldConvertToString(self): self.__assert_conversion(ndb.DateTimeProperty, DateTime)
def __init__(self, model_type, ancestor_type=None, keep_history=True): self.model_type = model_type self.ancestor_type = ancestor_type self.model_name = model_type.__name__ self.keep_history = keep_history if self.keep_history: history_props = { 'date': ndb.DateTimeProperty(auto_now_add=True), 'obj': ndb.StructuredProperty(model_type, repeated=False), 'client_id': ndb.StringProperty(), } self.history_model = type( self.model_name + 'History', (ndb.Model,), history_props)