Ejemplo n.º 1
0
class Collection(model.Model):  # key_name=urlname, parent=Publisher
    """Model for a collection of records."""
    name = model.StringProperty('n', required=True)
    urlname = model.ComputedProperty(lambda self: urlname(self.name))
    owner = model.UserProperty('o', required=True)
    admins = model.UserProperty('a', repeated=True)
    created = model.DateTimeProperty('c', auto_now_add=True)
    updated = model.DateTimeProperty('u', auto_now=True)
    json = model.TextProperty('j', required=True)  # JSON representation

    @classmethod
    def create(cls, name, publisher_key):
        return Collection(
            parent=publisher_key,
            id=urlname(name),
            name=name,
            owner=users.get_current_user(),
            json=simplejson.dumps(dict(
                    name=name,
                    admin=users.get_current_user().nickname(),
                    url='http://%s.%s.appspot.com/publishers/%s/%s' % \
                        (appver, appid, publisher_key.id(), urlname(name)))))

    @classmethod
    def get_by_urlname(cls, urlname, publisher_key):
        return model.Key('Collection', urlname, parent=publisher_key).get()

    @classmethod
    def all_by_publisher(cls, publisher_key):
        return Collection.query(ancestor=publisher_key).fetch()
Ejemplo n.º 2
0
class Publisher(model.Model):  # key_name=urlname
    """Model for a VertNet data Publisher."""
    name = model.StringProperty('n', required=True)
    urlname = model.ComputedProperty(lambda self: urlname(self.name))
    owner = model.UserProperty('o', required=True)
    admins = model.UserProperty('a', repeated=True)
    created = model.DateTimeProperty('c', auto_now_add=True)
    updated = model.DateTimeProperty('u', auto_now=True)
    json = model.TextProperty('j', required=True)  # JSON representation

    @classmethod
    def create(cls, name):
        return Publisher(
            id=urlname(name),
            name=name,
            owner=users.get_current_user(),
            json=simplejson.dumps(dict(
                    url='http://%s.%s.appspot.com/publishers/%s' % \
                        (appver, appid, urlname(name)),
                    name=name,
                    admin=users.get_current_user().nickname())))

    @classmethod
    def get_by_urlname(cls, urlname):
        return model.Key('Publisher', urlname).get()
Ejemplo n.º 3
0
 class MyModel(model.Model):
     bb = model.BooleanProperty('b')
     pp = model.IntegerProperty('p')
     qq = model.StringProperty('q')
     dd = model.FloatProperty('d')
     kk = model.KeyProperty('k')
     uu = model.UserProperty('u')
     xxyy = model.GeoPtProperty('xy')
Ejemplo n.º 4
0
 class MyModel(model.Model):
     b = model.BooleanProperty()
     p = model.IntegerProperty()
     q = model.StringProperty()
     d = model.FloatProperty()
     k = model.KeyProperty()
     u = model.UserProperty()
     xy = model.GeoPtProperty()
Ejemplo n.º 5
0
class Record(model.Model):  # key_name=record.occurrenceid, parent=Collection
    """Model for a record."""
    owner = model.UserProperty('u', required=True)
    record = model.TextProperty(
        'r', required=True)  # darwin core json representation
    created = model.DateTimeProperty('c', auto_now_add=True)
    updated = model.DateTimeProperty('u', auto_now=True)

    @classmethod
    def create(cls, rec, collection_key):
        return Record(parent=collection_key,
                      id=rec['occurrenceid'],
                      owner=users.get_current_user(),
                      record=simplejson.dumps(rec))

    @classmethod
    def all_by_collection(cls, collection_key):
        return Record.query(ancestor=collection_key).fetch()