示例#1
0
def latest():
    incr, start, next, prev = parse_qs(request.args)
    quotes = db.latest(incr, start)
    admin = authDB.isAuthenticated(request)
    if request.wants_json():
        next_link = '/quotes?start=%s' % (next)
        prev_link = '/quotes?start=%s' % (prev)
        json = {
            'quotes':
            quotes,
            'links': [
                build_link(next_link, 'pyqdb/quotes/next',
                           Quote.list_json_mimetype),
                build_link(prev_link, 'pyqdb/quotes/prev',
                           Quote.list_json_mimetype)
            ]
        }
        rs = jsonify(json, Quote.list_json_mimetype)
        add_link_hdr(rs, next_link, 'pyqdb/quotes/next')
        if start > 0:
            add_link_hdr(rs, prev_link, 'pyqdb/quotes/prev')
        return rs
    return render_template('quotes.html',
                           nav=navs,
                           quotes=quotes,
                           page='quotes',
                           next=next,
                           prev=prev,
                           isAdmin=admin)
示例#2
0
文件: pyqdb.py 项目: Ramblurr/pyqdb
def fetch_votes(quote_id):
    quote = db.get(quote_id)
    if quote is None:
        abort(404)
    json = { 'links': [ 
                        build_link('/quotes/%s' %(quote_id), 'pyqdb/quote', Quote.json_mimetype),
                        build_link('/quotes/%s/votes' %(quote_id), 'pyqdb/quote/cast-vote', Vote.json_mimetype, method='put') ],
              'type': '', # up or down
              'id': quote_id
    }
    return jsonify(json, Vote.json_mimetype)
示例#3
0
文件: pyqdb.py 项目: Ramblurr/pyqdb
def latest():
    incr,start,next,prev = parse_qs(request.args)
    quotes = db.latest(incr, start)
    admin = authDB.isAuthenticated(request)
    if request.wants_json():
        next_link = '/quotes?start=%s' % (next)
        prev_link = '/quotes?start=%s' % (prev)
        json = {'quotes': quotes, 'links': [ 
            build_link(next_link, 'pyqdb/quotes/next', Quote.list_json_mimetype),
            build_link(prev_link, 'pyqdb/quotes/prev', Quote.list_json_mimetype) ]
        }
        rs = jsonify(json, Quote.list_json_mimetype)
        add_link_hdr(rs, next_link, 'pyqdb/quotes/next')
        if start > 0:
            add_link_hdr(rs, prev_link, 'pyqdb/quotes/prev')
        return rs
    return render_template('quotes.html', nav=navs, quotes=quotes, page='quotes', next=next, prev=prev, isAdmin=admin)
示例#4
0
def welcome():
    if request.wants_json():
        links = navs
        links.append(build_link('/', 'self', 'application/json'))
        root = {'version': '0.1', 'title': 'VT Bash', 'links': links}
        return jsonify(root, 'application/json')
    news = News()
    return render_template('index.html', nav=navs, news=news.news)
示例#5
0
文件: pyqdb.py 项目: Ramblurr/pyqdb
def welcome():
    if request.wants_json():
        links = navs
        links.append(build_link('/', 'self', 'application/json'))
        root = { 'version': '0.1',
                 'title': 'VT Bash',
                 'links': links }
        return jsonify(root, 'application/json')
    news = News()
    return render_template('index.html', nav=navs, news=news.news)
示例#6
0
def fetch_votes(quote_id):
    quote = db.get(quote_id)
    if quote is None:
        abort(404)
    json = {
        'links': [
            build_link('/quotes/%s' % (quote_id), 'pyqdb/quote',
                       Quote.json_mimetype),
            build_link('/quotes/%s/votes' % (quote_id),
                       'pyqdb/quote/cast-vote',
                       Vote.json_mimetype,
                       method='put')
        ],
        'type':
        '',  # up or down
        'id':
        quote_id
    }
    return jsonify(json, Vote.json_mimetype)
示例#7
0
def new_quote():
    if request.wants_json():
        rs = jsonify(
            {
                'body':
                "Quote here",
                'tags': [],
                'link':
                build_link('/quotes',
                           'pyqdb/quote/new',
                           Quote.json_mimetype,
                           method='post',
                           title='Create a new quote')
            }, Quote.json_mimetype)
        add_link_hdr(rs, '/quotes', 'pyqdb/quote/new')
        return rs
    return render_template('submit.html', nav=navs)
示例#8
0
文件: pyqdb.py 项目: Ramblurr/pyqdb
def new_quote():
    if request.wants_json():
        rs = jsonify({'body': "Quote here", 'tags': [], 'link': build_link('/quotes', 'pyqdb/quote/new', Quote.json_mimetype, method='post', title='Create a new quote')}, Quote.json_mimetype)
        add_link_hdr(rs, '/quotes', 'pyqdb/quote/new')
        return rs
    return render_template('submit.html', nav=navs)
示例#9
0
文件: pyqdb.py 项目: Ramblurr/pyqdb
from rest import build_link, add_loc_hdr, add_link_hdr

# app config
SECRET_KEY = '\xfb\x12\xdf\xa1@i\xd6>V\xc0\xbb\x8fp\x16#Z\x0b\x81\xeb\x16'
DEBUG = True
CACHE_TYPE = 'simple'

app = Flask(__name__)
app.request_class = flask_override.Request
app.config.from_object(__name__)
app.wsgi_app = ProxyFix(app.wsgi_app)

cache = Cache(app)

navs = [
    build_link('/top', 'pyqdb/quotes', Quote.list_json_mimetype, title='Top'),
    build_link('/quotes', 'pyqdb/quotes', Quote.list_json_mimetype, title='Browse'),
    build_link('/random', 'pyqdb/quotes', Quote.list_json_mimetype, title='Random'),
    build_link('/tags', 'pyqdb/tags', Tag.list_json_mimetype, title='Tags'),
    build_link('/search', '', 'application/json', title='Search'),
    build_link('/quotes/new', 'pyqdb/quote/new', Quote.json_mimetype, title='Submit')
]

authDB = FlaskRealmDigestDB('MyAuthRealm')
authDB.add_user('admin', 'test')

## Routes and Handlers ##
@app.route('/')
def welcome():
    if request.wants_json():
        links = navs
示例#10
0
from rest import build_link, add_loc_hdr, add_link_hdr

# app config
SECRET_KEY = '\xfb\x12\xdf\xa1@i\xd6>V\xc0\xbb\x8fp\x16#Z\x0b\x81\xeb\x16'
DEBUG = True
CACHE_TYPE = 'simple'

app = Flask(__name__)
app.request_class = flask_override.Request
app.config.from_object(__name__)
app.wsgi_app = ProxyFix(app.wsgi_app)

cache = Cache(app)

navs = [
    build_link('/top', 'pyqdb/quotes', Quote.list_json_mimetype, title='Top'),
    build_link('/quotes',
               'pyqdb/quotes',
               Quote.list_json_mimetype,
               title='Browse'),
    build_link('/random',
               'pyqdb/quotes',
               Quote.list_json_mimetype,
               title='Random'),
    build_link('/tags', 'pyqdb/tags', Tag.list_json_mimetype, title='Tags'),
    build_link('/search', '', 'application/json', title='Search'),
    build_link('/quotes/new',
               'pyqdb/quote/new',
               Quote.json_mimetype,
               title='Submit')
]