/models/text.py

https://github.com/gfxmonk/savemytext.appspot.com · Python · 32 lines · 25 code · 7 blank · 0 comment · 3 complexity · 0f9eb5d3b04974ca11e7ab5f8e12dd62 MD5 · raw file

  1. from google.appengine.ext import db
  2. from logging import debug, info, warning, error
  3. from base import BaseModel
  4. class Text(BaseModel):
  5. title = db.StringProperty(required=False)
  6. content = db.TextProperty()
  7. owner = db.UserProperty(required=True)
  8. expanded = db.BooleanProperty(default=True)
  9. def __init__(self, *a, **k):
  10. super(type(self), self).__init__(**k)
  11. if not self.title:
  12. self.title = "(untitled)"
  13. @classmethod
  14. def add(cls, owner):
  15. text = cls(owner=owner, content='', title='')
  16. text.save()
  17. return text
  18. @classmethod
  19. def find_all(cls, owner):
  20. return db.Query(cls).filter('owner =', owner).order('title').fetch(limit=50)
  21. @classmethod
  22. def find(cls, owner, key):
  23. text = cls.get(key)
  24. if text and text.owner == owner:
  25. return text