Ivan Melnikov avatar Ivan Melnikov committed 8b7befb Draft

Send notification to cluster subscribers

Comments (0)

Files changed (1)

 
 def notify(page_id, from_email):
 	page = Page.get_by_id(page_id)
+	# notify page subscribers
 	users = Subscribe.all(keys_only=True).filter('page', page_id)
 	for user in users:
 		u = User.get_by_id(user.id())
-		log.info('Notify user %s about page %s updated', u.name, page.path)
-		mail.send_mail(sender=from_email,
-              to=u.email,
-              subject='Page "%s" updated' % page.path,
-              body='''
-              Page %s updated
-              ''' % page.path)
+		_send_notification(u, page, from_email)
+	
+	# notify cluster subscribers
+	for path in index_path(page.path):
+		deferred.defer(_notify_path, path, page, from_email)
+	
+def _notify_path(path, page, from_email):
+	log.info('Notify users in %s about page %s updated', path, page.path)
+	cluster = get_page(path)
+	if cluster is None: return
+
+	users = Subscribe.all(keys_only=True).filter('cluster', cluster.key().id())
+	for user in users:
+		u = User.get_by_id(user.id())
+		_send_notification(u, page, from_email)
+
+def _send_notification(u, page, from_email):
+	log.info('Notify user %s about page %s updated', u.name, page.path)
+	mail.send_mail(sender=from_email,
+				to=u.email,
+				subject='Page "%s" updated' % page.path,
+				body='''
+				Page %s updated
+				''' % page.path)
 
 
 ##################
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.