initial commit

Tue Jul 21 01:49:52 2009 +0900

author
hattori@www.hexacosa.net
date
Tue Jul 21 01:49:52 2009 +0900
changeset 0
a23659f42022
child 1
97a06a4663fc

initial commit

junoblog.py file | annotate | diff | revisions
templates/blog.html file | annotate | diff | revisions
templates/index.html file | annotate | diff | revisions
templates/login.html file | annotate | diff | revisions
templates/logout.html file | annotate | diff | revisions
templates/useradd.html file | annotate | diff | revisions
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/junoblog.py	Tue Jul 21 01:49:52 2009 +0900
     1.3 @@ -0,0 +1,73 @@
     1.4 +from juno import get, post, find, run, template, init, model, redirect
     1.5 +import time
     1.6 +
     1.7 +__version__ = '0.0.1'
     1.8 +__author__ = 'Hideo Hattori'
     1.9 +
    1.10 +CODEC = 'utf-8'
    1.11 +
    1.12 +init({'dev_port': 8080,
    1.13 +      'template_lib': 'jinja2',
    1.14 +      'db_location': 'juno-blog.db',
    1.15 +      'use_debugger': True})
    1.16 +
    1.17 +User = model('User', name = 'string',
    1.18 +                     title = 'string',
    1.19 +                     password = 'string')
    1.20 +
    1.21 +Blog = model('Blog', name = 'string',
    1.22 +                     title = 'string',
    1.23 +                     date = 'string',
    1.24 +                     text = 'string')
    1.25 +
    1.26 +@get('/')
    1.27 +def home(web):
    1.28 +    users = find(User).all()
    1.29 +    template('index.html', {'users': [ u for u in users ]})
    1.30 +
    1.31 +@post('/login/')
    1.32 +def login(web):
    1.33 +    name = web.input('name')
    1.34 +    password = web.input('password')
    1.35 +    exist = User.find().filter(User.name==name)
    1.36 +    template('login.html', {'user': name, 'exist': exist.count()})
    1.37 +
    1.38 +@post('/useradd/')
    1.39 +def useradd(web):
    1.40 +    name = web.input('name')
    1.41 +    password = web.input('password')
    1.42 +    title = web.input('title').decode(CODEC)
    1.43 +    exist = User.find().filter(User.name==name)
    1.44 +    if exist.count():
    1.45 +        template('index.html', {})
    1.46 +        return
    1.47 +    user = User(name=name, title=title, password=password)
    1.48 +    user.add().save()
    1.49 +    redirect('/blog/%s' % name)
    1.50 +
    1.51 +@get('/logout/')
    1.52 +def logout(web, name):
    1.53 +    template('logout.html', {'user': name})
    1.54 +
    1.55 +@get('/blog/:name/')
    1.56 +def blog(web, name):
    1.57 +    user = User.find().filter(User.name==name).all()[0]
    1.58 +    blogs = Blog.find().filter(Blog.name==name).all()
    1.59 +    blogs = [ b for b in blogs if b.name == name ]
    1.60 +    template('blog.html', {'user': user, 'blogs': blogs})
    1.61 +
    1.62 +@post('/blogpost/:name/')
    1.63 +def postblog(web, name):
    1.64 +    title = web.input('title').decode(CODEC)
    1.65 +    text = web.input('pagetext').decode(CODEC)
    1.66 +    date = time.ctime()
    1.67 +    b = Blog(name=name, title=title, text=text, date=date)
    1.68 +    b.add().save()
    1.69 +    blogs = find(Blog).all()
    1.70 +    blogs = [ b for b in blogs if b.name == name ]
    1.71 +    template('blog.html', {'user': {'name': name, 'title': title},
    1.72 +                           'blogs': blogs})
    1.73 +
    1.74 +if __name__ == '__main__':
    1.75 +    run()
    1.76 +
     2.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     2.2 +++ b/templates/blog.html	Tue Jul 21 01:49:52 2009 +0900
     2.3 @@ -0,0 +1,19 @@
     2.4 +<html><body>
     2.5 +    <h1>{{ user.title }}</h1>
     2.6 +    <h2>This page is {{ user.name }}'s blog</h2>
     2.7 +    <form method="post" action="/blogpost/{{ user.name }}/">
     2.8 +    <p>new<br/>
     2.9 +    title : <input type="text" name="title" /><br/>
    2.10 +    text  : <textarea name="pagetext" rows="12" cols="50" /></textarea><br/>
    2.11 +    <input type="submit" value="post new article" />
    2.12 +    </p>
    2.13 +    </form>
    2.14 +    {% for blog in blogs %}
    2.15 +    <h3>{{ blog.title }}</h3>
    2.16 +    <p>{{ blog.text }}</p>
    2.17 +    <p>{{ blog.date }}</p>
    2.18 +    <hr/>
    2.19 +    {% endfor %}
    2.20 +    <a href="/blog/{{ user.name }}/">user top</a>
    2.21 +    <a href="/">top</a>
    2.22 +</body></html>
     3.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     3.2 +++ b/templates/index.html	Tue Jul 21 01:49:52 2009 +0900
     3.3 @@ -0,0 +1,20 @@
     3.4 +<html>
     3.5 +  <title>juno-blog</title>
     3.6 +<body>
     3.7 +  <p>Hello Juno!</p>
     3.8 +    <form method="post" action="/login/">
     3.9 +    <p>Login<br/>
    3.10 +    username : <input type="text" name="name" />
    3.11 +    password : <input type="text" name="password" />
    3.12 +    <input type="submit" value="Login" />
    3.13 +    </p>
    3.14 +    </form>
    3.15 +  <p><a href="logout.html">logout</a></p>
    3.16 +  <p>
    3.17 +  {% for user in users %}
    3.18 +  {{ user.name }} : <a href="/blog/{{ user.name }}/">{{ user.title }}</a><br/>
    3.19 +  {% endfor %}
    3.20 +  </p>
    3.21 +</body>
    3.22 +</html>
    3.23 +
     4.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     4.2 +++ b/templates/login.html	Tue Jul 21 01:49:52 2009 +0900
     4.3 @@ -0,0 +1,20 @@
     4.4 +<html><body>
     4.5 +<p>Thank you vist this site.</p>
     4.6 +<p>
     4.7 +{% if exist == 0 %}
     4.8 +  <p>{{ user }} is not exist.</p>
     4.9 +  <form method="post" action="/useradd/">
    4.10 +  <p>Crate Blog<br/>
    4.11 +  title : <input type="text" name="title" />
    4.12 +  username : <input type="text" name="name" />
    4.13 +  password : <input type="text" name="password" />
    4.14 +  <input type="submit" value="Create" />
    4.15 +  </p>
    4.16 +  </form>
    4.17 +{% else %}
    4.18 +  username : {{ user }}; <a href="./logout">logout</a>
    4.19 +  <p><a href="/blog/{{ user }}/">{{ user }}</a></p>
    4.20 +{% endif %}
    4.21 +</p>
    4.22 +<p><a href="/">top page</a></p>
    4.23 +</body></html>
     5.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     5.2 +++ b/templates/logout.html	Tue Jul 21 01:49:52 2009 +0900
     5.3 @@ -0,0 +1,4 @@
     5.4 +<html><body>
     5.5 +    <p>{{ user }} さん、またおこしください。</p>
     5.6 +<p><a href="/">top</a></p>
     5.7 +</body></html>
     6.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     6.2 +++ b/templates/useradd.html	Tue Jul 21 01:49:52 2009 +0900
     6.3 @@ -0,0 +1,9 @@
     6.4 +<html>
     6.5 +  <body>
     6.6 +    {% for blog in blogs %}
     6.7 +      {{ blog.text %}
     6.8 +    {% endfor %}
     6.9 +    <a href="/blog/{{ user }}/">user top</a>
    6.10 +    <a href="/">top</a>
    6.11 +  </body>
    6.12 +</html>

mercurial