def increment_count(self, key, record): """ transactionでアクセスカウントを増やす """ counter = Counter.get(key) counter.count += 1 access_record = AccessRecord( parent = counter, count = counter.count, referer = record['referer'], user_agent = record['user_agent'], remote_addr = record['remote_addr'], ) access_record.put() return counter.put()
def get(self): page = self.get_int('page', 1) per_page = self.get_int('per_page', 10) query = Blog.select().where(Blog.hide == False).order_by(Blog.id.desc()) ip = self.request.headers['X-Real-Ip'] if ip != '127.0.0.1': AccessRecord.create_a_r(ip) data = { 'title': 'khahux | 平凡的一生', 'paginator': Paginator(query, page, per_page), 'all_tag': BlogTags.get_all_tags(), 'all_category': BlogCategory.get_all_category() } self.render('purecss_ui/blog.html', **data)
def get(self): page = self.get_int('page', 1) per_page = self.get_int('per_page', 10) query = Blog.select().where(Blog.hide == False).order_by( Blog.id.desc()) ip = self.request.headers['X-Real-Ip'] if ip != '127.0.0.1': AccessRecord.create_a_r(ip) data = { 'title': 'khahux | 平凡的一生', 'paginator': Paginator(query, page, per_page), 'all_tag': BlogTags.get_all_tags(), 'all_category': BlogCategory.get_all_category() } self.render('purecss_ui/blog.html', **data)
def get(self): try: user = users.get_current_user() # requestのkeyに対応するCounterを取得 counter = Counter.get(db.Key(encoded=self.request.get("key"))) # 現在のユーザーと関連づけられていなければ403エラー if counter == None or user != counter.user: responses.display_error(self, 403) return template_values = { "user": user, "user_url": users.create_logout_url("/"), "counter": counter, "records": AccessRecord.all().ancestor(counter).order("-count"), } path = os.path.join(os.path.dirname(__file__), os.pardir, "templates", "record.html") self.response.out.write(template.render(path, template_values)) # requestのkeyが正しくない場合 except BadKeyError, error: logging.error(str(error)) responses.display_error(self, 400)
def post(self): """ requestからkeyを受け取り、対応するCounterのentityを削除する """ try: # 削除する対象を取得 counter = Counter.get(db.Key(encoded = self.request.get('key'))) # 現在のユーザーと関連づけられていなければ403エラー if counter == None or counter.user != users.get_current_user(): responses.display_error(self, 403) return # 関連画像、アクセス履歴ともに一括削除 for image in counter.image: NumberImage.get(image).delete() for record in AccessRecord.all().ancestor(counter): record.delete() counter.delete() self.redirect('/') # requestのkeyが正しくない場合 except BadKeyError, error: logging.error(str(error)) responses.display_error(self, 400)