Skip to content

Commit

Permalink
Merge branch 'master' of https://github.com/dcolish/Cockerel
Browse files Browse the repository at this point in the history
  • Loading branch information
Hong Quach committed Jan 19, 2011
2 parents 7ca5891 + 5bb07a0 commit a6607a8
Show file tree
Hide file tree
Showing 56 changed files with 225 additions and 97 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Expand Up @@ -9,7 +9,7 @@ parser.out
*.vo
*.glob
*.d
coqext/hypreason/Makefile
coqd/coqext/hypreason/Makefile
*.v.d
*.egg-info
docs/_build
Expand Down
11 changes: 7 additions & 4 deletions README
@@ -1,6 +1,7 @@
For fuller, more recent documentation on Cockerel go to:
http://packages.python.org/cockerel


1. Introduction
----------------------------------------

Expand Down Expand Up @@ -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
--------------------------------------

Expand All @@ -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
Expand Down
13 changes: 13 additions & 0 deletions 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
1 change: 1 addition & 0 deletions cockerel/auth/__init__.py
@@ -0,0 +1 @@
from util import login_required, permissions
50 changes: 50 additions & 0 deletions cockerel/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)
25 changes: 25 additions & 0 deletions cockerel/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 .permissions import principals
from cockerel.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
File renamed without changes.
6 changes: 6 additions & 0 deletions cockerel/forms/__init__.py
@@ -0,0 +1,6 @@
#
from admin import LoginForm, SignupForm

from classes import AddEditClassForm

from lessons import EditLessonForm
File renamed without changes.
File renamed without changes.
File renamed without changes.
7 changes: 3 additions & 4 deletions cockerel/models/__init__.py
@@ -1,6 +1,5 @@
# #
# from flaskext.sqlalchemy import SQLAlchemy
from flaskext.sqlalchemy import SQLAlchemy

# from webapp import
db = SQLAlchemy()

# db = SQLAlchemy(app)
__all__ = ['db']
3 changes: 2 additions & 1 deletion cockerel/models/schema.py
@@ -1,5 +1,6 @@
from werkzeug import generate_password_hash, check_password_hash
from cockerel.webapp import db

from . import db


user_classes = db.Table('user_classes', db.Model.metadata,
Expand Down
3 changes: 3 additions & 0 deletions cockerel/utilities/__init__.py
@@ -0,0 +1,3 @@
from base import new_app

__all__ = ['new_app']
52 changes: 52 additions & 0 deletions cockerel/utilities/base.py
@@ -0,0 +1,52 @@
"""
cockerel.webapp
---------------
Main instance of the webapp. All modules will be loaded from this file. To
add a new module you must import it here and register it.
"""
import logging
import os

from flask import g

from flaskext.markdown import Markdown

from cockerel.models import db

from cockerel.webapp import (
admin,
classes,
frontend,
lessons,
prover,
)
from cockerel.webapp.prover import ProverExtension


def update_config(app):
"""syncronizes the config with the g global request object"""
g.config = app.config


def register_modules(app, mod_list):
for x in mod_list:
app.register_module(x)


def new_app(app, serialize=False):
logging.basicConfig(level=logging.DEBUG)
md = Markdown(app, extensions=['tables'])
md.register_extension(ProverExtension)
register_modules(app, [admin, classes, frontend, lessons, prover])
app.secret_key = os.urandom(24)
app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:////tmp/test.db'
app.config['COQD_HOST'] = 'localhost'
app.config['COQD_PORT'] = 8003
if serialize:
app.config['serialize'] = serialize

# XXX:dc: kind of a hack but I want to keep the db and the app seperate
db.init_app(app)
db.app = app

return app
58 changes: 8 additions & 50 deletions cockerel/webapp/__init__.py
@@ -1,54 +1,12 @@
"""
cockerel.webapp
---------------
Main instance of the webapp. All modules will be loaded from this file. To
add a new module you must import it here and register it.
"""
import logging
import os
#
from flask import Flask

from flask import Flask, g
from flaskext.sqlalchemy import SQLAlchemy
from flaskext.markdown import Markdown
from admin import admin
from frontend import frontend
from classes import classes
from lessons import lessons
from prover import prover

logging.basicConfig(level=logging.DEBUG)

HOST = "localhost"
app = Flask(__name__)
db = SQLAlchemy(app)
md = Markdown(app, extensions=['tables'])

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 .utils import register_modules

register_modules(app, [admin, classes, frontend, lessons, prover])

app.secret_key = os.urandom(24)

app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:////tmp/test.db'
app.config['COQD_HOST'] = 'localhost'
app.config['COQD_PORT'] = 8003

# see if the db exists, if not make it and initialize
if not os.path.exists(app.config.get('SQLALCHEMY_DATABASE_URI')):
db.create_all()


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:
app.config['serialize'] = serialize
return app
__all__ = ['admin', 'app', 'frontend', 'classes', 'lessons', 'prover']
6 changes: 6 additions & 0 deletions cockerel/webapp/admin/__init__.py
@@ -0,0 +1,6 @@
#

from .admin import admin

__all__ = ['admin']

Expand Up @@ -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.forms import LoginForm, SignupForm

admin = Module(__name__)

Expand Down
File renamed without changes.
File renamed without changes.
3 changes: 3 additions & 0 deletions cockerel/webapp/classes/__init__.py
@@ -0,0 +1,3 @@
from .classes import classes

__all__ = ['classes']
Expand Up @@ -16,10 +16,9 @@
)
from flatland.out.markup import Generator

from util import login_required

from cockerel.auth import login_required
from cockerel.forms import AddEditClassForm
from cockerel.models.schema import db, Classes
from .forms.classes import AddEditClassForm

classes = Module(__name__)

Expand All @@ -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'])
Expand Down
File renamed without changes.
File renamed without changes.
Expand Up @@ -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")
3 changes: 3 additions & 0 deletions cockerel/webapp/lessons/__init__.py
@@ -0,0 +1,3 @@
from lessons import lessons

__all__ = ['lessons']
Expand Up @@ -8,8 +8,8 @@
)
from flatland.out.markup import Generator

from util import login_required
from .forms.lessons import EditLessonForm
from cockerel.auth import login_required
from cockerel.forms import EditLessonForm
from cockerel.models.schema import db, Classes, Lesson

lessons = Module(__name__)
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
4 changes: 4 additions & 0 deletions cockerel/webapp/prover/__init__.py
@@ -0,0 +1,4 @@
from prover import prover
from mdx_prover import ProverExtension

__all__ = ['prover', 'ProverExtension']
Expand Up @@ -16,7 +16,7 @@

from sqlalchemy.orm.exc import NoResultFound

from cockerel.webapp import db
from cockerel.models import db
from cockerel.models.schema import Theorem
from .prover import hash_theorem

Expand Down
Expand Up @@ -14,7 +14,7 @@
)

from cockerel.models.schema import Proof, Theorem
from cockerel.webapp.views.util import login_required
from cockerel.auth import login_required

prover = Module(__name__)

Expand Down
1 change: 0 additions & 1 deletion cockerel/webapp/templates/admin/__init__.py

This file was deleted.

9 changes: 1 addition & 8 deletions cockerel/webapp/templates/base.html
Expand Up @@ -42,14 +42,7 @@ <h1>Welcome to Cockerel</h1>
<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>

0 comments on commit a6607a8

Please sign in to comment.