Source

ytl / db.py

Full commit
__author__ = 'juha'

from google.appengine.ext import db
from google.appengine.api import users


class Group(db.Model):
  created = db.DateTimeProperty(auto_now_add=True)
  name = db.StringProperty(required=True)
  email = db.EmailProperty(required=True)


class Contact(db.Model):
  group = db.ReferenceProperty(Group)
  substituted_by = db.SelfReferenceProperty()
  firstname = db.StringProperty(required=True)
  lastname = db.StringProperty(required=True)
  street = db.PostalAddressProperty()
  zipcode = db.StringProperty()
  municipality = db.StringProperty()
  phones = db.ListProperty(str)
  email = db.EmailProperty()
  areas = db.ListProperty(str)
  created = db.DateTimeProperty(auto_now_add=True)
  comment = db.StringProperty()
  available = db.BooleanProperty(default=True)

  def __json__(self):
    return {
      'id': self.key().id(),
      'key': str(self.key()),
      'firstname': self.firstname,
      'lastname': self.lastname,
      'group_key': str(self.group.key()) if self.group else None
    }


class UpdateRequest(Contact):
  TYPE_CREATE = 2
  TYPE_UPDATE = 1
  TYPE_DELETE = 0
  requested_by = db.StringProperty()
  requested = db.DateTimeProperty()
  type = db.StringProperty(choices=(TYPE_CREATE, TYPE_UPDATE, TYPE_DELETE))
  note = db.StringProperty()


class ChangeLog(db.Model):
  created_by = users.get_current_user()
  changed = db.DateTimeProperty(auto_now_add=True)