Beispiel #1
0
	def follow(self):
		db.following.save(vars(self))

		# Notification for the Followee
		notification = Notification(uid=self.followee)
		notification.make_follow(follower_id=self.follower)
		notification.save()
		
		return self
Beispiel #2
0
def add_like_to_sheet(sheet_id, uid):
	"""
	Add uid as a liker of sheet_id.
	"""
	db.sheets.update({"id": sheet_id}, {"$addToSet": {"likes": uid}})
	sheet = get_sheet(sheet_id)

	notification = Notification(uid=sheet["owner"])
	notification.make_sheet_like(liker_id=uid, sheet_id=sheet_id)
	notification.save()
Beispiel #3
0
def notifications_read_api(request):
	"""
	API for marking notifications as read

	Takes JSON in the "notifications" parameter of an array of 
	notifcation ids as strings.
	"""
	if request.method == "POST":
		notifications = request.POST.get("notifications")
		if not notifications:
			return jsonResponse({"error": "'notifications' post parameter missing."})
		notifications = json.loads(notifications)
		for id in notifications:
			notification = Notification(_id=id)
			if notification.uid != request.user.id: 
				# Only allow expiring your own notifications
				continue
			notification.mark_read().save()

		return jsonResponse({"status": "ok"})

	else:
		return jsonResponse({"error": "Unsupported HTTP method."})