Ejemplo n.º 1
0
def post_comment():
    comment = request.get_json()
    author = comment["author"]
    body = comment["body"]
    published_date = comment["published_Date"]
    article_id = comment["article_id"]
    success = utils.post_comment(author, body, published_date, article_id)
    return jsonify({'success': success})
Ejemplo n.º 2
0
	def post(self):
		action = cgi.escape(self.request.get('action'))
		
		if action == 'add_suggestion':
			restaurant = cgi.escape(self.request.get('restaurant'))
			if restaurant == '':
				self.error(400)
				return

			sug = Suggestion(restaurant=db.get(restaurant), author=self.currentuser, 
							 group=self.currentgroup)
			sug.put()
			self.currentuser.lastposted = date.today()
			self.currentuser.put()
			notify_suggestion(sug)
			
		elif action == "remove_suggestion":
			suggestion = cgi.escape(self.request.get('suggestion'))
			suggestion = db.get(suggestion)
			if suggestion.author.user == self.currentuser.user:
				suggestion.delete()	
			else:
				logging.error('user: %s tried to delete suggestion he doesn\'t own' % self.currentuser.nickname)

		elif action == "add_comment":
			text = cgi.escape(self.request.get('text'))
			suggestion = db.get(cgi.escape(self.request.get('suggestion')))
			post_comment(text, self.currentuser, suggestion)
			
		elif action == "remove_comment":
			comment = cgi.escape(self.request.get('comment'))
			comment = db.get(comment)
			if comment.author.user == self.currentuser.user:
				comment.delete()
			else:
				logging.error('user: %s tried to delete comment he doesn\'t own' % self.currentuser.nickname)

		else:
			self.error(400)
			return
		
		self.get()
Ejemplo n.º 3
0
    def post(self, thread_id):
        request_json = tornado.escape.json_decode(self.request.body)
        captcha_token = None
        if settings.TOKEN_HEADER in self.request.headers:
            captcha_token = self.request.headers.get(settings.TOKEN_HEADER)

        sql_cursor = SQL_CON.cursor()
        stat_code, ret_json = utils.post_comment(sql_cursor, thread_id,
                                                 request_json, captcha_token)
        sql_cursor.close()

        self.set_status(stat_code)
        self.write(ret_json)
Ejemplo n.º 4
0
def post(request):
	'''
	'''
	user = request.user
	if request.method == 'POST':
		form = CommentPostForm(request.POST)
		if form.is_valid():
			data = form.cleaned_data
			items = data['reply'].split('-')
			obj_type = items[0]
			obj_id = atoi(items[1])
			content = data['content']
			
			if obj_type == 'l':
				try:
					obj = Link.objects.get(id=obj_id)
				except:
					raise Http404
			elif obj_type == 'd':
				try:
					obj = Discuss.objects.get(id=obj_id)
				except:
					raise Http404
			else:
				raise Http404
			
			if data['parent']:
				parent_id = atoi(data['parent'])
				try:
					parent = Comment.objects.get(id=parent_id)
				except:
					parent = None
			else:
				parent = None
			
			
			c = post_comment(user, content, obj, parent)
			if c:
				return HttpResponseRedirect(reverse(show_comment, args=[c.id]))
	
	try:
		from_url = request.META['HTTP_REFERER']
		return HttpResponseRedirect(from_url)
	except KeyError:
		raise Http404
Ejemplo n.º 5
0
def post(request):
    '''
	'''
    user = request.user
    if request.method == 'POST':
        form = CommentPostForm(request.POST)
        if form.is_valid():
            data = form.cleaned_data
            items = data['reply'].split('-')
            obj_type = items[0]
            obj_id = atoi(items[1])
            content = data['content']

            if obj_type == 'l':
                try:
                    obj = Link.objects.get(id=obj_id)
                except:
                    raise Http404
            elif obj_type == 'd':
                try:
                    obj = Discuss.objects.get(id=obj_id)
                except:
                    raise Http404
            else:
                raise Http404

            if data['parent']:
                parent_id = atoi(data['parent'])
                try:
                    parent = Comment.objects.get(id=parent_id)
                except:
                    parent = None
            else:
                parent = None

            c = post_comment(user, content, obj, parent)
            if c:
                return HttpResponseRedirect(reverse(show_comment, args=[c.id]))

    try:
        from_url = request.META['HTTP_REFERER']
        return HttpResponseRedirect(from_url)
    except KeyError:
        raise Http404