Permalink
Browse files

big re-org. try to keep the views near the templates

  • Loading branch information...
1 parent e0a47e5 commit 498258a53ec66ac9105ea7e3e532d758c219d9ef @dcolish committed Jan 17, 2011
Showing with 138 additions and 50 deletions.
  1. +7 −4 README
  2. +13 −0 TODO
  3. +0 −17 cockerel/runserver.py
  4. +5 −7 cockerel/webapp/__init__.py
  5. +1 −0 cockerel/webapp/auth/__init__.py
  6. +50 −0 cockerel/webapp/auth/permissions.py
  7. +25 −0 cockerel/webapp/auth/security.py
  8. 0 cockerel/webapp/{views → auth}/util.py
  9. +6 −0 cockerel/webapp/forms/__init__.py
  10. 0 cockerel/webapp/{views → }/forms/admin.py
  11. 0 cockerel/webapp/{views → }/forms/classes.py
  12. 0 cockerel/webapp/{views → }/forms/lessons.py
  13. +0 −1 cockerel/webapp/templates/admin/__init__.py
  14. +1 −8 cockerel/webapp/templates/base.html
  15. +0 −1 cockerel/webapp/templates/frontend/__init__.py
  16. +0 −1 cockerel/webapp/templates/frontend/index.html
  17. +5 −0 cockerel/webapp/views/__init__.py
  18. +6 −0 cockerel/webapp/views/admin/__init__.py
  19. +1 −1 cockerel/webapp/views/{ → admin}/admin.py
  20. 0 cockerel/webapp/{templates/admin → views/admin/templates}/login.html
  21. 0 cockerel/webapp/{templates/admin → views/admin/templates}/signup.html
  22. +2 −1 cockerel/webapp/views/{frontend.py → base.py}
  23. +3 −0 cockerel/webapp/views/classes/__init__.py
  24. +3 −4 cockerel/webapp/views/{ → classes}/classes.py
  25. 0 cockerel/webapp/{templates/classes → views/classes/templates}/add.html
  26. 0 cockerel/webapp/{templates/classes → views/classes/templates}/index.html
  27. 0 cockerel/webapp/{templates/classes → views/classes/templates}/view.html
  28. +0 −1 cockerel/webapp/views/forms/__init__.py
  29. +3 −0 cockerel/webapp/views/lessons/__init__.py
  30. +2 −2 cockerel/webapp/views/{ → lessons}/lessons.py
  31. 0 cockerel/webapp/{templates/lessons → views/lessons/templates}/add.html
  32. 0 cockerel/webapp/{templates/lessons → views/lessons/templates}/edit.html
  33. 0 cockerel/webapp/{templates/lessons → views/lessons/templates}/view.html
  34. +3 −1 cockerel/webapp/views/prover/__init__.py
  35. 0 cockerel/webapp/{templates/prover → views/prover/templates}/prover.html
  36. +1 −0 coqd/base.py
  37. +1 −1 setup.py
