Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Initial commit.

  • Loading branch information...
commit cb472c41d8a1dbdd0b4b71c0806753df15b15f5c 0 parents
@pflarr authored
Showing with 770 additions and 0 deletions.
  1. +4 −0 CHANGES.txt
  2. +2 −0  MANIFEST.in
  3. +4 −0 README.txt
  4. +25 −0 basic_site.egg-info/PKG-INFO
  5. +29 −0 basic_site.egg-info/SOURCES.txt
  6. +1 −0  basic_site.egg-info/dependency_links.txt
  7. +3 −0  basic_site.egg-info/entry_points.txt
  8. +1 −0  basic_site.egg-info/not-zip-safe
  9. +1 −0  basic_site.egg-info/paster_plugins.txt
  10. +6 −0 basic_site.egg-info/requires.txt
  11. +1 −0  basic_site.egg-info/top_level.txt
  12. +20 −0 basic_site/__init__.py
  13. +165 −0 basic_site/models.py
  14. +94 −0 basic_site/security.py
  15. BIN  basic_site/static/favicon.ico
  16. BIN  basic_site/static/footerbg.png
  17. BIN  basic_site/static/headerbg.png
  18. +8 −0 basic_site/static/ie6.css
  19. BIN  basic_site/static/middlebg.png
  20. +65 −0 basic_site/static/pylons.css
  21. BIN  basic_site/static/pyramid-small.png
  22. BIN  basic_site/static/pyramid.png
  23. BIN  basic_site/static/transparent.gif
  24. +1 −0  basic_site/templates/foot.mako
  25. +32 −0 basic_site/templates/head.mako
  26. +15 −0 basic_site/templates/news.mako
  27. +12 −0 basic_site/templates/page.mako
  28. +24 −0 basic_site/tests.py
  29. +41 −0 basic_site/views.py
  30. +65 −0 development.ini
  31. +77 −0 production.ini
  32. +27 −0 setup.cfg
  33. +47 −0 setup.py
