代码拉取完成,页面将自动刷新
#!/usr/bin/python
#encoding=utf-8
import web
import os
import json
from web.net import htmlquote
from fwrite.template import template_render
from fwrite.db import *
PATH = os.path.join(os.path.dirname(__file__), 'templates')
class JSONDateTimeEncoder(json.JSONEncoder):
def default(self, obj):
if isinstance(obj, (datetime.date, datetime.datetime)):
return obj.isoformat()
else:
return json.JSONEncoder.default(self, obj)
class index:
def run(self):
content = {}
return template_render('index.html', PATH, content)
def GET(self):
return self.run()
def POST(self):
return self.run()
class article_show:
def GET(self, key):
if key:
key = htmlquote(key)
article = get_article(key)
if article:
column_key = article.get('column', '')
columns = get_columns(column_key)
if columns:
article['column_name'] = columns[0].get('name', '')
content = {'article':article}
return template_render('article.html', PATH, content)
else:
raise web.seeother('/')
else:
raise web.seeother('/')
class ajax_columns:
def GET(self):
data = web.input()
page = data.get('page', 1)
try:
int(page)
except:
page = 1
columns = get_columns(page = 1)
cs = {'columns':{}}
for c in columns:
key = str(c.get('key',''))
name = str(c.get('name',''))
if key and name:
cs['columns'][key] = {'key':key, 'name':name}
return json.dumps(cs,cls=JSONDateTimeEncoder)
class ajax_articles:
def GET(self):
data = web.input()
page = data.get('page', 1)
column_key = htmlquote(data.get('coumn_key', ''))
try:
int(page)
except:
page = 1
articles = get_articles(column_key = column_key,page = page)
arts = {'articles':{}}
for c in articles:
key = str(c.get('key',''))
title = str(c.get('title',''))
if key and title:
arts['articles'][key] = {'key':key, 'title':title}
return json.dumps(arts,cls=JSONDateTimeEncoder)
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。