def admin_sidebar_item(): return { 'name': current_plugin.name, 'slug': current_plugin.slug, 'items': [{ 'type': 'link', 'name': '新建标签', 'url': plugin_url_for('new', _component='admin') }, { 'type': 'link', 'name': '管理标签', 'url': plugin_url_for('list', _component='admin') }] }
def authorize(): token_url = get_setting('token_url').value client_id = get_setting('client_id').value scope = get_setting('scope').value redirect_url = get_setting('redirect_url').value client_secret = get_setting('client_secret').value code = request.args['code'] with urllib.request.urlopen(token_url, data=urllib.parse.urlencode({ 'client_id': client_id, 'grant_type': 'authorization_code', 'scope': scope, 'code': code, 'redirect_uri': redirect_url, 'client_secret': client_secret }).encode()) as f: result = json.loads(f.read().decode()) set_setting('access_token', value=result['access_token']) set_setting('token_type', value=result['token_type']) set_setting('expires_at', value=str(int(time.time()) + result['expires_in'])) set_setting('refresh_token', value=result['refresh_token']) opener.addheaders = [ ('Authorization', result['token_type'] + ' ' + result['access_token']) ] return redirect(plugin_url_for('me', _component='admin'))
def admin_sidebar_item(): return { 'name': current_plugin.name, 'slug': current_plugin.slug, 'items': [{ 'type': 'link', 'name': '设置账号', 'url': plugin_url_for('account', _component='admin') }, { 'type': 'link', 'name': '测试发送邮件', 'url': plugin_url_for('test-send-mail', _component='admin') }] }
def admin_sidebar_item(): return { 'name': current_plugin.name, 'slug': current_plugin.slug, 'items': [{ 'type': 'link', 'name': '设置', 'url': plugin_url_for('settings', _component='admin') }, { 'type': 'link', 'name': '我', 'url': plugin_url_for('me', _component='admin') }, { 'type': 'link', 'name': '管理提醒', 'url': plugin_url_for('list', _component='admin') }] }
def me(): if is_authorized(): api_base_url = get_setting('api_base_url').value try: f = opener.open(api_base_url + '/me') me = json.loads(f.read().decode()) except urllib.error.HTTPError as e: me = None else: me = None return current_plugin.render_template('me.html', me=me, login_url=plugin_url_for( 'login', _component='admin'))
def edit_tag(): if request.method == 'GET': id = request.args.get('id', type=int) tag = None if id is not None: tag = Tag.query.get(id) return current_plugin.render_template('edit.html', tag=tag) else: id = request.form.get('id', type=int) if id is None: tag = Tag() else: tag = Tag.query.get(id) tag.name = request.form['name'] tag.slug = request.form['slug'] tag.description = request.form['description'] if tag.id is None: db.session.add(tag) db.session.commit() return redirect(plugin_url_for('list', _component='admin'))
def new_tag(): return redirect(plugin_url_for('edit', _component='admin'))
def admin_article_list_url(params): return plugin_url_for('list', _component='admin', **params)