Example #1
0
	def post(self):
		challenge = self.request.get('recaptcha_challenge_field')
		response = self.request.get('recaptcha_response_field')
		remoteip = environ['REMOTE_ADDR']

		cResponse = captcha.submit(challenge, response,
			'6LfrwroSAAAAADfwZ2WtvUV0zdbyV3BzAfRTzaDr',
			remoteip)

		# Create a new comment
		message = Comment()
		message.nickname = self.request.get('nickname')
		message.email = self.request.get('email')
		message.gravatar = get_gravatar_url(message.email.encode('utf-8'))
		message.website = self.request.get('website')
		message.msg = self.request.get('msg')
		message.ref_msg = self.request.get('refMsg')
		message.ref_name = self.request.get('refName')

		id = self.request.get('id')
		message.article = Article.all().filter('id =', id).get()

		show_cancel = self.request.get('cancel')
		msgid = 0 if self.request.get('msgId') == '' else int(self.request.get('msgId'))

		if cResponse.is_valid:
			rep = re.compile('^http://', re.IGNORECASE)		
			message.website = re.sub(rep, '', message.website)

			# Escape the content
			message.msg = escape_str(message.msg)
			message.escaped_msg = message.msg.replace('\\', '\\\\')
			message.ref_msg = escape_str(message.ref_msg)
			message.put()
			self.redirect('/article/' + message.article.permalink)
		else:
			self.captcha_error = 'Please try again'
			self.save_nickname = message.nickname
			self.save_email = message.email
			self.save_website = message.website
			self.save_msg = message.msg
			self.save_ref = message.ref_msg
			self.save_refname = message.ref_name
			self.save_showcancel = show_cancel
			self.save_msgid = msgid
			self.get()
Example #2
0
	def get(self):
		# Get current page
		try:
			pageno = int(self.request.get('pageno'))
		except ValueError:
			pageno = 1

		query = Message.all().order('-time_stamp')
		group = query.fetch(1000)

		msg_list = []
		pagei = 0
		start = 0
		length = len(group)

		while group != [] and msg_list == []:
			# Pick out each page
			while start + self.msg_per_page - 1 < length:
				pagei = pagei + 1
				if pagei == pageno:
					msg_list = group[start : start + self.msg_per_page]
				start = start + self.msg_per_page
			if len(group[start : start + self.msg_per_page]) > 0:
				pagei = pagei + 1
				if pagei == pageno:
					msg_list = group[start : start + self.msg_per_page]

			last_time = group[-1].time_stamp
			query.filter('time_stamp <', last_time)
			group = query.fetch(1000)

		show_left_arrow = 1 if pageno > 1 else 0
		show_right_arrow = 1 if pageno < pagei else 0
		show_left_dot = 1 if pageno >= 5 else 0
		show_right_dot = 1 if pageno <= pagei - 4 else 0

		pageno_list = [i for i in range(max(1, pageno - 3), min(pagei + 1, pageno + 4))]

		for message in msg_list:
			temp = remove_html_tag(message.msg).replace('\n', ' ')
			message.msg = escape_str(temp[:20]) + '...' if len(temp) > 20 else escape_str(temp[:20])

		template_values = {
			'messages': msg_list,
			'page_current': pageno,
			'page_total': pagei,
			'pageno_list': pageno_list,
			'show_left_arrow': show_left_arrow,
			'show_right_arrow': show_right_arrow,
			'show_left_dot': show_left_dot,
			'show_right_dot': show_right_dot,
			'colno': len(pageno_list) + show_left_arrow + show_right_arrow + 
			                           show_left_dot + show_right_dot,
			'page_prev': max(1, pageno - 1),
			'page_next': min(pagei, pageno + 1),

			'logout_url': users.create_logout_url('/'),
			'page_name': 'guestbookAdmin'
		}

		path = os.path.join(os.path.dirname(__file__), 'pages/guestbookAdmin.html')
		self.response.headers['Content-Type'] = 'text/html;charset=utf-8'
		self.response.out.write(template.render(path, template_values))
Example #3
0
    def get(self):
        # Get current page
        try:
            pageno = int(self.request.get("pageno"))
        except ValueError:
            pageno = 1

        query = Comment.all().order("-time_stamp")
        group = query.fetch(1000)

        msg_list = []
        pagei = 0
        start = 0
        length = len(group)

        while group != [] and msg_list == []:
            # Pick out each page
            while start + self.msg_per_page - 1 < length:
                pagei = pagei + 1
                if pagei == pageno:
                    msg_list = group[start : start + self.msg_per_page]
                start = start + self.msg_per_page
            if len(group[start : start + self.msg_per_page]) > 0:
                pagei = pagei + 1
                if pagei == pageno:
                    msg_list = group[start : start + self.msg_per_page]

            last_time = group[-1].time_stamp
            query.filter("time_stamp <", last_time)
            group = query.fetch(1000)

        show_left_arrow = 1 if pageno > 1 else 0
        show_right_arrow = 1 if pageno < pagei else 0
        show_left_dot = 1 if pageno >= 5 else 0
        show_right_dot = 1 if pageno <= pagei - 4 else 0

        pageno_list = [i for i in range(max(1, pageno - 3), min(pagei + 1, pageno + 4))]

        for message in msg_list:
            temp = remove_html_tag(message.msg).replace("\n", " ")
            message.msg = escape_str(temp[:15]) + "..." if len(temp) > 15 else escape_str(temp[:15])

        template_values = {
            "messages": msg_list,
            "page_current": pageno,
            "page_total": pagei,
            "pageno_list": pageno_list,
            "show_left_arrow": show_left_arrow,
            "show_right_arrow": show_right_arrow,
            "show_left_dot": show_left_dot,
            "show_right_dot": show_right_dot,
            "colno": len(pageno_list) + show_left_arrow + show_right_arrow + show_left_dot + show_right_dot,
            "page_prev": max(1, pageno - 1),
            "page_next": min(pagei, pageno + 1),
            "logout_url": users.create_logout_url("/"),
            "page_name": "commentsAdmin",
        }

        path = os.path.join(os.path.dirname(__file__), "pages/commentsAdmin.html")
        self.response.headers["Content-Type"] = "text/html;charset=utf-8"
        self.response.out.write(template.render(path, template_values))