我们从Python开源项目中,提取了以下25个代码示例,用于说明如何使用google.appengine.ext.ndb.DateProperty()。
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_DateProperty(self, model, prop, kwargs): """Returns a form field for a ``ndb.DateProperty``.""" if prop._auto_now or prop._auto_now_add: return None return f.DateField(format='%Y-%m-%d', **kwargs)
def _get_for_dict(self, entity): value = super(DateProperty, self)._get_for_dict(entity) if not value: return None return str(value)
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_DateProperty(self, model, prop, kwargs): """Returns a form field for a ``ndb.DateProperty``.""" if prop._auto_now or prop._auto_now_add: return None kwargs.setdefault('format', '%Y-%m-%d') return f.DateField(**kwargs)
def testDateProperty_shouldConvertToString(self): self.__assert_conversion(ndb.DateProperty, DateTime)