Permalink
Browse files

Trying to deal with editing pages/posts.

  • Loading branch information...
1 parent 8304a91 commit c6c89ebcbe74fc4c6d06cf68ac2efdbae8980e5b @pflarr committed Sep 20, 2011
@@ -18,6 +18,7 @@ basic_site.egg-info/not-zip-safe
basic_site.egg-info/paster_plugins.txt
basic_site.egg-info/requires.txt
basic_site.egg-info/top_level.txt
+basic_site/static/base.css
basic_site/static/favicon.ico
basic_site/static/footerbg.png
basic_site/static/headerbg.png
@@ -28,8 +29,9 @@ basic_site/static/pyramid-small.png
basic_site/static/pyramid.png
basic_site/static/transparent.gif
basic_site/templates/edit.mako
+basic_site/templates/files.mako
basic_site/templates/foot.mako
basic_site/templates/head.mako
-basic_site/templates/news.mako
+basic_site/templates/main.mako
basic_site/templates/page.mako
basic_site/templates/users.mako
View
@@ -27,21 +27,29 @@ def main(global_config, **settings):
authentication_policy=authn_policy,
authorization_policy=authz_policy)
config.add_static_view('static', 'basic_site:static')
- config.add_route('home', '/')
+ config.add_route('home', '')
config.add_view('basic_site.views.home',
route_name='home',
renderer='basic_site:templates/main.mako')
- config.add_route('users', '/users')
+ config.add_route('post','post/{id:\d+}')
+ XXXconfig.add_view('basic_site.views.post',
+ config.add_route('add', '{mode:add}/{ptype:(page|post)}')
+ config.add_route('edit', '{mode:edit}/{ptype:(page|port)}/{id}')
+ config.add_view('basic_site.views.edit', route_name='add',
+ renderer='basic_site:templates/edit.mako')
+ config.add_view('basic_site.views.edit', route_name='edit',
+ renderer='basic_site:templates/edit.mako')
+ config.add_route('users', 'users')
config.add_view('basic_site.views.users', route_name='users',
renderer='basic_site:templates/users.mako')
- config.add_route('file_rev', '/file/{rev}/{name}')
- config.add_route('file', '/file/{name}')
+ config.add_route('file_rev', 'file/{rev}/{name}')
+ config.add_route('file', 'file/{name}')
config.add_view('basic_site.views.file', route_name='file')
config.add_view('basic_site.views.file', route_name='file_rev')
- config.add_route('files', '/files/')
+ config.add_route('files', 'files/')
config.add_view('basic_site.views.files', route_name='files',
renderer='basic_site:templates/files.mako')
- config.add_route('logout', '/logout/')
+ config.add_route('logout', 'logout/')
config.add_view('basic_site.views.logout', route_name='logout')
return config.make_wsgi_app()
View
@@ -65,20 +65,21 @@ def change_pw(self, new):
class Post(Base):
__tablename__ = 'posts'
id = Column(Integer(), primary_key=True)
+ title = Column(String(30), nullable=False)
created = Column(DateTime(), nullable=False)
creator = Column(String(10), nullable=False)
sticky = Column(Boolean(), nullable=False)
- contents = Column(String(), nullable=False)
+ content = Column(String(), nullable=False)
- def __init__(self, creator, title, contents, sticky=False, created=None):
+ def __init__(self, creator, title, content, sticky=False, created=None):
if created:
self.created = created
else:
self.created = datetime.datetime.utcnow()
self.creator = creator
self.sticky = sticky
self.title = title[:30]
- self.contents = contents
+ self.content = content
def edit(self, title, content, sticky, user):
"""Edit this post, and record the change in the history."""
@@ -99,7 +100,7 @@ class Post_History(Base):
creator = Column(String(10), nullable=False)
sticky = Column(Boolean(), nullable=False)
title = Column(String(30), nullable=False)
- contents = Column(String(), nullable=False)
+ content = Column(String(), nullable=False)
def __init__(self, editor_uid, post):
for col in post.__table__.c:
@@ -117,7 +118,7 @@ def restore(self, user):
post.edit(user, self.title, self.content)
except sqlalchemy.orm.exc.NoResultFound:
# Recreate it if it doesn't still exist
- post = Post(user, self.title, self.contents, self.created)
+ post = Post(user, self.title, self.content, self.created)
session.add(page)
session.flush()
@@ -127,10 +128,10 @@ class Page(Base):
name = Column(String(15), unique=True)
created = Column(DateTime(), nullable=False)
creator = Column(String(10), nullable=False)
- contents = Column(String(), nullable=False)
+ content = Column(String(), nullable=False)
allowed_chars = ['abcdefghijklmnopqrstuvwxyz0123456789 _-']
- def __init__(self, creator, name, contents, created=None):
+ def __init__(self, creator, name, content, created=None):
if created:
self.created = created
else:
@@ -139,7 +140,7 @@ def __init__(self, creator, name, contents, created=None):
self.name = ''.join([c if c.lower() in self.allowed_chars else '_'
for c in name[:15]])
self.creator = creator
- self.contents = contents
+ self.content = content
def edit(self, name, content, user):
"""Edit this post, and record the change in the history."""
@@ -158,7 +159,7 @@ class Page_History(Base):
changed_by = Column(String(10), ForeignKey(User.uid), nullable=False)
created = Column(DateTime(), nullable=False)
creator = Column(String(10), nullable=False)
- contents = Column(String(), nullable=False)
+ content = Column(String(), nullable=False)
def __init__(self, editor_uid, page):
for col in page.__table__.c:
@@ -176,7 +177,7 @@ def restore(self, user):
page.edit(self.content, user)
except sqlalchemy.orm.exc.NoResultFound:
# Recreate it if it doesn't still exist
- page = Page(user, self.name, self.contents, self.created)
+ page = Page(user, self.name, self.content, self.created)
session.add(page)
session.flush()
@@ -1,34 +1,37 @@
<%include file="head.mako" />
<%
-if mode == 'edit_post':
- content = post.content
-elif mode == 'edit_page':
- content = page.content
+if mode == 'edit':
+ content = data.content
else:
content = ''
%>
-<DIV id="main">
+<DIV id="content">
<DIV id="instructions">
</DIV>
- <FORM action="${save_url}" method="post">
- % if mode == 'new_post':
- <INPUT name="title" type="text" size="30" maxlength="30">
- % elif mode == 'edit_post':
- <INPUT name="id" type="hidden" value="${post.name}">
- <INPUT name="title" type="text" size="30"
- maxlength="30" value=${post.title}>
- % elif mode == 'new_page':
- <INPUT name="name" type="text" size="15" maxlength="15">
- % elif mode == 'edit_page':
- <INPUT name="old_name" type="hidden" value="${page.name}">
- <INPUT name="name" type="text" size="15" maxlength="15">
+ <FORM action="${request.route_url('add',mode='add',ptype='post')}"
+ method="post">
+ % if ptype == 'post':
+ <LABEL for="title">Post Title:</LABEL>
+ <INPUT name="title" type="text" size="30" maxlength="30"
+ value="${data.title if data else ''|h}"><BR/>
+ % elif ptype == 'page':
+ <LABEL for="name">Page Name:</LABEL>
+ <INPUT name="name" type="text" size="15" maxlength="15"
+ value="${data.name if data else ''}"><BR/>
% endif
- <TEXTAREA name="content" rows="50" cols="160">${content}</TEXTAREA>
+ % if (mode,ptype) == ('edit','page'):
+ <INPUT name="old_name" type="hidden" value="${data.name}">
+ % endif
+ <LABEL for="content">${ptype.capitalize()} content:</LABEL><BR/>
+ <TEXTAREA name="content" rows="20" cols="80">${content}</TEXTAREA>
<INPUT name="mode" type="hidden" value="${mode}">
+ <INPUT name="ptype" type="hidden" value="${ptype}"><BR/>
+ <BUTTON type="submit" name="action" value="submit">Submit</BUTTON>
+ <BUTTON type="submit" name="action" value="preview">Preview</BUTTON>
</FORM>
</DIV>
@@ -21,8 +21,10 @@
% endif
</DIV>
-% if message:
- <DIV class="message">${message|h}</DIV>
+% if msg:
+ % for item in msg:
+ <DIV class="message">${item|h}</DIV>
+ % endfor
% endif
</DIV>
@@ -1,12 +1,18 @@
<%include file="head.mako" />
+
<DIV id="content">
+% if user:
+<DIV><A href="${request.route_url('add', ptype='post', mode='add')}"
+ >Add a new Post</A></DIV>
+% endif
% for post in posts:
<DIV class="news">
${post.content}
<DIV class="news_footer">
<SPAN class="creator">${post.creator|h}</SPAN>
<SPAN class="created">${post.created|h}</SPAN>
+ <A href="${request.route_url('edit', post.id)}"></A>
</DIV>
</DIV>
% endfor
Oops, something went wrong.

0 comments on commit c6c89eb

Please sign in to comment.