Ejemplo n.º 1
0
 def new_upvote(post, post_id):
     if not self.valid_post(post):
         return
     upvote = post.upvotes.filter('user ='******'Content-Type'] = 'application/json'
         obj = {
                 'success': False,
                 'message': 'You cant upvote your own post!'
                 }
         self.json(obj)
     elif upvote:
         self.response.headers['Content-Type'] = 'application/json'
         obj = {
                 'success': False,
                 'message': 'You can\'t upvote again'
                 }
         self.json(obj)
     else:
         upvote = models.Upvote(user=self.user, post=post)
         upvote.put()
         post = models.Post.get_by_id(int(post_id))
         obj = {
                 'success': True,
                 'message': ' ' + str(post.upvote + 1)
                 }
         self.json(obj)
Ejemplo n.º 2
0
def upvote(request):
    article_url = request.REQUEST.get('article_url')
    diff_v1 = request.REQUEST.get('diff_v1')
    diff_v2 = request.REQUEST.get('diff_v2')
    remote_ip = request.META.get('REMOTE_ADDR')
    article_id = Article.objects.get(url=article_url).id
    models.Upvote(article_id=article_id, diff_v1=diff_v1, diff_v2=diff_v2, creation_time=datetime.datetime.now(), upvoter_ip=remote_ip).save()
    return render_to_response('upvote.html')