Example #1
0
 def post(self, article_id):
     article = models.Article.get_by_id(int(article_id))
     user = models.User.get_current()
     models.Subscription.get_or_insert('%s-%s' % (article_id, user.key()), article=article, user=user)
     
     Notification.send(article.author.user.email(), subject='%s is watching your post.' % user.nickname, body='%s is watching your post "%s".\r\n\r\n%s/%s' % (user.nickname, article.title, self.request.host_url, article_id))
     
     return Action.Result.DEFAULT
Example #2
0
 def post(self, obj_class, obj_id):
     user = models.User.get_current()
     obj = models.Reputation(key_name = '%s-%s-%s' % (obj_class, obj_id, user.user.email), obj_class=obj_class, obj_id=int(obj_id), user=user, reputation=self.reputation).put()
     
     if obj_class == u'Article':
         Notification.send(obj.author.user.email(), subject='%s %ss your post.' % (user.nickname, self.reputation), body='%s %ss your post "%s".\r\n\r\n%s/%s' % (user.nickname, self.reputation, obj.title, self.request.host_url, obj_id))
     elif obj_class == u'Comment':
         Notification.send(obj.author.user.email(), subject='%s %ss your comment.' % (user.nickname, self.reputation), body='%s %ss your comment.\r\n\r\n\t%s\r\n%s/%s#comment-%s' % (user.nickname, self.reputation, obj.body, self.request.host_url, obj.article.key().id(), obj_id))
     
     return Action.Result.DEFAULT
Example #3
0
 def delete(self, article_id):
     article = models.Article.get_by_id(int(article_id))
     if article.author.user != users.get_current_user() and not users.is_current_user_admin():
         raise users.NotAllowedError(_('Only the author can delete this article.'))
     article.delete()
     
     subscribers = models.Subscription.get_user_list(article)
     author_email = article.author.user.email()
     if author_email in subscribers:
         subscribers.remove(author_email)
     if subscribers:
         Notification.send(subscribers, subject='"%s" has been deleted.' % article.title, body='"%s" has been deleted by %s .\r\n\r\n%s/%s' % (article.title, article.author.nickname, self.request.host_url, article_id))
     
     return Action.Result.DEFAULT
Example #4
0
 def post(self, article_id, comment_id=None):
     comment = models.Comment(
                                   article=models.Article.get_by_id(int(article_id)),
                                   author=models.User.get_current(),
                                   body=self.request.get('body'),
                                   )
     if comment_id is not None:
         comment.parent_comment = models.Comment.get_by_id(int(comment_id))
     self.comment = comment.save().to_dict()
     
     subscribers = models.Subscription.get_user_list(comment.article)
     author_email = comment.author.user.email()
     if author_email in subscribers:
         subscribers.remove(author_email)
     if subscribers:
         Notification.send(subscribers, subject='%s wrote a comment to "%s".' % (comment.author.nickname, comment.article.title), body='%s wrote a comment to "%s".\r\n\r\n\t%s\r\n\r\n%s/%s#comment-%s' % (comment.author.nickname, comment.article.title, comment.body, self.request.host_url, article_id, comment.key().id()))
     
     return Action.Result.DEFAULT
Example #5
0
 def put(self):
     params = self.get_json_payload()
     article_id = int(params['id'])
     article = models.Article.get_by_id(article_id)
     if article.author.user != users.get_current_user():
         raise users.NotAllowedError(_('Only the author can edit this article.'))        
     article.title = params['title']
     article.body = params['body']
     tag_string = params['tags']
     if tag_string:
         article.tags = models.Tag.save_all(tag_string.split(','))
     article.save()
     self.article = article
     self.tags = models.Tag.get(article.tags)
     
     subscribers = models.Subscription.get_user_list(article)
     author_email = article.author.user.email()
     if author_email in subscribers:
         subscribers.remove(author_email)
     if subscribers:
         Notification.send(subscribers, subject='"%s" has been updated.' % article.title, body='"%s" has been updated by %s.\r\n\r\n%s/%s' % (article.author.nickname, article.title, self.request.host_url, article_id))
     return Action.Result.DEFAULT