Skip to content

Commit fa17ccf

Browse files
WahahaWahaha
Wahaha
authored and
Wahaha
committed
a versy basic implement done
1 parent 5e9e99b commit fa17ccf

File tree

12 files changed

+210
-0
lines changed

12 files changed

+210
-0
lines changed

app.py

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
from wheezy.http import WSGIApplication
2+
from wheezy.web.middleware import bootstrap_defaults
3+
from wheezy.web.middleware import path_routing_middleware_factory
4+
5+
from config import options
6+
from urls import all_urls
7+
8+
9+
main = WSGIApplication([
10+
bootstrap_defaults(url_mapping=all_urls),
11+
path_routing_middleware_factory
12+
], options)
13+
14+
if __name__ == '__main__':
15+
from wsgiref.handlers import BaseHandler
16+
from wsgiref.simple_server import make_server
17+
try:
18+
print('Visit http://localhost:8080/')
19+
BaseHandler.http_version = '1.1'
20+
make_server('', 8080, main).serve_forever()
21+
except KeyboardInterrupt:
22+
pass
23+
print('\nThanks!')

config.py

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
from wheezy.html.utils import html_escape
2+
from wheezy.template.engine import Engine
3+
from wheezy.template.ext.core import CoreExtension
4+
from wheezy.template.loader import FileLoader
5+
from wheezy.web.templates import WheezyTemplate
6+
7+
options = {}
8+
9+
# Template Engine
10+
searchpath = ['templates']
11+
engine = Engine(
12+
loader=FileLoader(searchpath),
13+
extensions=[
14+
CoreExtension(),
15+
])
16+
engine.global_vars.update({
17+
'h': html_escape
18+
})
19+
options.update({
20+
'render_template': WheezyTemplate(engine)
21+
})
22+
23+
album_path = "static/album"

repository.py

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import os
2+
import time
3+
from os import path
4+
5+
6+
class Repository(object):
7+
8+
def __init__(self, path):
9+
self.path = path
10+
11+
def list_album(self):
12+
return [(f, time.ctime(os.path.getctime(os.path.join(self.path, f)))) for f in os.listdir(self.path)]
13+
14+
def list_photos(self, path):
15+
full_path = os.path.join(self.path, path)
16+
return [os.path.join(full_path, f) for f in os.listdir(full_path)]

static/album/funny/gao_guai.gif

1.78 MB
Loading

static/album/funny/jiao_hua_le.gif

2 MB
Loading

static/album/funny/kou_foot.gif

1.79 MB
Loading

static/main.css

+69
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
html {
2+
background-color: #e6e9e9;
3+
background-image: -webkit-linear-gradient(270deg,rgb(230,233,233) 0%,rgb(216,221,221) 100%);
4+
background-image: linear-gradient(270deg,rgb(230,233,233) 0%,rgb(216,221,221) 100%);
5+
-webkit-font-smoothing: antialiased;
6+
}
7+
8+
body {
9+
margin: 0 auto;
10+
padding: 2em 2em 4em;
11+
max-width: 800px;
12+
font-family: "Helvetica Neue", Helvetica, Arial, sans-serif;
13+
font-size: 16px;
14+
line-height: 1.5em;
15+
color: #545454;
16+
background-color: #ffffff;
17+
box-shadow: 0 0 2px rgba(0, 0, 0, 0.06);
18+
}
19+
20+
h1, h2, h3, h4, h5, h6 {
21+
color: #222;
22+
font-weight: 600;
23+
line-height: 1.3em;
24+
}
25+
26+
h2 {
27+
margin-top: 1.3em;
28+
}
29+
30+
a {
31+
color: #0083e8;
32+
}
33+
34+
b, strong {
35+
font-weight: 600;
36+
}
37+
38+
samp {
39+
display: none;
40+
}
41+
42+
img {
43+
-webkit-animation: colorize 2s cubic-bezier(0, 0, .78, .36) 1;
44+
animation: colorize 2s cubic-bezier(0, 0, .78, .36) 1;
45+
background: transparent;
46+
border: 10px solid rgba(0, 0, 0, 0.12);
47+
border-radius: 4px;
48+
display: block;
49+
margin: 1.3em auto;
50+
max-width: 95%;
51+
}
52+
53+
@-webkit-keyframes colorize {
54+
0% {
55+
-webkit-filter: grayscale(100%);
56+
}
57+
100% {
58+
-webkit-filter: grayscale(0%);
59+
}
60+
}
61+
62+
@keyframes colorize {
63+
0% {
64+
filter: grayscale(100%);
65+
}
66+
100% {
67+
filter: grayscale(0%);
68+
}
69+
}

templates/layout.html

+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
@require(path_for)
2+
<!DOCTYPE html>
3+
<html>
4+
5+
<head>
6+
<meta charset="utf-8">
7+
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
8+
<title>Alubms</title>
9+
<meta name="description" content="A very simple local photo browse">
10+
<link rel="stylesheet" href="@path_for('static', path='main.css')">
11+
</head>
12+
<body>
13+
14+
<h1>Album</h1>
15+
<hr>
16+
17+
<div>
18+
@def content():
19+
@end
20+
@content()
21+
</div>
22+
23+
</body>
24+
</html>

templates/list.html

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
@extends("layout.html")
2+
3+
@def content():
4+
@require(path_for, albums)
5+
<h1>Albums</h1>
6+
@for a in albums:
7+
<p>
8+
<a href="/album/@a[0]">@a[0]</a>
9+
</p>
10+
@end
11+
@end

templates/view.html

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
@extends("layout.html")
2+
3+
@def content():
4+
@require(path_for, photos)
5+
<h1>Photos</h1>
6+
@for p in photos:
7+
<p>
8+
<img src="/@p"/>
9+
</p>
10+
@end
11+
@end

urls.py

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
from wheezy.routing import url
2+
from wheezy.web.handlers import file_handler
3+
from views import ListHandler, ViewHandler
4+
5+
all_urls = [
6+
url('', ListHandler, name='list'),
7+
url('album/{title}', ViewHandler, name='view_album'),
8+
url('static/{path:any}',
9+
file_handler(root='static/'),
10+
name='static')
11+
]

views.py

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
from wheezy.web.handlers import BaseHandler
2+
from repository import Repository
3+
4+
from config import album_path
5+
6+
7+
class ListHandler(BaseHandler):
8+
9+
def get(self):
10+
repo = Repository(album_path)
11+
albums = repo.list_album()
12+
return self.render_response('list.html',
13+
albums=albums)
14+
15+
16+
class ViewHandler(BaseHandler):
17+
18+
def get(self):
19+
repo = Repository(album_path)
20+
photos = repo.list_photos(self.route_args.get('title'))
21+
return self.render_response('view.html',
22+
photos=photos)

0 commit comments

Comments
 (0)