def articles(): i = ctx.request.input(action='', page='1') if i.action == 'edit': article = _get_article(i.id) return Template('templates/articleform.html', form_title=_('Edit Article'), form_action='/api/articles/update', categories=_get_categories(), static=False, **article) if i.action == 'delete': api_delete_article() raise seeother('articles') page = int(i.page) previous = page > 1 next = False articles = _get_articles(page, 51, published_only=False) if len(articles) == 51: articles = articles[:-1] next = True return Template('templates/articles.html', page=page, previous=previous, next=next, categories=_get_categories(), articles=articles)
def pages(): i = ctx.request.input(action='') if i.action == 'edit': page = _get_page(i.id) return Template('/templates/articleform.html', form_title=_('Edit Page'), form_action='/api/pages/update', static=True, **page) if i.action == 'delete': api_delete_page() raise seeother('pages') return Template('templates/pages.html', pages=_get_pages())
def categories(): i = ctx.request.input(action='') if i.action == 'add': return Template('templates/categoryform.html', form_title=_('Add Category'), form_action='/api/categories/create') if i.action == 'edit': cat = _get_category(i.id) return Template('templates/categoryform.html', form_title=_('Edit Category'), form_action='/api/categories/update', **cat) if i.action == 'delete': api_delete_category() raise seeother('categories') return Template('templates/categories.html', categories=_get_categories())
def do_search(): httpVal = ctx.request.input() userId = httpVal.get('userID', '') print userId _Downloud_All(userId) ls = _get_Text(userId) #得到用户相关的标签云 #ls = { # "text" : ['Loredfsm', 'Lorem1'], # "weight" : [12, 12.2] # } texts = ls["text"] weights = ls["weight"] html_text = ''''''; for i in range(0, len(texts)): html_text += '''{text: "''' html_text += texts[i] html_text += '''", weight: ''' html_text += str(weights[i]) html_text += ''', link: "photo?txt=''' html_text += texts[i] html_text += '''&usr=''' html_text += userId html_text += '''"}''' if i != len(texts)-1: html_text += ''',''' return Template('static/cloud.html', labels=html_text)
def attachments(): i = ctx.request.input(action='', page='1', size='20') if i.action == 'delete': delete_attachment(i.id) raise seeother('attachments') page = int(i.page) size = int(i.size) num = db.select_int('select count(id) from attachments where website_id=?', ctx.website.id) if page < 1: raise APIValueError('page', 'page invalid.') if size < 1 or size > 100: raise APIValueError('size', 'size invalid.') offset = (page - 1) * size atts = db.select( 'select * from attachments where website_id=? order by id desc limit ?,?', ctx.website.id, offset, size + 1) next = False if len(atts) > size: atts = atts[:-1] next = True return Template('templates/attachments.html', attachments=atts, page=page, previous=page > 2, next=next)
def wikis(): ' show Wikis menu. ' i = ctx.request.input(action='') if i.action == 'edit': wiki = _get_wiki(i.id) return Template('templates/wikiform.html', form_title='Edit Wiki', form_action='/api/wikis/update', **wiki) if i.action == 'pages': wiki = _get_wiki(i.id) return Template('templates/wikipages.html', wiki=wiki) if i.action == 'editpage': page = _get_wikipage(i.id) wiki = _get_wiki(page.wiki_id) return Template('templates/wikipageform.html', wiki=wiki, page=page) return Template('templates/wikis.html', wikis=_get_wikis())
def _wrapper(*args, **kw): r = func(*args, **kw) if isinstance(r, dict): y, m, d = get_today() r['__lunar_date__'] = get_lunar(y, m, d) r['__user__'] = ctx.user r['static_prefix'] = '' if ctx.application.debug else STATIC_PATH_PREFIX return Template('templates/%s' % path, r) return r
def _wrapper(*args, **kw): r = func(*args, **kw) if isinstance(r, dict): r['__user__'] = ctx.user r['__request__'] = ctx.request r['__time__'] = int(1000 * time.time()) r['__navigations__'] = _get_navigations() r['__theme_path__'] = 'themes/default' return Template('themes/default/%s' % path, r) return r
def index(): i = ctx.request.input() client = _create_client() data = client.parse_signed_request(i.signed_request) if data is None: raise StandardError('Error!') user_id = data.get('uid', '') auth_token = data.get('oauth_token', '') if not user_id or not auth_token: return Template('/static/auth.html', client_id=APP_ID) expires = data.expires client.set_access_token(auth_token, expires) # check database if user exist: user = None users = db.select('select * from users where id=?', user_id) if users: # user exist, update if token changed: user = users[0] if auth_token != user.auth_token: uu = _from_weibo_user(client.users.show.get(uid=user_id)) uu['auth_token'] = auth_token uu['expired_time'] = expires user.update(uu) db.update_kw('users', 'id=?', user_id, **uu) else: u = client.users.show.get(uid=user_id) user = _from_weibo_user(u) user['id'] = user_id user['level'] = 0 user['weight'] = 55 if user['gender'] == u'f' else 75 user['since_id'] = '' user['auth_token'] = auth_token user['expired_time'] = expires db.insert('users', **user) img = user['avatar_large'] or user['profile_image_url'] or user['image_url'] return Template('/static/index.html', user=user, user_img=img, signed_request=i.signed_request)
def do_photo1(): ls = { "src" : ['1', '2', '3', '4'], "dec" : [u"图片1", 'Image2', 'Image3', 'Image4'] } # .decode('utf-8') src = ls["src"] dec = ls["dec"] html_text = ''''''; for i in range(0, len(src)): html_text += '''<div class="cell"><a href="#"><img src="/static/images/''' html_text += src[i] html_text += '''.jpg" /></a><p><a href="#">''' #html_text += dec[i] html_text += '''</a></p></div>''' return Template('static/pic.html', txt=html_text, encoding="utf-8")
def do_photo(): httpVal = ctx.request.input() txt = httpVal.get('txt', '') usr = httpVal.get('usr', '') #print txt, usr ls = _get_Image(txt, usr); # 获取某个对应标签的图片 src = ls["src"] dec = ls["dec"] html_text = ''''''; for i in range(0, len(src)): html_text += '''<div class="cell"><a href="#"><img src="http://ww3.sinaimg.cn/bmiddle/''' html_text += src[i] html_text += '''" /></a><p><a href="#">''' html_text += dec[i] html_text += '''</a></p></div>''' return Template('static/pic.html', txt=html_text, encoding="utf-8")
def _wrapper(*args, **kw): r = func(*args, **kw) if isinstance(r, dict): templ_path, model = _init_theme(path, r) return Template(templ_path, model) return r
def home(): u = _check_cookie() if u is None: return Template('static/signin.html') return Template('static/home.html', user=u)
def index(): return Template('static/index.html')
def show_search(): return Template('static/index.html')
def add_attachment(): return Template('templates/attachmentform.html')
def add_page(): return Template('templates/articleform.html', form_title=_('Add Page'), form_action='/api/pages/create', static=True)
def add_article(): return Template('templates/articleform.html', form_title=_('Add Article'), form_action='/api/articles/create', categories=_get_categories(), static=False)
def add_wiki(): ' show New Wiki menu. ' return Template('templates/wikiform.html', form_title='Add Wiki', form_action='/api/wikis/create')
def index(): u = _check_cookie() if u is None: return Template('static/signin.html') return Template('static/index.html', user=u)
def index(): u = _check_cookie() #return Template('./static/signin.html') if u is None: return Template('./static/signin.html') return Template('static/myweibo.html', user=u)
def _init_template(path, model): model['__get_template_file__'] = lambda f: '/templates/%s' % f model['__user__'] = ctx.user model['__request__'] = ctx.request model['__time__'] = int(1000 * time.time()) return Template('templates/%s' % path, model)