def create(data, notifData=None): """ Create an event document. Parameters: data - a dictionary of the event data. notifData - a dictionary of data to be sent in the notifications. Returns: an event document. """ db = core.connect() theTime = utils.utctime() data["created"] = theTime data["modified"] = theTime # create notification events notifications = stream.notifications(data["streamId"]) for userId in notifications: create({ "createdBy": data.get("createdBy"), "displayString": data.get("displayString"), "streamId": user.messageStream(userId), "unread": True, "content": data.get("content") }) newEvent = schema.event() newEvent.update(data) newEvent["type"] = "event" return db.create(newEvent)
def update(data): """ Update a user document. Parameters: data - a dictionary containing the fields to update. Should not attempt to update _id, _rev, type, joined, lastSeen. """ data["modified"] = utils.utctime() return core.update(data)
def updateLastSeen(userName): """ Update the last seen field of the specified user. Stores the current time. Parameters: userName - the user name. """ db = core.connect() theUser = readFull(userName, False) theUser["lastSeen"] = utils.utctime() db[theUser["_id"]] = theUser
def favorite(id, userId): db = core.connect() if (not canRead(id, userId)) or isFavorited(id, userId): return fav = { "created": utils.utctime(), "createdBy": userId, "type": "favorite" } db[favoriteId(id, userId)] = fav return joinData(db[id], userId)
def update(id, data): """ Update a shift in the database. Parameters: id - a shift id. data - a dictinary of shift fields to update. Returns: a dictionary representing the updated shift document. """ db = core.connect() theShift = db[id] theShift.update(data) theShift["modified"] = utils.utctime() db[id] = theShift return db[id]
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 create(data): """ Create a shift in the database. Parameters: data - the new data for the shift. Returns: The id of the new shift (string). """ db = core.connect() theTime = utils.utctime() data["created"] = theTime data["modified"] = theTime data["domain"] = utils.domain(data["href"]) newShift = schema.shift() newShift.update(data) newShift["type"] = "shift" id = db.create(newShift) newShift = db[id] return joinData(newShift, newShift["createdBy"])
def update(data): """ Update an event document. Parameters: data - dictionary of key-values to update. Returns: an event document. """ db = core.connect() id = data["id"] doc = db[id] doc.update(data) doc["modified"] = utils.utctime() if core.validate(doc): db[id] = doc return db[id] else: # TODO: throw an exception - David 7/9/09 return None
def create(data, add=True): """ Create a stream. Will fail if: 1. createdBy field missing. Parameters: data - the data for the new stream. add - whether this should be added to the user's list of stream. Defaults to True. Returns: The id of the newly created stream. """ db = core.connect() data["created"] = utils.utctime() newStream = schema.stream() newStream.update(data) userId = newStream["createdBy"] if not userId: raise MissingCreatorError newStream["type"] = "stream" id = db.create(newStream) if add: user.addStream(userId, id) return db[id]