Skip to content

Instantly share code, notes, and snippets.

@maciekrb
Created April 10, 2014 22:00

Revisions

  1. maciekrb created this gist Apr 10, 2014.
    28 changes: 28 additions & 0 deletions User Variables
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,28 @@
    class VariableGroup(EndpointsModel):
    _message_fields_schema = ('name', 'id', 'tags', 'identifier')
    acl = ndb.StructuredProperty(AclRule)
    tag_keys = ndb.KeyProperty(kind='Tag', repeated=True)
    group_id = ndb.StringProperty()
    name = ndb.StringProperty()

    @property
    def identifier(self):
    if self.group_id is None:
    self.group_id = int(random.random() * 10000)
    return "vgroup_{}".format(self.group_id)

    @EndpointsAliasProperty(repeated=True, property_type=Tag.ProtoModel())
    def tags(self):
    if self.tag_keys:
    return ndb.get_multi(self.tag_keys)


    class Variable(EndpointsModel):
    _message_fields_schema = ('value', 'id', 'groupid')
    acl = ndb.StructuredProperty(AclRule)
    group_key = ndb.KeyProperty(kind='VariableGroup')
    value = ndb.GenericProperty()

    @EndpointsAliasProperty(repeated=True, property_type=Tag.ProtoModel())
    def groupid(self):
    return self.group_key.id()