Source

codeShare / dbModels.py

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()
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.