4 CHANGES.txt
@@ -0,0 +1,4 @@
+0.0
+---
+
+- Initial version
2  MANIFEST.in
@@ -0,0 +1,2 @@
+include *.txt *.ini *.cfg *.rst
+recursive-include basic_site *.ico *.png *.css *.gif *.jpg *.pt *.txt *.mak *.mako *.js *.html *.xml
4 README.txt
@@ -0,0 +1,4 @@
+basic_site README
+
+
+
25 basic_site.egg-info/PKG-INFO
@@ -0,0 +1,25 @@
+Metadata-Version: 1.0
+Name: basic-site
+Version: 0.0
+Summary: basic_site
+Home-page: UNKNOWN
+Author: UNKNOWN
+Author-email: UNKNOWN
+License: UNKNOWN
+Description: basic_site README
+
+
+
+
+
+ 0.0
+ ---
+
+ - Initial version
+
+Keywords: web wsgi bfg pylons pyramid
+Platform: UNKNOWN
+Classifier: Programming Language :: Python
+Classifier: Framework :: Pylons
+Classifier: Topic :: Internet :: WWW/HTTP
+Classifier: Topic :: Internet :: WWW/HTTP :: WSGI :: Application
29 basic_site.egg-info/SOURCES.txt
@@ -0,0 +1,29 @@
+CHANGES.txt
+MANIFEST.in
+README.txt
+development.ini
+production.ini
+setup.cfg
+setup.py
+basic_site/__init__.py
+basic_site/models.py
+basic_site/tests.py
+basic_site/views.py
+basic_site.egg-info/PKG-INFO
+basic_site.egg-info/SOURCES.txt
+basic_site.egg-info/dependency_links.txt
+basic_site.egg-info/entry_points.txt
+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/favicon.ico
+basic_site/static/footerbg.png
+basic_site/static/headerbg.png
+basic_site/static/ie6.css
+basic_site/static/middlebg.png
+basic_site/static/pylons.css
+basic_site/static/pyramid-small.png
+basic_site/static/pyramid.png
+basic_site/static/transparent.gif
+basic_site/templates/mytemplate.pt
1  basic_site.egg-info/dependency_links.txt
@@ -0,0 +1 @@
+
3  basic_site.egg-info/entry_points.txt
@@ -0,0 +1,3 @@
+ [paste.app_factory]
+ main = basic_site:main
+
1  basic_site.egg-info/not-zip-safe
@@ -0,0 +1 @@
+
1  basic_site.egg-info/paster_plugins.txt
@@ -0,0 +1 @@
+pyramid
6 basic_site.egg-info/requires.txt
@@ -0,0 +1,6 @@
+pyramid
+SQLAlchemy
+transaction
+repoze.tm2>=1.0b1
+zope.sqlalchemy
+WebError
1  basic_site.egg-info/top_level.txt
@@ -0,0 +1 @@
+basic_site
20 basic_site/__init__.py
@@ -0,0 +1,20 @@
+from pyramid.config import Configurator
+from pyramid.session import UnencryptedCookieSessionFactoryConfig
+from sqlalchemy import engine_from_config
+
+from basic_site.models import initialize_sql
+
+def main(global_config, **settings):
+ """ This function returns a Pyramid WSGI application.
+ """
+ engine = engine_from_config(settings, 'sqlalchemy.')
+ initialize_sql(engine)
+ session_factory = UnencryptedCookieSessionFactoryConfig()
+ config = Configurator(settings=settings, session_factory=session_factory)
+ config.add_static_view('static', 'basic_site:static')
+ config.add_route('Main', '/')
+ config.add_view('basic_site.views.Main',
+ route_name='home',
+ renderer='templates/main.mako')
+ return config.make_wsgi_app()
+
165 basic_site/models.py
@@ -0,0 +1,165 @@
+from sqlalchemy import create_engine, Column, ForeignKey
+from sqlalchemy.orm import sessionmaker, scoped_session
+from sqlalchemy.ext.declarative import declarative_base
+from sqlalchemy.types import String, DateTime, Integer, Boolean
+
+from zope.sqlalchemy import ZopeTransactionExtension
+
+from z3c.bcrypt import BcryptPasswordManager
+manager = BcryptPasswordManager()
+
+import sqlalchemy.orm
+
+DBSession = scoped_session(sessionmaker(extension=ZopeTransactionExtension()))
+Base = declarative_base()
+
+def initialize_sql(engine):
+ DBSession.configure(bind=engine)
+ Base.metadata.bind = engine
+ Base.metadata.create_all(engine)
+
+class User(Base):
+ __tablename__ = 'Users'
+ uid = Column(String(10), primary_key=True)
+ pw_hash = Column(String())
+ fullname = Column(String())
+
+ def __init__(self, name, pw, fullname):
+ self.uid = name[:10]
+ self.pw_hash = manager.encodePassword(pw)
+ self.fullname = fullname
+
+ def check_pw(self, passwd):
+ return manager.checkPassword(self.pw_hash, passwd)
+
+ def change_pw(self, old, new):
+ """Verifies the old pw before changing it to new. Returns True if
+ successful."""
+ if manager.checkPassword(self.pw_hash, old):
+ self.pw_hash = manager.encodePassword(pw)
+ return True
+ else:
+ return False
+
+class UserSession(Base):
+ __tablename__ = 'Sessions'
+ id = Column(String(), primary_key=True)
+ last_used = Column(DateTime(), nullable=False)
+ ip = Column(Integer(), nullable=False)
+ user = Column(String(10), ForeignKey(User.uid))
+
+ def __init__(self, ip):
+ now = datetime.datetime.utcnow()
+ md5 = hashlib.md5(ip)
+ md5.update(randome.randint(1,0xffffffff))
+ self.id = md5.hexdigest()
+ self.last_used = now
+ self.ip = ip
+
+class Post(Base):
+ __tablename__ = 'Post'
+ id = Column(Integer(), primary_key=True)
+ created = Column(DateTime(), nullable=False)
+ creator = Column(String(10), nullable=False)
+ sticky = Column(Boolean(), nullable=False)
+ contents = Column(String(), nullable=False)
+
+ def __init__(self, creator, title, contents, sticky=False):
+ if created:
+ self.created = created
+ else:
+ self.created = datetime.datetime.utcnow()
+ self.creator = creator
+ self.sticky = sticky
+ self.title = title[:30]
+ self.contents = contents
+
+ def edit(self, user, new_title, new_content):
+ """Edit this post, and record the change in the history."""
+ session = DBSession()
+ hist = Post_History(user, self)
+ self.title = new_title[:30]
+ self.content = new_content
+ session.add(hist)
+
+class Post_History(Base):
+ id = Column(Integer(), nullable=False)
+ created = Column(DateTime(), nullable=False)
+ creator = Column(String(10), nullable=False)
+ sticky = Column(Boolean(), nullable=False)
+ title = Column(String(30), nullable=False)
+ contents = Column(String(), nullable=False)
+ changed_by = Column(String(10), ForiegnKey(Users.uid), nullable=False)
+ changed_on = Column(DateTime(), nullable=False)
+
+ def __init__(self, editor_uid, post):
+ for col in post.__table__.c:
+ self.__table__[col] = post.__table__.c[col]
+ self.changed_by = editor_uid
+ self.changed_on = datetime.datetime.utcnow()
+
+ def restore(self, user):
+ """Restore this history item's content."""
+ session = DBSession()
+ try:
+ post = session.query(Post)\
+ .filter(Post.id = self.id)\
+ .one()
+ 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)
+ session.add(page)
+ session.flush()
+
+class Page(Base):
+ __tablename__ = 'Page'
+ name = Column(String(15), primary_key=True)
+ created = Column(DateTime(), nullable=False)
+ creator = Column(String(10), nullable=False)
+ contents = Column(String(), nullable=False)
+
+ def __init__(self, creator, name, contents, created=None):
+ if created:
+ self.created = created
+ else:
+ self.created = datetime.datetime.utcnow()
+ self.name = name[:15]
+ self.creator = creator
+ self.contents = contents
+
+ def edit(self, new_name, new_content, user):
+ """Edit this post, and record the change in the history."""
+ session = DBSession()
+ hist = Page_History(user, self)
+ self.name = new_name
+ self.content = new_content
+ session.add(hist)
+
+class Page_History(Base):
+ name = Column(String(15), nullable=False)
+ created = Column(DateTime(), nullable=False)
+ creator = Column(String(10), nullable=False)
+ contents = Column(String(), nullable=False)
+ changed_by = Column(String(10), ForiegnKey(Users.uid), nullable=False)
+ changed_on = Column(DateTime(), nullable=False)
+
+ def __init__(self, editor_uid, page):
+ for col in page.__table__.c:
+ self.__table__[col] = page.__table__.c[col]
+ self.changed_by = editor_uid
+ self.changed_on = datetime.datetime.utcnow()
+
+ def restore(self, user):
+ """Restore this history item's content."""
+ session = DBSession()
+ try:
+ page = session.query(Page)\
+ .filter(Page.id = self.id)\
+ .one()
+ 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)
+ session.add(page)
+ session.flush()
94 basic_site/security.py
@@ -0,0 +1,94 @@
+import datetime
+
+from models import UserSession, User
+
+class Auth:
+ session_expire = datetime.timedelta(hours=2)
+ def __init__(self, request):
+ self.error = None
+ self.user = None
+ self.session = None
+ self.ip = None
+
+ if 'HTTP_COOKIE' in env:
+ try:
+ cookie = request.cookie
+ except:
+ cookie = None
+ else:
+ cookie = None
+
+ if cookie:
+ sessionkey = cookie.get('session').value
+ else:
+ sessionkey = None
+
+ ip = env.get('REMOTE_ADDR', 0)
+ if ip:
+ try:
+ ip = ip.split('.')
+ ip = map(int, ip)
+ ip = ip[0] << 24 + ip[1] << 16 + ip[2] << 8 + ip[3]
+ except:
+ ip = 0
+
+ if ip == 0:
+ return
+
+ if sessionkey:
+ q = session.query(UserSession)\
+ .filter(UserSession.id == sessionkey)\
+ .filter(UserSession.ip == ip)\
+ .filter(UserSession.last_used >
+ (now - self.session_expire))
+ try:
+ user_sess = q.one()
+ except:
+ # Couldn't find a matching session
+ sessionkey = None
+
+ # If they don't have a session key already, make them one.
+ if not sessionkey:
+ user_sess = UserSession(ip)
+ session.add(user_sess)
+ self.ip = ip
+ self.session = user_sess.id
+ request.response.set_cookie('session', self.session)
+ return
+
+ q = session.query(UserSession)
+ q.filter(UserSession.last_used < (now - self.session_expire))
+ q.delete()
+
+ # At this point, we should have a user_sess object and a
+ # session key. Now we'll check to see if the session key is logged in,
+ # or if the user is trying to log in.
+ request.response.set_cookie('session', self.session)
+ self.session = sessionkey
+ self.ip = ip
+ user_sess.last_used = now
+ session.commit()
+ if user_sess.user:
+ # Already logged in
+ self.user = user_sess.user
+ return
+
+ # If they aren't trying to log in, we're done.
+ if 'user' not in form or 'passwd' not in form:
+ return
+
+ uid = form.get_first('user')
+ passwd = form.get_first('passwd')
+ try:
+ user = session.query(User).filter(User.uid = uid).one()
+ except:
+ self.error = "No such user: %s" % uid
+ return
+
+ if user.check_pw(passwd):
+ self.user = uid
+ else:
+ self.error = "Invalid Password"
+
+ def logged_in(self):
+ return self.user is not None
BIN  basic_site/static/favicon.ico
Binary file not shown
BIN  basic_site/static/footerbg.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
BIN  basic_site/static/headerbg.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
8 basic_site/static/ie6.css
@@ -0,0 +1,8 @@
+* html img,
+* html .png{position:relative;behavior:expression((this.runtimeStyle.behavior="none")&&(this.pngSet?this.pngSet=true:(this.nodeName == "IMG" && this.src.toLowerCase().indexOf('.png')>-1?(this.runtimeStyle.backgroundImage = "none",
+this.runtimeStyle.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='" + this.src + "',sizingMethod='image')",
+this.src = "static/transparent.gif"):(this.origBg = this.origBg? this.origBg :this.currentStyle.backgroundImage.toString().replace('url("','').replace('")',''),
+this.runtimeStyle.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='" + this.origBg + "',sizingMethod='crop')",
+this.runtimeStyle.backgroundImage = "none")),this.pngSet=true)
+);}
+#wrap{display:table;height:100%}
BIN  basic_site/static/middlebg.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
65 basic_site/static/pylons.css
@@ -0,0 +1,65 @@
+html,body,div,span,applet,object,iframe,h1,h2,h3,h4,h5,h6,p,blockquote,pre,a,abbr,acronym,address,big,cite,code,del,dfn,em,font,img,ins,kbd,q,s,samp,small,strike,strong,sub,sup,tt,var,b,u,i,center,dl,dt,dd,ol,ul,li,fieldset,form,label,legend,table,caption,tbody,tfoot,thead,tr,th,td{margin:0;padding:0;border:0;outline:0;font-size:100%;/* 16px */
+vertical-align:baseline;background:transparent;}
+body{line-height:1;}
+ol,ul{list-style:none;}
+blockquote,q{quotes:none;}
+blockquote:before,blockquote:after,q:before,q:after{content:'';content:none;}
+:focus{outline:0;}
+ins{text-decoration:none;}
+del{text-decoration:line-through;}
+table{border-collapse:collapse;border-spacing:0;}
+sub{vertical-align:sub;font-size:smaller;line-height:normal;}
+sup{vertical-align:super;font-size:smaller;line-height:normal;}
+ul,menu,dir{display:block;list-style-type:disc;margin:1em 0;padding-left:40px;}
+ol{display:block;list-style-type:decimal-leading-zero;margin:1em 0;padding-left:40px;}
+li{display:list-item;}
+ul ul,ul ol,ul dir,ul menu,ul dl,ol ul,ol ol,ol dir,ol menu,ol dl,dir ul,dir ol,dir dir,dir menu,dir dl,menu ul,menu ol,menu dir,menu menu,menu dl,dl ul,dl ol,dl dir,dl menu,dl dl{margin-top:0;margin-bottom:0;}
+ol ul,ul ul,menu ul,dir ul,ol menu,ul menu,menu menu,dir menu,ol dir,ul dir,menu dir,dir dir{list-style-type:circle;}
+ol ol ul,ol ul ul,ol menu ul,ol dir ul,ol ol menu,ol ul menu,ol menu menu,ol dir menu,ol ol dir,ol ul dir,ol menu dir,ol dir dir,ul ol ul,ul ul ul,ul menu ul,ul dir ul,ul ol menu,ul ul menu,ul menu menu,ul dir menu,ul ol dir,ul ul dir,ul menu dir,ul dir dir,menu ol ul,menu ul ul,menu menu ul,menu dir ul,menu ol menu,menu ul menu,menu menu menu,menu dir menu,menu ol dir,menu ul dir,menu menu dir,menu dir dir,dir ol ul,dir ul ul,dir menu ul,dir dir ul,dir ol menu,dir ul menu,dir menu menu,dir dir menu,dir ol dir,dir ul dir,dir menu dir,dir dir dir{list-style-type:square;}
+.hidden{display:none;}
+p{line-height:1.5em;}
+h1{font-size:1.75em;line-height:1.7em;font-family:helvetica,verdana;}
+h2{font-size:1.5em;line-height:1.7em;font-family:helvetica,verdana;}
+h3{font-size:1.25em;line-height:1.7em;font-family:helvetica,verdana;}
+h4{font-size:1em;line-height:1.7em;font-family:helvetica,verdana;}
+html,body{width:100%;height:100%;}
+body{margin:0;padding:0;background-color:#ffffff;position:relative;font:16px/24px "Nobile","Lucida Grande",Lucida,Verdana,sans-serif;}
+a{color:#1b61d6;text-decoration:none;}
+a:hover{color:#e88f00;text-decoration:underline;}
+body h1,
+body h2,
+body h3,
+body h4,
+body h5,
+body h6{font-family:"NeutonRegular","Lucida Grande",Lucida,Verdana,sans-serif;font-weight:normal;color:#373839;font-style:normal;}
+#wrap{min-height:100%;}
+#header,#footer{width:100%;color:#ffffff;height:40px;position:absolute;text-align:center;line-height:40px;overflow:hidden;font-size:12px;vertical-align:middle;}
+#header{background:#000000;top:0;font-size:14px;}
+#footer{bottom:0;background:#000000 url(footerbg.png) repeat-x 0 top;position:relative;margin-top:-40px;clear:both;}
+.header,.footer{width:750px;margin-right:auto;margin-left:auto;}
+.wrapper{width:100%}
+#top,#top-small,#bottom{width:100%;}
+#top{color:#000000;height:230px;background:#ffffff url(headerbg.png) repeat-x 0 top;position:relative;}
+#top-small{color:#000000;height:60px;background:#ffffff url(headerbg.png) repeat-x 0 top;position:relative;}
+#bottom{color:#222;background-color:#ffffff;}
+.top,.top-small,.middle,.bottom{width:750px;margin-right:auto;margin-left:auto;}
+.top{padding-top:40px;}
+.top-small{padding-top:10px;}
+#middle{width:100%;height:100px;background:url(middlebg.png) repeat-x;border-top:2px solid #ffffff;border-bottom:2px solid #b2b2b2;}
+.app-welcome{margin-top:25px;}
+.app-name{color:#000000;font-weight:bold;}
+.bottom{padding-top:50px;}
+#left{width:350px;float:left;padding-right:25px;}
+#right{width:350px;float:right;padding-left:25px;}
+.align-left{text-align:left;}
+.align-right{text-align:right;}
+.align-center{text-align:center;}
+ul.links{margin:0;padding:0;}
+ul.links li{list-style-type:none;font-size:14px;}
+form{border-style:none;}
+fieldset{border-style:none;}
+input{color:#222;border:1px solid #ccc;font-family:sans-serif;font-size:12px;line-height:16px;}
+input[type=text],input[type=password]{width:205px;}
+input[type=submit]{background-color:#ddd;font-weight:bold;}
+/*Opera Fix*/
+body:before{content:"";height:100%;float:left;width:0;margin-top:-32767px;}
BIN  basic_site/static/pyramid-small.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
BIN  basic_site/static/pyramid.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
BIN  basic_site/static/transparent.gif
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1  basic_site/templates/foot.mako
@@ -0,0 +1 @@
+</BODY></HTML>
32 basic_site/templates/head.mako
@@ -0,0 +1,32 @@
+<HTML>
+<HEAD>
+ <TITLE>${request.registry.settings['site_name'] + page.subtitle|h}</TITLE>
+ <LINK type="text/css" rel="stylesheet"
+ href="${request.static_url(basic_site:static/base.css)}">
+</HEAD>
+<DIV id="head">
+ <IMG src="files/logo.png">
+ <FORM action='' method="POST">
+ Login:
+ <LABEL target="user">User</LABEL>
+ <INPUT type="text" name="user">
+ <LABEL target="passwd">Password</LABEL>
+ <INPUT type="password" name="passwd">
+ </FORM>
+</DIV>
+
+<%
+ def cur_class(this_page):
+ if this_page == page_name:
+ return 'class="current"'
+ else:
+ return ''
+%>
+<DIV id=pages>
+ <ul>
+ <LI><A href="news.cgi" ${cur_class('*Main')}>Main</A>
+ <LI><A href="album.cgi" ${cur_class('*Album')}>Album</A>
+ % for page in pages:
+ <LI><A href="page.cgi?page=${page.name|u}" ${cur_class(page.name)}>${page.name}</A>
+ % endfor
+</DIV>
15 basic_site/templates/news.mako
@@ -0,0 +1,15 @@
+<%include file="head.mako" />
+
+<DIV id="main">
+% for item in news:
+ <DIV class="news">
+ ${item.content}
+ <DIV class="news_footer">
+ <SPAN class="creator">${item.creator|h}</SPAN>
+ <SPAN class="created">${item.created|h}</SPAN>
+ </DIV>
+ </DIV>
+% endfor
+</DIV>
+
+<%include file="foot.mako" />
12 basic_site/templates/page.mako
@@ -0,0 +1,12 @@
+<%include file="head.mako" />
+
+<DIV id="main">
+ ${page.content}
+ <DIV class="page_footer">
+ <SPAN class="creator">${page.creator|h}</SPAN>
+ <SPAN class="created">${page.created|h}</SPAN>
+ </DIV>
+% endfor
+</DIV>
+
+<%include file="foot.mako" />
24 basic_site/tests.py
@@ -0,0 +1,24 @@
+import unittest
+from pyramid.config import Configurator
+from pyramid import testing
+
+def _initTestingDB():
+ from sqlalchemy import create_engine
+ from basic_site.models import initialize_sql
+ session = initialize_sql(create_engine('sqlite://'))
+ return session
+
+class TestMyView(unittest.TestCase):
+ def setUp(self):
+ self.config = testing.setUp()
+ _initTestingDB()
+
+ def tearDown(self):
+ testing.tearDown()
+
+ def test_it(self):
+ from basic_site.views import my_view
+ request = testing.DummyRequest()
+ info = my_view(request)
+ self.assertEqual(info['root'].name, 'root')
+ self.assertEqual(info['project'], 'basic_site')
41 basic_site/views.py
@@ -0,0 +1,41 @@
+from basic_site.models import DBSession
+from basic_site.models import Pages, Posts
+from basic_site.auth import Auth
+
+import sqlalchemy.orm
+
+def Main(request):
+ dbsession = DBSession()
+
+ context = {'auth': Auth(request)}
+
+ skip = request.matchdict.get('skip', 0)
+
+ posts = dbsession.query(Post)\
+ .order_by(Post.created)\
+ .skip(skip)\
+ .limit(5)\
+ .all()
+
+ context['posts'] = posts
+ context['page_name'] = '*Main'
+ context['page_subtitle'] = ''
+
+ return context
+
+def Page(request):
+ dbsession = DBSession()
+
+ context = {'auth': Auth(request)}
+
+ try:
+ page = dbsession.query(Page)\
+ .filter(Page.name == request.matchdict['page'])\
+ .one()
+ except sqlalchemy.orm.exc.NoResultFound:
+ return exception_response(404)
+
+ context['page'] = page
+ context['page_name'] = page.name
+ context['page_subtitle'] = '- %s' % page.name
+ return context
65 development.ini
@@ -0,0 +1,65 @@
+[app:basic_site]
+use = egg:basic_site
+reload_templates = true
+debug_authorization = false
+debug_notfound = false
+debug_routematch = false
+debug_templates = true
+default_locale_name = en
+sqlalchemy.url = sqlite:///%(here)s/basic_site.db
+file_path = /home/pflarr/tmp/files/
+site_name = "Basic Site GoshDarnit"
+
+[pipeline:main]
+pipeline =
+ egg:WebError#evalerror
+ tm
+ basic_site
+
+[filter:tm]
+use = egg:repoze.tm2#tm
+commit_veto = repoze.tm:default_commit_veto
+
+[server:main]
+use = egg:Paste#http
+host = 0.0.0.0
+port = 6543
+
+# Begin logging configuration
+
+[loggers]
+keys = root, basic_site, sqlalchemy
+
+[handlers]
+keys = console
+
+[formatters]
+keys = generic
+
+[logger_root]
+level = INFO
+handlers = console
+
+[logger_basic_site]
+level = DEBUG
+handlers =
+qualname = basic_site
+
+[logger_sqlalchemy]
+level = INFO
+handlers =
+qualname = sqlalchemy.engine
+# "level = INFO" logs SQL queries.
+# "level = DEBUG" logs SQL queries and results.
+# "level = WARN" logs neither. (Recommended for production systems.)
+
+[handler_console]
+class = StreamHandler
+args = (sys.stderr,)
+level = NOTSET
+formatter = generic
+
+[formatter_generic]
+format = %(asctime)s %(levelname)-5.5s [%(name)s][%(threadName)s] %(message)s
+
+# End logging configuration
77 production.ini
@@ -0,0 +1,77 @@
+[app:basic_site]
+use = egg:basic_site
+reload_templates = false
+debug_authorization = false
+debug_notfound = false
+debug_routematch = false
+debug_templates = false
+default_locale_name = en
+sqlalchemy.url = sqlite:///%(here)s/basic_site.db
+
+[filter:weberror]
+use = egg:WebError#error_catcher
+debug = false
+;error_log =
+;show_exceptions_in_wsgi_errors = true
+;smtp_server = localhost
+;error_email = janitor@example.com
+;smtp_username = janitor
+;smtp_password = "janitor's password"
+;from_address = paste@localhost
+;error_subject_prefix = "Pyramid Error"
+;smtp_use_tls =
+;error_message =
+
+[filter:tm]
+use = egg:repoze.tm2#tm
+commit_veto = repoze.tm:default_commit_veto
+
+[pipeline:main]
+pipeline =
+ weberror
+ tm
+ basic_site
+
+[server:main]
+use = egg:Paste#http
+host = 0.0.0.0
+port = 6543
+
+# Begin logging configuration
+
+[loggers]
+keys = root, basic_site, sqlalchemy
+
+[handlers]
+keys = console
+
+[formatters]
+keys = generic
+
+[logger_root]
+level = WARN
+handlers = console
+
+[logger_basic_site]
+level = WARN
+handlers =
+qualname = basic_site
+
+[logger_sqlalchemy]
+level = WARN
+handlers =
+qualname = sqlalchemy.engine
+# "level = INFO" logs SQL queries.
+# "level = DEBUG" logs SQL queries and results.
+# "level = WARN" logs neither. (Recommended for production systems.)
+
+[handler_console]
+class = StreamHandler
+args = (sys.stderr,)
+level = NOTSET
+formatter = generic
+
+[formatter_generic]
+format = %(asctime)s %(levelname)-5.5s [%(name)s][%(threadName)s] %(message)s
+
+# End logging configuration
27 setup.cfg
@@ -0,0 +1,27 @@
+[nosetests]
+match=^test
+nocapture=1
+cover-package=basic_site
+with-coverage=1
+cover-erase=1
+
+[compile_catalog]
+directory = basic_site/locale
+domain = basic_site
+statistics = true
+
+[extract_messages]
+add_comments = TRANSLATORS:
+output_file = basic_site/locale/basic_site.pot
+width = 80
+
+[init_catalog]
+domain = basic_site
+input_file = basic_site/locale/basic_site.pot
+output_dir = basic_site/locale
+
+[update_catalog]
+domain = basic_site
+input_file = basic_site/locale/basic_site.pot
+output_dir = basic_site/locale
+previous = true
47 setup.py
@@ -0,0 +1,47 @@
+import os
+import sys
+
+from setuptools import setup, find_packages
+
+here = os.path.abspath(os.path.dirname(__file__))
+README = open(os.path.join(here, 'README.txt')).read()
+CHANGES = open(os.path.join(here, 'CHANGES.txt')).read()
+
+requires = [
+ 'pyramid',
+ 'SQLAlchemy',
+ 'transaction',
+ 'repoze.tm2>=1.0b1', # default_commit_veto
+ 'zope.sqlalchemy',
+ 'WebError',
+ ]
+
+if sys.version_info[:3] < (2,5,0):
+ requires.append('pysqlite')
+
+setup(name='basic_site',
+ version='0.0',
+ description='basic_site',
+ long_description=README + '\n\n' + CHANGES,
+ classifiers=[
+ "Programming Language :: Python",
+ "Framework :: Pylons",
+ "Topic :: Internet :: WWW/HTTP",
+ "Topic :: Internet :: WWW/HTTP :: WSGI :: Application",
+ ],
+ author='',
+ author_email='',
+ url='',
+ keywords='web wsgi bfg pylons pyramid',
+ packages=find_packages(),
+ include_package_data=True,
+ zip_safe=False,
+ test_suite='basic_site',
+ install_requires = requires,
+ entry_points = """\
+ [paste.app_factory]
+ main = basic_site:main
+ """,
+ paster_plugins=['pyramid'],
+ )
+
Please sign in to comment.
Something went wrong with that request. Please try again.