Source

codeShare / dbModels.py

Full commit
from google.appengine.ext import db

#Library DB model
class Library(db.Model):
    name = db.StringProperty(required=True)
    owner = db.UserProperty(required=True)
    
    @staticmethod
    def getLibByName(libname):
        '''getLibByName -- returns library by library name'''
        return db.GqlQuery("SELECT * FROM Library WHERE name = :1", libname).get()    



#CodeFile DB model
class CodeFile(db.Model):
    filename = db.StringProperty(required=True)  
    content = db.TextProperty()
    library = db.ReferenceProperty(reference_class=Library, required=True)
    #directory = db.ReferenceProperty(required=True)
    creator = db.UserProperty(required=True)
    creationdate = db.DateTimeProperty(auto_now_add=True)
    lastchangedby = db.UserProperty(required=True)
    date = db.DateTimeProperty(auto_now=True)
    editor = db.StringProperty() #temporary value, will be pulled from memcache each time
    
    @staticmethod
    def getFile(lib, filename):
        '''getFile -- returns the file by library name and filename'''
        return db.GqlQuery("SELECT * FROM CodeFile WHERE library = :1 AND filename = :2", lib, filename).get()

    

#Chat DB model
class Chat(db.Model):
    author = db.UserProperty(required=True)
    content = db.StringProperty(multiline=True)
    date = db.DateTimeProperty(auto_now_add=True)
    library = db.ReferenceProperty(reference_class=Library)
    file = db.ReferenceProperty(reference_class=CodeFile)
    
    
        
#Right DB Model - User rights on library
class Right(db.Model):
    username = db.StringProperty(required=True)
    lib = db.ReferenceProperty(reference_class=Library, required=True)
    type = db.StringProperty(choices=set(['manage', 'write', 'read']), required=True)
    
    @staticmethod
    def getRight(username, libname):
        '''getRight -- returns right (dbModels.Right()) by username, libname'''
        lib = Library.getLibByName(libname)
        if lib is None:
            return None
        return db.GqlQuery("SELECT * FROM Right WHERE username = :1 and lib = :2", username, lib).get()