Ejemplo n.º 1
0
class BaseX(object):
    @classmethod
    def retrieve_by_key_safe(cls, key_urlsafe):
        try:
            return ndb.Key(urlsafe=key_urlsafe).get()
        except:
            return None

    @classmethod
    def retrieve_by_id(cls, id):
        try:
            return cls.get_by_id(int(id))
        except ValueError:
            return None

    @classmethod
    def retrieve_one_by(cls, name, value):
        cls_db_list = cls.query(getattr(cls, name) == value).fetch(1)
        if cls_db_list:
            return cls_db_list[0]
        return None

    created_ago = ndb.ComputedProperty(
        lambda self: util.format_datetime_ago(self.created) \
            if self.created else None
      )
    modified_ago = ndb.ComputedProperty(
        lambda self: util.format_datetime_ago(self.modified) \
            if self.modified else None
      )

    created_utc = ndb.ComputedProperty(
        lambda self: util.format_datetime_utc(self.created) \
            if self.created else None
      )
    modified_utc = ndb.ComputedProperty(
        lambda self: util.format_datetime_utc(self.modified) \
            if self.modified else None
      )
Ejemplo n.º 2
0
 def modified_utc(self):
   return util.format_datetime_utc(self.modified) if self.modified else None
Ejemplo n.º 3
0
 def modified_utc(self):
   if not self.modified:
     return None
   return util.format_datetime_utc(self.modified)
Ejemplo n.º 4
0
 def created_utc(self):
   return util.format_datetime_utc(self.created) if self.created else None
Ejemplo n.º 5
0
 def created_utc(self):
   if not self.created:
     return None
   return util.format_datetime_utc(self.created)