Skip to content

Commit

Permalink
image uploader
Browse files Browse the repository at this point in the history
  • Loading branch information
ukyo committed May 18, 2011
1 parent a18d6c9 commit d642d9c
Show file tree
Hide file tree
Showing 40 changed files with 659 additions and 39 deletions.
3 changes: 2 additions & 1 deletion app.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
application: kaysns
application: atnd-checker
version: 1
runtime: python
api_version: 1
Expand Down Expand Up @@ -36,6 +36,7 @@ handlers:

- url: /.*
script: kay/main.py
secure: always

skip_files: |
^(.*/)?(
Expand Down
11 changes: 9 additions & 2 deletions app/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@

from kay.utils.forms.modelform import ModelForm
from app.models import (
MyUser, BbsThread, BbsComment, BlogEntry, BlogComment
MyUser, BbsThread, BbsComment,
BlogEntry, BlogComment, Image
)

class UserForm(ModelForm):
Expand Down Expand Up @@ -32,4 +33,10 @@ class Meta:
class BlogCommentForm(ModelForm):
class Meta:
model = BlogComment
exclude = ('user', 'entry')
exclude = ('user', 'entry')


class ImageForm(ModelForm):
class Meta:
model = Image
exclude = ('user', )
Binary file modified app/forms.pyc
Binary file not shown.
21 changes: 15 additions & 6 deletions app/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,22 +11,27 @@ class MyUser(DatastoreUser):
tags = db.StringListProperty()
description = db.TextProperty()

class BrMixin(object):
class ViewMixin(object):
def view_text(self):
if self.newline_to_br:
return self.text.replace('\r\n', '\n').replace('\n', '<br/>')
else:
return self.text

class Thread(db.Model, BrMixin):

def view_datetime(self, attr_name):
attr = getattr(self, attr_name)
return attr.strftime('%Y/%m/%d %H:%M:%S')


class Thread(db.Model, ViewMixin):
user = kay.db.OwnerProperty()
title = db.StringProperty(required=True)
tags = db.StringListProperty()
text = db.TextProperty(required=True)
newline_to_br = db.BooleanProperty()
newline_to_br = db.BooleanProperty(default=True)
created = db.DateTimeProperty(auto_now_add=True)

class Comment(db.Model, BrMixin):
class Comment(db.Model, ViewMixin):
user = kay.db.OwnerProperty()
title = db.StringProperty(required=True)
text = db.TextProperty(required=True)
Expand All @@ -44,4 +49,8 @@ class BlogEntry(Thread):

class BlogComment(Comment):
entry = db.ReferenceProperty(BlogEntry, collection_name='comments')


class Image(db.Model):
user = kay.db.OwnerProperty()
icon = db.BlobProperty()
background_image = db.BlobProperty()
Binary file modified app/models.pyc
Binary file not shown.
6 changes: 6 additions & 0 deletions app/templates/base.html
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,12 @@
<li><a href="/blog/manage">Manage Entries</a>
<li><a href="/blog/create">Create a Entry</a>
</ul>
<li><a href="/uploader">Uploader</a>
<li>Setting
<ul>
<li><a href="/manage-profile">Profile</a>
<li><a href="/setting/image">Image</a>
</ul>
<li><a href="{{ create_logout_url() }}">logout</a>
</ul>
{% endblock %}
Expand Down
7 changes: 4 additions & 3 deletions app/templates/bbs/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,14 @@
{{ form()|safe }}
</div>
<table>
<tr><th>Auther</th><th>Title</th><th>Updated</th><th>Created</th></tr>
<tr><th>Auther</th><th>Title</th><th>Reply</th><th>Updated</th><th>Created</th></tr>
{% for thread in threads.object_list %}
<tr>
<td>{{ thread.user.user_name }}</td>
<td><a href="/bbs/{{ thread.key().id() }}">{{ thread.title }}</a></td>
<td>{{ thread.updated }}</td>
<td>{{ thread.created }}</td>
<td>{{ thread.comments.count() }}</td>
<td>{{ thread.view_datetime('updated') }}</td>
<td>{{ thread.view_datetime('created') }}</td>
</tr>
{% endfor %}
</table>
Expand Down
4 changes: 2 additions & 2 deletions app/templates/bbs/thread.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,15 @@ <h1>{{ thread.title }}</h1>
<div>
<dl class="info">
<dt>Auther</dt><dd>{{ thread.user.user_name }}</dd>
<dt>Created</dt><dd>{{ thread.created }}</dd>
<dt>Created</dt><dd>{{ thread.view_datetime('created') }}</dd>
</dl>
<div class="text">{{ thread.view_text()|safe }}</div>
</div>
{% for comment in thread.comments %}
<div>
<dl class="info">
<dt>Auther</dt><dd>{{ comment.user.user_name }}</dd>
<dt>Created</dt><dd>{{ comment.created }}</dd>
<dt>Created</dt><dd>{{ comment.view_datetime('created') }}</dd>
</dl>
<div class="text">{{ comment.view_text()|safe }}</div>
{% endfor %}
Expand Down
4 changes: 2 additions & 2 deletions app/templates/blog/entry.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
{% block content %}
<h1><a href="/{{ user_name }}/blog">{{ user_name }} - Blog Page</a></h1>
<div class="blog-title">{{ entry.title }}</div>
<div class="blog-created">{{ entry.created }}</div>
<div class="blog-created">{{ entry.view_datetime('created') }}</div>
<div class="blog-text">{{ entry.view_text()|safe }}</div>
<div class="blog-tags">
Tags:
Expand All @@ -19,7 +19,7 @@ <h1><a href="/{{ user_name }}/blog">{{ user_name }} - Blog Page</a></h1>
{% for comment in entry.comments %}
<div class="blog-entry-comment">
<div class="blog-entry-comment-title">{{ comment.title }}</div>
<div class="blog-entry-comment-created">{{ comment.created }}</div>
<div class="blog-entry-comment-created">{{ comment.view_datetime('created') }}</div>
<div class="blog-entry-comment-text">{{ comment.view_text()|safe }}</div>
<div class="blog-entry-comment-author">by {{ comment.user }}</div>
</div>
Expand Down
2 changes: 1 addition & 1 deletion app/templates/blog/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ <h1><a href="/{{ user_name }}/blog">{{ user_name }} - Blog Page</a></h1>
<div class="blog-title">
<a href="/{{ user_name }}/blog/{{ entry.key().id() }}">{{ entry.title }}</a>
</div>
<div class="blog-created">{{ entry.created }}</div>
<div class="blog-created">{{ entry.view_datetime('created') }}</div>
<div class="blog-text">{{ entry.view_text()|safe }}</div>
<div class="blog-tags">
Tags:
Expand Down
8 changes: 8 additions & 0 deletions app/templates/setting/image.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{% extends "app/base.html" %}
{% block title %}Setting/Image{% endblock %}
{% block content %}
<h1>Setting/Image</h1>
<div>
{{ form()|safe }}
</div>
{% endblock %}
59 changes: 59 additions & 0 deletions app/templates_compiled/base.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
from __future__ import division
from jinja2.runtime import LoopContext, TemplateReference, Macro, Markup, TemplateRuntimeError, missing, concat, escape, markup_join, unicode_join, to_string, TemplateNotFound
name = '\\base.html'

def root(context, environment=environment):
l_request = context.resolve('request')
if 0: yield None
yield u'<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">\n\n'
included_template = environment.get_template('auth/macros.html', '\\base.html').make_module(context.parent, True)
l_render_loginbox = getattr(included_template, 'render_loginbox', missing)
if l_render_loginbox is missing:
l_render_loginbox = environment.undefined("the template %r (imported on line 3 in '\\\\base.html') does not export the requested name 'render_loginbox'" % included_template.__name__, name='render_loginbox')
context.vars['render_loginbox'] = l_render_loginbox
context.exported_vars.discard('render_loginbox')
yield u'\n\n<html>\n <head>\n '
for event in context.blocks['head'][0](context):
yield event
yield u'\n </head>\n <body>\n '
if context.call(environment.getattr(environment.getattr(l_request, 'user'), 'is_anonymous')):
if 0: yield None
yield u'\n %s\n ' % (
escape(context.call(l_render_loginbox)),
)
else:
if 0: yield None
yield u'\n <div id="menu">\n '
for event in context.blocks['menu'][0](context):
yield event
yield u'\n </div>\n <div id="content">\n '
for event in context.blocks['content'][0](context):
yield event
yield u'\n </div>\n '
yield u'\n </body>\n</html>'

def block_content(context, environment=environment):
if 0: yield None
yield u'\n \n '

def block_menu(context, environment=environment):
l_create_logout_url = context.resolve('create_logout_url')
l_request = context.resolve('request')
if 0: yield None
yield u'\n <ul>\n <li><a href="/">My Page</a>\n <li><a href="/bbs">BBS</a>\n <li>Blog\n <ul>\n <li><a href="/%s/blog">My Blog</a>\n <li><a href="/blog/manage">Manage Entries</a>\n <li><a href="/blog/create">Create a Entry</a>\n </ul>\n <li><a href="/uploader">Uploader</a>\n <li>Setting\n <ul>\n <li><a href="/manage-profile">Profile</a>\n <li><a href="/setting/image">Image</a>\n </ul>\n <li><a href="%s">logout</a>\n </ul>\n ' % (
escape(environment.getattr(l_request, 'user')),
escape(context.call(l_create_logout_url)),
)

def block_head(context, environment=environment):
if 0: yield None
yield u'\n <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">\n \t <title>'
for event in context.blocks['title'][0](context):
yield event
yield u'</title>\n '

def block_title(context, environment=environment):
if 0: yield None

blocks = {'content': block_content, 'menu': block_menu, 'head': block_head, 'title': block_title}
debug_info = '1=8&3=9&7=16&10=18&13=19&14=22&15=26&17=27&35=29&38=30&40=32&42=33&38=35&17=39&23=44&33=45&7=48&9=51'
44 changes: 44 additions & 0 deletions app/templates_compiled/bbs/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
from __future__ import division
from jinja2.runtime import LoopContext, TemplateReference, Macro, Markup, TemplateRuntimeError, missing, concat, escape, markup_join, unicode_join, to_string, TemplateNotFound
name = '\\bbs\\index.html'

def root(context, environment=environment):
parent_template = None
if 0: yield None
parent_template = environment.get_template('app/base.html', '\\bbs\\index.html')
for name, parent_block in parent_template.blocks.iteritems():
context.blocks.setdefault(name, []).append(parent_block)
for event in parent_template.root_render_func(context):
yield event

def block_content(context, environment=environment):
l_paginator = context.resolve('paginator')
l_threads = context.resolve('threads')
l_form = context.resolve('form')
t_1 = environment.filters['safe']
if 0: yield None
yield u'\n <div>\n %s\n </div>\n <table>\n <tr><th>Auther</th><th>Title</th><th>Reply</th><th>Updated</th><th>Created</th></tr>\n ' % (
escape(t_1(context.call(l_form))),
)
l_thread = missing
for l_thread in environment.getattr(l_threads, 'object_list'):
if 0: yield None
yield u'\n <tr>\n <td>%s</td>\n <td><a href="/bbs/%s">%s</a></td>\n <td>%s</td>\n <td>%s</td>\n <td>%s</td>\n </tr>\n ' % (
escape(environment.getattr(environment.getattr(l_thread, 'user'), 'user_name')),
escape(context.call(environment.getattr(context.call(environment.getattr(l_thread, 'key')), 'id'))),
escape(environment.getattr(l_thread, 'title')),
escape(context.call(environment.getattr(environment.getattr(l_thread, 'comments'), 'count'))),
escape(context.call(environment.getattr(l_thread, 'view_datetime'), 'updated')),
escape(context.call(environment.getattr(l_thread, 'view_datetime'), 'created')),
)
l_thread = missing
yield u'\n </table>\n %s\n' % (
escape(t_1(l_paginator)),
)

def block_title(context, environment=environment):
if 0: yield None
yield u'BBS Page - app'

blocks = {'content': block_content, 'title': block_title}
debug_info = '1=8&3=14&5=21&9=24&11=27&12=28&13=30&14=31&15=32&17=35&19=36&2=39'
45 changes: 45 additions & 0 deletions app/templates_compiled/bbs/thread.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
from __future__ import division
from jinja2.runtime import LoopContext, TemplateReference, Macro, Markup, TemplateRuntimeError, missing, concat, escape, markup_join, unicode_join, to_string, TemplateNotFound
name = '\\bbs\\thread.html'

def root(context, environment=environment):
parent_template = None
if 0: yield None
parent_template = environment.get_template('app/base.html', '\\bbs\\thread.html')
for name, parent_block in parent_template.blocks.iteritems():
context.blocks.setdefault(name, []).append(parent_block)
for event in parent_template.root_render_func(context):
yield event

def block_content(context, environment=environment):
l_form = context.resolve('form')
l_thread = context.resolve('thread')
t_1 = environment.filters['safe']
if 0: yield None
yield u'\n <h1>%s</h1>\n <div>\n <dl class="info">\n <dt>Auther</dt><dd>%s</dd>\n <dt>Created</dt><dd>%s</dd>\n </dl>\n <div class="text">%s</div>\n </div>\n ' % (
escape(environment.getattr(l_thread, 'title')),
escape(environment.getattr(environment.getattr(l_thread, 'user'), 'user_name')),
escape(context.call(environment.getattr(l_thread, 'view_datetime'), 'created')),
escape(t_1(context.call(environment.getattr(l_thread, 'view_text')))),
)
l_comment = missing
for l_comment in environment.getattr(l_thread, 'comments'):
if 0: yield None
yield u'\n <div>\n <dl class="info">\n <dt>Auther</dt><dd>%s</dd>\n <dt>Created</dt><dd>%s</dd>\n </dl>\n <div class="text">%s</div>\n ' % (
escape(environment.getattr(environment.getattr(l_comment, 'user'), 'user_name')),
escape(context.call(environment.getattr(l_comment, 'view_datetime'), 'created')),
escape(t_1(context.call(environment.getattr(l_comment, 'view_text')))),
)
l_comment = missing
yield u'\n <div>\n %s\n </div>\n' % (
escape(t_1(context.call(l_form))),
)

def block_title(context, environment=environment):
l_thread = context.resolve('thread')
if 0: yield None
yield escape(environment.getattr(l_thread, 'title'))
yield u' - BBS Thread Page - app'

blocks = {'content': block_content, 'title': block_title}
debug_info = '1=8&3=14&4=20&7=21&8=22&10=23&12=26&15=29&16=30&18=31&19=34&21=35&2=38'
27 changes: 27 additions & 0 deletions app/templates_compiled/blog/create.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
from __future__ import division
from jinja2.runtime import LoopContext, TemplateReference, Macro, Markup, TemplateRuntimeError, missing, concat, escape, markup_join, unicode_join, to_string, TemplateNotFound
name = '\\blog\\create.html'

def root(context, environment=environment):
parent_template = None
if 0: yield None
parent_template = environment.get_template('app/base.html', '\\blog\\create.html')
for name, parent_block in parent_template.blocks.iteritems():
context.blocks.setdefault(name, []).append(parent_block)
for event in parent_template.root_render_func(context):
yield event

def block_content(context, environment=environment):
l_form = context.resolve('form')
t_1 = environment.filters['safe']
if 0: yield None
yield u'\n<h1>Create a Blog Entry</h1>\n<div>\n %s\n</div>\n' % (
escape(t_1(context.call(l_form))),
)

def block_title(context, environment=environment):
if 0: yield None
yield u'Create a Blog Entry - app'

blocks = {'content': block_content, 'title': block_title}
debug_info = '1=8&3=14&6=19&2=22'
29 changes: 29 additions & 0 deletions app/templates_compiled/blog/delete.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
from __future__ import division
from jinja2.runtime import LoopContext, TemplateReference, Macro, Markup, TemplateRuntimeError, missing, concat, escape, markup_join, unicode_join, to_string, TemplateNotFound
name = '\\blog\\delete.html'

def root(context, environment=environment):
parent_template = None
if 0: yield None
parent_template = environment.get_template('app/base.html', '\\blog\\delete.html')
for name, parent_block in parent_template.blocks.iteritems():
context.blocks.setdefault(name, []).append(parent_block)
for event in parent_template.root_render_func(context):
yield event

def block_content(context, environment=environment):
l_entry = context.resolve('entry')
t_1 = environment.filters['safe']
if 0: yield None
yield u'\n <h1>Delete a Blog Entry</h1>\n <div id="check-delete">\n <dl>\n <dt>Title\n <dd>%s\n <dt>Text\n <dd>%s\n </dl>\n </div>\n <div>\n <p>Do you delete this Entry ?</p>\n <ul>\n <li><a href="/blog/delete/%s">Yes</a>\n <li><a href="/blog/manage">No</a>\n </ul>\n </div>\n' % (
escape(environment.getattr(l_entry, 'title')),
escape(t_1(environment.getattr(l_entry, 'text'))),
escape(context.call(environment.getattr(context.call(environment.getattr(l_entry, 'key')), 'id'))),
)

def block_title(context, environment=environment):
if 0: yield None
yield u'Delete a Blog Entry - app'

blocks = {'content': block_content, 'title': block_title}
debug_info = '1=8&3=14&8=19&10=20&16=21&2=24'
Loading

0 comments on commit d642d9c

Please sign in to comment.