/
views.py
43 lines (35 loc) · 1.17 KB
/
views.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
import os
from bottle import TEMPLATE_PATH, route, static_file, template, install, request
from app.apod import Apod
BASE_PATH = os.path.dirname(os.path.abspath(__file__))
TEMPLATE_PATH.append(BASE_PATH + "/templates")
@route('/', method='GET')
@route('/<date>', method='GET')
def index(date=None):
return template('index.tpl')
@route('/about', method='GET')
def about():
return template('about.tpl')
@route('/apod/:date', method='GET')
def apod(date):
apod = Apod(date)
return {
"title": apod.title,
"image_credit": apod.image_credit,
"low_res_image_path": apod.low_res_image_path,
"high_res_image_path": apod.high_res_image_path,
"explanation": apod.explanation.decode('utf-8', 'ignore'),
"date": apod.date,
"slug": apod.slug,
"votes": apod.votes,
"type": apod.type
}
@route('/assets/<filepath:path>', method='GET')
def server_asset(filepath):
return static_file(filepath, root=BASE_PATH + '/../assets')
@route('/apod/:date/vote', method='POST')
def vote(date):
vote = request.POST.get('vote')
apod = Apod(date)
apod.vote(vote)
return None