Permalink
Browse files

Merged the concepts of pages and posts. Pages are now just a grouping…

… of posts.
  • Loading branch information...
1 parent 9c776fb commit cafdc6f3cd0d2be03ecebf9e49a9d8c8878cc1ae @pflarr committed Dec 21, 2011
View
1 TODO
@@ -3,6 +3,5 @@ Fix internal links
Add a basic theme.css
Add a default logo
Add a default site.css
-Enforce user permissions
Make it pretty.
View
@@ -28,34 +28,46 @@ def main(global_config, **settings):
authorization_policy=authz_policy)
config.add_static_view('static', 'basic_site:static')
config.add_route('home', '')
- config.add_view('basic_site.views.home',
- route_name='home',
+ config.add_view('basic_site.views.posts',
+ route_name='home', permission='view',
renderer='basic_site:templates/main.mako')
+ config.add_route('posts', r'p/{page:[a-zA-Z0-9_ -]+}/{skip:\d*}')
+ config.add_view('basic_site.views.posts', route_name='posts',
+ renderer='basic_site:templates/main.mako',
+ permission='view')
config.add_route('post',r'post/{id:\d+(\.\d+)?}')
config.add_view('basic_site.views.post', route_name='post',
- renderer='basic_site:templates/post.mako')
- config.add_route('page',r'page/{name:[a-z0-9_ -]+(\.\d+)?}')
- config.add_view('basic_site.views.page', route_name='page',
- renderer='basic_site:templates/page.mako')
- config.add_route('add', 'add/{ptype:(page|post)}')
- config.add_route('edit', 'edit/{ptype:(page|post)}/{id}')
+ renderer='basic_site:templates/post.mako',
+ permission='view')
+ config.add_route('new_page', 'new_page')
+ config.add_view('basic_site.views.new_page', route_name='new_page',
+ renderer='basic_site:templates/new_page.mako',
+ permission='edit')
+ config.add_route('add', 'add/{page:[a-zA-Z0-9_ -]+}')
config.add_view('basic_site.views.edit', route_name='add',
- renderer='basic_site:templates/edit.mako')
+ renderer='basic_site:templates/edit.mako',
+ permission='edit')
+ config.add_route('edit', 'edit/{id:\d+}')
config.add_view('basic_site.views.edit', route_name='edit',
- renderer='basic_site:templates/edit.mako')
- config.add_route('restore', 'restore/{ptype:(page|post)}/'
- '{id:[a-z0-9_ -]+)/{skip:\d+}')
- config.add_view('basic_site.views.restore', route_name='restore')
+ renderer='basic_site:templates/edit.mako',
+ permission='edit')
+ config.add_route('restore', 'restore/{id:[a-z0-9_ -]+)/{version:\d+}')
+ config.add_view('basic_site.views.restore', route_name='restore',
+ permission='edit')
config.add_route('users', 'users')
config.add_view('basic_site.views.users', route_name='users',
- renderer='basic_site:templates/users.mako')
+ renderer='basic_site:templates/users.mako',
+ permission='edit')
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_view('basic_site.views.file', route_name='file',
+ permission='view')
+ config.add_view('basic_site.views.file', route_name='file_rev',
+ permission='view')
config.add_route('files', 'files/')
config.add_view('basic_site.views.files', route_name='files',
- renderer='basic_site:templates/files.mako')
+ renderer='basic_site:templates/files.mako',
+ permission='edit')
config.add_route('logout', 'logout/')
config.add_view('basic_site.views.logout', route_name='logout')
return config.make_wsgi_app()
View
@@ -2,6 +2,7 @@
from creole.html_emitter import HtmlEmitter
import datetime
+import re
from sqlalchemy import create_engine, Column, ForeignKey
from sqlalchemy.ext.declarative import declarative_base
@@ -34,6 +35,12 @@ def initialize_sql(engine):
if not admin:
admin = User('admin', DEFAULT_ADMIN_PW, True, 'Admin')
session.add(admin)
+
+ msg = "The default admin password is: '%s'. CHANGE IT! Until it "\
+ "is changed, anyone can log in as an admin." % DEFAULT_ADMIN_PW
+ post = Post('admin', 'Home', 'CHANGE THE DEFAULT PASSWORD!', msg,
+ sticky=True)
+ session.add(post)
session.flush()
transaction.commit()
@@ -69,19 +76,26 @@ def change_pw(self, new):
self.pw_hash = manager.encodePassword(new)
class Post(Base):
+ PAGE_RE_STR = r'[a-zA-Z0-9_ -]{1,30}'
+ PAGE_RE = re.compile('^%s$' % PAGE_RE_STR)
__tablename__ = 'posts'
- id = Column(Integer(), primary_key=True)
+ id = Column(Integer, primary_key=True)
+ page = Column(String(30))
title = Column(String(30), nullable=False)
created = Column(DateTime(), nullable=False)
creator = Column(String(10), nullable=False)
sticky = Column(Boolean(), nullable=False)
content = Column(String(), nullable=False)
- def __init__(self, creator, title, content, sticky=False, created=None):
+ def __init__(self, creator, page, title, content,
+ sticky=False, created=None):
if created:
self.created = created
else:
self.created = datetime.datetime.utcnow()
+ if not self.PAGE_RE.match(page):
+ raise ValueError("Invalid Page Name")
+ self.page = page
self.creator = creator
self.sticky = sticky
self.title = title[:30]
@@ -107,6 +121,7 @@ def render(self):
class Post_History(Base):
__tablename__ = 'post_history'
hist_id = Column(Integer(), primary_key=True)
+ page = Column(String(30), nullable=False)
id = Column(Integer(), nullable=False)
changed_on = Column(DateTime(), nullable=False)
changed_by = Column(String(10), ForeignKey(User.uid), nullable=False)
@@ -126,7 +141,7 @@ def __init__(self, editor_uid, post):
self.changed_by = editor_uid
self.changed_on = datetime.datetime.utcnow()
- def restore(self, user):
+ def restore(self, user, current):
"""Restore this history item's content. Returns an item to add to
the db/session."""
if current:
@@ -140,75 +155,6 @@ def render(self):
doc = Parser(self.content).parse()
return BS_Emitter(doc).emit()
-
-class Page(Base):
- __tablename__ = 'pages'
- id = Column(Integer(), primary_key=True)
- name = Column(String(15), unique=True)
- created = Column(DateTime(), nullable=False)
- creator = Column(String(10), nullable=False)
- content = Column(String(), nullable=False)
-
- allowed_chars = 'abcdefghijklmnopqrstuvwxyz0123456789 _-'
- def __init__(self, creator, name, content, created=None):
- if created:
- self.created = created
- else:
- self.created = datetime.datetime.utcnow()
-
- self.name = ''.join([c if c.lower() in self.allowed_chars else '_'
- for c in name[:15]])
- self.creator = creator
- self.content = content
-
- def edit(self, user, name, content, created=None):
- """Edit this page, and return the history table entry."""
- hist = Page_History(user, self)
- self.name = name
- self.content = content
- if created:
- self.created = datetime.datetime.utcnow()
- else:
- self.created = created
- return hist
-
- def render(self):
- doc = Parser(self.content).parse()
- return BS_Emitter(doc).emit()
-
-class Page_History(Base):
- __tablename__ = 'page_history'
- hist_id = Column(Integer(), primary_key=True)
- id = Column(Integer(), nullable=False)
- name = Column(String(15), nullable=False)
- changed_on = Column(DateTime(), nullable=False)
- changed_by = Column(String(10), ForeignKey(User.uid), nullable=False)
- created = Column(DateTime(), nullable=False)
- creator = Column(String(10), nullable=False)
- content = Column(String(), nullable=False)
-
- def __init__(self, editor_uid, page):
- self.id = page.id
- self.name = page.name
- self.created = page.created
- self.creator = page.creator
- self.content = page.content
- self.changed_by = editor_uid
- self.changed_on = datetime.datetime.utcnow()
-
- def restore(self, user, current):
- """Restore this history item's content, returns a list of rows to
- add to the session."""
-
- if current:
- return current.edit(user, self.name, self.content, self.created)
- else:
- return Page(user, self.name, self.content, self.created)
-
- def render(self):
- doc = Parser(self.content).parse()
- return BS_Emitter(doc).emit()
-
class File(Base):
__tablename__ = 'files';
id = Column(Integer, primary_key=True)
View
@@ -7,19 +7,16 @@
import sqlalchemy.orm
-
def groupfinder(uid, request):
"""There are only two groups: 'editor' and 'admin'. The only difference
is that only administrators can add users and edit certain files
(like the logo and custom.css)."""
if not uid:
return None
session = DBSession()
- try:
- user = session.query(User)\
- .filter(User.uid == uid)\
- .one()
- except sqlalchemy.orm.exc.NoResultFound:
+ user = session.query(User).get(uid)
+
+ if not user:
return None
groups = ['group:editors']
View
@@ -1,13 +1,20 @@
div.head {
border: 1px solid blue;
+ margin-bottom: 10px;
+ padding: 5px;
}
div.login {
float: right;
+ clear: left;
font-size: small;
margin-bottom: 6px;
}
+div.login form {
+ margin: 0px;
+}
+
div.login input {
border: 1px black solid;
font-size: small;
@@ -18,10 +25,12 @@ div.login button {
font-size: small;
}
-div.head div.message {
+div.message {
font-weight: bold;
- float: right;
- clear: right;
+ border: 1px red solid;
+ background: white;
+ margin-bottom: 6px;
+ padding: 5px;
}
div.pages {
@@ -52,13 +61,27 @@ div.main {
}
div.content {
- margin-left: 210px;
- padding: 10px;
+ margin-left: 215px;
border: 1px solid red;
}
+div.content > div {
+ padding: 10px;
+ margin-bottom: 6px;
+}
+
div.post {
margin-bottom: 5px;
border: 1px solid blue;
}
+table {
+ border-collapse: collapse;
+}
+
+table td, table th {
+ padding: 3px;
+ padding-right: 6px;
+ padding-bottom: 1px;
+}
+
@@ -2,11 +2,7 @@
% if data:
<DIV class="post">
- % if ptype=="post":
- <H2 class="preview">Preview: ${data.title}</H2>
- % elif ptype=="page":
- <H2 class="preview">Preview: ${data.name}</H2>
- % endif
+ <H2 class="preview">Preview: ${data.title}</H2>
${data.render()|n}
<DIV class="post_footer">
<SPAN class="creator">${data.creator|h}</SPAN>
@@ -15,30 +11,23 @@
</DIV>
% endif
<DIV id="instructions">
-
+Insert wiki syntax instructions here.
+</DIV>
+
+<DIV>
+ <FORM action="${request.route_url(mode, page=page, id=id)}"
+ method="post">
+ <LABEL for="title">Post Title:</LABEL>
+ <INPUT name="title" type="text" size="30" maxlength="30"
+ value="${data.title if data else ''|h}"><BR/>
+ <LABEL for="content">Post content:</LABEL><BR/>
+ <%
+ content = data.content if data else ''
+ %>
+ <TEXTAREA name="content" rows="20" cols="80">${content}</TEXTAREA><BR>
+ <BUTTON type="submit" name="action" value="submit">Submit</BUTTON>
+ <BUTTON type="submit" name="action" value="preview">Preview</BUTTON>
+ </FORM>
</DIV>
-
-<FORM action="${request.route_url(mode,ptype=ptype,id=id)}"
- 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
-% if (mode,ptype) == ('edit','page'):
- <INPUT name="old_name" type="hidden" value="${data.name}">
-% endif
- <LABEL for="content">${ptype.capitalize()} content:</LABEL><BR/>
-<%
- content = data.content if data else ''
-%>
- <TEXTAREA name="content" rows="20" cols="80">${content}</TEXTAREA><BR>
- <BUTTON type="submit" name="action" value="submit">Submit</BUTTON>
- <BUTTON type="submit" name="action" value="preview">Preview</BUTTON>
-</FORM>
<%include file="foot.mako" />
Oops, something went wrong.

0 comments on commit cafdc6f

Please sign in to comment.