def create(data, createStreams=True): """ Create a new user. Parameters: data - a dictionary containing the new user's data. createStreams - defaults to True. If True, will generate the user's public, private, and message streams. """ db = core.connect() data["joined"] = utils.utctime() newUser = schema.user() newUser.update(data) newUser["type"] = "user" userId = db.create(newUser) userRef = ref(userId) # create public stream for user # for when the user publishes her/his own content publicStream = stream.create({ "objectRef": userRef, "uniqueName": ref(userId,"public"), "private": False, "meta": "public", "createdBy": userId }, False) # private stream for when shifts are sent directly to a user privateStream = stream.create({ "objectRef": userRef, "uniqueName": ref(userId,"private"), "private": True, "meta": "private", "createdBy": userId }, False) # create the message stream for the user messageStream = stream.create({ "objectRef": userRef, "uniqueName": ref(userId, "messages"), "private": True, "meta": "message", "createdBy": userId }, False) theUser = db[userId] theUser.update({ "messageStream": messageStream["_id"], "publicStream": publicStream["_id"], "privateStream": privateStream["_id"] }) db[userId] = theUser return db[userId]
def createCommentStream(id): """ Create a comment stream for a shift if it doesn't already exist. Parameters: id - a shift id. """ db = core.connect() theShift = db[id] commentStream = stream.create({ "meta": "comments", "objectRef": ref(id), "createdBy": theShift["createdBy"] }) return commentStream["_id"]
def create(data): data["meta"] = "group" newGroup = schema.group() newGroup.update(data) return stream.create(newGroup)