class MoraNone(db.MoraPolyModel): int_ = db.IntegerProperty() float_ = db.FloatProperty() bool_ = db.BooleanProperty() str_ = db.StringProperty() txt = db.TextProperty() byte_str = db.ByteStringProperty() blob = db.BlobProperty() date = db.DateProperty() time = db.TimeProperty() datetime = db.DateTimeProperty() geopt = db.GeoPtProperty() address = db.PostalAddressProperty() phone = db.PhoneNumberProperty() email = db.EmailProperty() user = db.UserProperty() im = db.IMProperty() link = db.LinkProperty() category = db.CategoryProperty() rating = db.RatingProperty() reference = db.ReferenceProperty() self_reference = db.SelfReferenceProperty() blob_reference = db.BlobReferenceProperty() list_ = db.ListProperty(int) str_list = db.StringListProperty()
class Ingredient(db.Model): """A D20 character.""" name = db.StringProperty() price = db.FloatProperty("Price per unit volume (USD/liter)") abv = db.IntegerProperty("Alcohol content by volume as a percentage") @property def proof(self): return self.abv * 2 def __unicode__(self): return self.name
class Drink(db.Model): name = db.StringProperty() ingredients = DictProperty() @property def price(self): raise NotImplementedError() @property def abv(self): raise NotImplementedError() @property def volume(self): raise NotImplementedError() def __unicode__(self): return name
class Widget(db.MoraModel): # Primitives int_ = db.IntegerProperty(default=13) float_ = db.FloatProperty(default=1.3) bool_ = db.BooleanProperty(default=True) str_ = db.StringProperty(default='word') text = db.TextProperty(default='word word word') # Temporal date = db.DateProperty(default=datetime.date(1983, 10, 11)) time = db.TimeProperty(default=datetime.time(1)) datetime = db.DateTimeProperty(default=datetime.datetime(1983, 10, 11)) # Binary data byte_str = db.ByteStringProperty(default=b'word') blob = db.BlobProperty(default=b'blobword') #blob_ref = db.BlobReferenceProperty(default='fake') # Special Google Data Protocol & GeoRSS GML Properties # These are XML like properties that correspond to GDP and GeoRSS geopt = db.GeoPtProperty(default=db.GeoPt(lat=1.3, lon=1.3)) address = db.PostalAddressProperty( default=db.PostalAddress("1600 Ampitheater Pkwy., Mountain View, CA")) phone = db.PhoneNumberProperty(default=db.PhoneNumber("1 (206) 555-1212")) email = db.EmailProperty(default=db.Email("*****@*****.**")) im = db.IMProperty(default=db.IM("http://example.com/", "Larry97")) link = db.LinkProperty(default=db.Link("http://www.google.com/")) category = db.CategoryProperty(default=db.Category("kittens")) rating = db.RatingProperty(default=db.Rating(97)) # Special User Property # TODO: test user property # user = db.UserProperty(default=users.User( # email='*****@*****.**', # federated_identity='fake')) # References reference = db.ReferenceProperty(None) self_reference = db.SelfReferenceProperty() # Lists list_ = db.ListProperty(int, default=[13]) str_list = db.StringListProperty(default=['one'])
class Art(db.Model): title = db.StringProperty(required=True) # this is done due to StringProperty size limitation art = db.TextProperty(required=True) created = db.DateTimeProperty(auto_now_add=True)
from tools import Handler +from google.appengine.ext import db class Hello(Handler): @@ -16,3 +17,30 @@ class ShoppingList(Handler): def get(self): items = self.request.get_all("food") self.render("shopping_list.html", title="Shopping List", items=items) + +class Art(db.Model): + title = db.StringProperty(required = True) + art = db.TextProperty(required = True) + created = db.DateTimeProperty(auto_now_add = True) + +class AsciiChan(Handler): + + def render_front(self, title="", art="", error=""): + arts = db.GqlQuery("SELECT * FROM Art ORDER BY created DESC") + self.render("asciichan.html", title=title, art=art, error=error, arts=arts) + + def get(self): + self.render_front() + + @db.transactional + def post(self): + title = self.request.get("title") + art = self.request.get("art") + + if title and art: + a = Art(title=title, art=art)
class Post(db.Model): title = db.StringProperty(required=True)
self.render('index.html', **posts_dic) class New(BaseHandler): def get(self): self.render('new.html) def post(self): subject = self.request.get('subject') content = self.request.get('content') blog_post = Post(title=subject, content=content) blog_post.put() self.redirect('/') class About(BaseHandler): def get(self): self.render('about.html') class Post(db.Model): title = db.StringProperty(required=True) content = db.StringProperty(required=True) adddate = db.dateTimeProperty(auto_now_add=True) app = webapp2.WSGIApplication([ ('/', Home), ('/about', About) ], debug=True)