View
11 README
@@ -1,6 +1,7 @@
For fuller, more recent documentation on Cockerel go to:
http://packages.python.org/cockerel
+
1. Introduction
----------------------------------------
@@ -32,19 +33,21 @@ into. This can be done with:
virtualenv some_env_path
. some_env_path/bin/activate
- easy_install Cockerel
+ pip install Cockerel
where 'Cockerel' is the directory where the repository resides.
To start Cockerel run
- cockerel
+ python manager.py initd
+ python manager.py runserver
To start Coqd run
- coqd
+ python manager.py runcoqd
The Cockerel webpage will, by default, be at
http://localhost:5000
+
3. Developing Cockerel -- Instructions for Installing
--------------------------------------
@@ -59,7 +62,7 @@ Then
python setup.py develop
-As part of the the last command, easy_install downloads all dependencies for
+As part of the the last command, easy_install/pip downloads all dependencies for
the project. As of 2010 Aug 16, you may have to must repeat:
python setup.py develop
View
13 TODO
@@ -0,0 +1,13 @@
+Cockerel TODO List for Winter Break
+
+* Features
+** Choose between simplifying radically or finishing users
+** Add config object for setting basic server options (command line options too?)
+** Clean up editor interface and display output correctly
+
+* Testing
+** Setup automated test runner
+** Develop more tests
+
+* Packaging
+** Debianize the whole thang
View
17 cockerel/runserver.py
@@ -1,17 +0,0 @@
-from cockerel.webapp import app
-
-
-def new_app(serialize):
- if serialize:
- app.config['serialize'] = serialize
- return app
-
-
-def main(serialize):
- new_app(serialize)
- app.debug = True
- app.run()
-
-
-if __name__ == '__main__':
- main()
View
12 cockerel/webapp/__init__.py
@@ -21,11 +21,11 @@
from .views.prover.mdx_prover import ProverExtension
md.register_extension(ProverExtension)
-from .views.admin import admin
-from .views.classes import classes
-from .views.frontend import frontend
-from .views.lessons import lessons
-from .views.prover.prover import prover
+from .views import admin
+from .views import classes
+from .views import frontend
+from .views import lessons
+from .views import prover
from .utils import register_modules
register_modules(app, [admin, classes, frontend, lessons, prover])
@@ -45,8 +45,6 @@ def update_config():
"""syncronizes the config with the g global request object"""
g.config = app.config
-app.before_request(update_config)
-
def new_app(serialize):
if serialize:
View
1 cockerel/webapp/auth/__init__.py
@@ -0,0 +1 @@
+from util import login_required, permissions
View
50 cockerel/webapp/auth/permissions.py
@@ -0,0 +1,50 @@
+"""
+Permissions
+===========
+
+Will specify what roles or attributes are needed to be held by an Identity for
+it to access a resource. The resource can be anything within the application.
+However, it should be restricted to page endpoints. Privileges which will be
+integrated later will restrict the access to data in a more fine grained manner
+
+"""
+from flaskext.principal import (
+ identity_loaded,
+ Permission,
+ RoleNeed,
+ UserNeed,
+ )
+
+
+def permission(*roles):
+ perm = Permission(RoleNeed('none'))
+ for x in roles:
+ perm = perm.union(x)
+ return perm
+
+
+class Permissions(dict):
+ def __getattr__(self, attr):
+ try:
+ return self[attr]
+ except:
+ return super(self, dict).attr
+
+ def __setattr__(self, attr, value):
+ self[attr] = value
+
+permissions = Permissions()
+
+permissions.read = Permission(RoleNeed('read'))
+permissions.insert = Permission(RoleNeed('insert'))
+permissions.modify = Permission(RoleNeed('modify'))
+permissions.delete = Permission(RoleNeed('delete'))
+permissions.full_access = permission(permissions.delete, permissions.insert,
+ permissions.modify, permissions.read)
+
+
+@identity_loaded.connect
+def set_owned_by(sender, identity):
+ permissions.owned_by = Permission(UserNeed(identity.user))
+ permissions.modify_own_content = permission(permissions.owned_by,
+ permissions.full_access)
View
25 cockerel/webapp/auth/security.py
@@ -0,0 +1,25 @@
+"""
+Security
+========
+
+Inflate and set the users Identity. Works with `permission.Permissions` since
+all roles will be added to an Identity and then checked before routing.
+"""
+
+from flask import g, session
+from flaskext.principal import Identity
+
+
+from pdxacm.webapp import principals
+from pdxacm.models.schema import User
+
+
+def check_user():
+ g.identity = Identity(User.query.filter_by(
+ username=session.get('username')))
+
+
+@principals.identity_saver
+def set_user(identity):
+ g.identity = identity
+ session['username'] = identity.username
View
0 cockerel/webapp/views/util.py → cockerel/webapp/auth/util.py
File renamed without changes.
View
6 cockerel/webapp/forms/__init__.py
@@ -0,0 +1,6 @@
+#
+from admin import LoginForm, SignupForm
+
+from classes import AddEditClassForm
+
+from lessons import EditLessonForm
View
0 cockerel/webapp/views/forms/admin.py → cockerel/webapp/forms/admin.py
File renamed without changes.
View
0 cockerel/webapp/views/forms/classes.py → cockerel/webapp/forms/classes.py
File renamed without changes.
View
0 cockerel/webapp/views/forms/lessons.py → cockerel/webapp/forms/lessons.py
File renamed without changes.
View
1 cockerel/webapp/templates/admin/__init__.py
@@ -1 +0,0 @@
-#
View
9 cockerel/webapp/templates/base.html
@@ -42,14 +42,7 @@
<div id="footer">
{% block footer %}
{% endblock %}
- <a href="http://flask.pocoo.org/">
- <img
- src="http://flask.pocoo.org/static/badges/powered-by-flask-s.png"
- border="0"
- alt="powered by Flask"
- title="powered by Flask" />
- </a>
- <p>Copyright 2010 by Dan Colish</p>
+ <p>Copyright 2010 by Dan Colish</p>
</div>
</body>
</html>
View
1 cockerel/webapp/templates/frontend/__init__.py
@@ -1 +0,0 @@
-#
View
1 cockerel/webapp/templates/frontend/index.html
@@ -1 +0,0 @@
-{% extends "base.html" %}
View
5 cockerel/webapp/views/__init__.py
@@ -1 +1,6 @@
#
+from admin import admin
+from base import frontend
+from classes import classes
+from lessons import lessons
+from prover import prover
View
6 cockerel/webapp/views/admin/__init__.py
@@ -0,0 +1,6 @@
+#
+
+from .admin import admin
+
+__all__ = ['admin']
+
View
2 cockerel/webapp/views/admin.py → cockerel/webapp/views/admin/admin.py
@@ -10,7 +10,7 @@
from flatland.out.markup import Generator
from cockerel.models.schema import db, User
-from .forms.admin import LoginForm, SignupForm
+from cockerel.webapp.forms import LoginForm, SignupForm
admin = Module(__name__)
View
0 cockerel/webapp/templates/admin/login.html → ...l/webapp/views/admin/templates/login.html
File renamed without changes.
View
0 cockerel/webapp/templates/admin/signup.html → .../webapp/views/admin/templates/signup.html
File renamed without changes.
View
3 cockerel/webapp/views/frontend.py → cockerel/webapp/views/base.py
@@ -5,8 +5,9 @@
frontend = Module(__name__)
+
@frontend.route('/', methods=['GET'])
def index():
# TODO: what do we need on the homepage?
# How about notifications of new stuff added
- return render_template("frontend/index.html")
+ return render_template("base.html")
View
3 cockerel/webapp/views/classes/__init__.py
@@ -0,0 +1,3 @@
+from .classes import classes
+
+__all__ = ['classes']
View
7 cockerel/webapp/views/classes.py → cockerel/webapp/views/classes/classes.py
@@ -16,10 +16,9 @@
)
from flatland.out.markup import Generator
-from util import login_required
-
from cockerel.models.schema import db, Classes
-from .forms.classes import AddEditClassForm
+from cockerel.webapp.auth import login_required
+from cockerel.webapp.forms import AddEditClassForm
classes = Module(__name__)
@@ -28,7 +27,7 @@
def index():
"""Shows all classes currently in the system"""
classes = Classes.query.all()
- return render_template("/classes/index.html", classes=classes)
+ return render_template("classes/index.html", classes=classes)
@classes.route('/classes/add', methods=['GET', 'POST'])
View
0 cockerel/webapp/templates/classes/add.html → ...l/webapp/views/classes/templates/add.html
File renamed without changes.
View
0 cockerel/webapp/templates/classes/index.html → ...webapp/views/classes/templates/index.html
File renamed without changes.
View
0 cockerel/webapp/templates/classes/view.html → .../webapp/views/classes/templates/view.html
File renamed without changes.
View
1 cockerel/webapp/views/forms/__init__.py
@@ -1 +0,0 @@
-#
View
3 cockerel/webapp/views/lessons/__init__.py
@@ -0,0 +1,3 @@
+from lessons import lessons
+
+__all__ = ['lessons']
View
4 cockerel/webapp/views/lessons.py → cockerel/webapp/views/lessons/lessons.py
@@ -8,8 +8,8 @@
)
from flatland.out.markup import Generator
-from util import login_required
-from .forms.lessons import EditLessonForm
+from cockerel.webapp.auth import login_required
+from cockerel.webapp.forms import EditLessonForm
from cockerel.models.schema import db, Classes, Lesson
lessons = Module(__name__)
View
0 cockerel/webapp/templates/lessons/add.html → ...l/webapp/views/lessons/templates/add.html
File renamed without changes.
View
0 cockerel/webapp/templates/lessons/edit.html → .../webapp/views/lessons/templates/edit.html
File renamed without changes.
View
0 cockerel/webapp/templates/lessons/view.html → .../webapp/views/lessons/templates/view.html
File renamed without changes.
View
4 cockerel/webapp/views/prover/__init__.py
@@ -1 +1,3 @@
-#
+from .prover import prover
+
+__all__ = ['prover']
View
0 cockerel/webapp/templates/prover/prover.html → ...webapp/views/prover/templates/prover.html
File renamed without changes.
View
1 coqd/base.py
@@ -18,6 +18,7 @@ def start(self):
]
self.process = spawn(' '.join(['coqtop'] + args))
+ # XXX: Bug in pexpect doesn't let this work
# self.process = spawn('coqtop', [
# '-include ./coqd/coqext/hypreason/',
# '-require HypReason',
View
2 setup.py
@@ -54,7 +54,7 @@
},
install_requires=[
- 'flask',
+ 'Flask',
'Flask-Markdown==0.3',
'Flask-SQLAlchemy',
'Flask-Script',

0 comments on commit 498258a

Please sign in to comment.