Skip to content

Commit

Permalink
Fixed minor bugs and module dependencies after redistribution of secu…
Browse files Browse the repository at this point in the history
…rity code

Added glyphicons to the layout
  • Loading branch information
gr- committed Nov 27, 2013
1 parent 660a091 commit 579beda
Show file tree
Hide file tree
Showing 6 changed files with 47 additions and 35 deletions.
35 changes: 23 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,20 +14,23 @@ Python package dependencies are listed under the `requires` label in the `setup.
Getting Started
---------------

- pyvenv venv
First, create and set up the python virtual environment:

- source venv/bin/activate

- python ez_setup.py

- cd <directory containing this file>

- $venv/bin/python setup.py develop
$ pyvenv venv
$ source venv/bin/activate
$ curl https://bitbucket.org/pypa/setuptools/raw/bootstrap/ez_setup.py | python
$ easy_install pip
$ pip install -U setuptools
$ pip install pyramid

- $venv/bin/initialize_birdie_db development.ini
Then install Birdie requirements (package dependencies) and the app itself in `develop` mode:

- $venv/bin/pserve development.ini --reload
$ cd <path to this README.md file>
$ python setup.py develop
$ initialize_birdie_db development.ini
$ venv/bin/pserve development.ini --reload

Enjoy at [http://localhost:6543](http://localhost:6543)

## INSTALL

Expand Down Expand Up @@ -61,7 +64,7 @@ To finilize your sandbox, install the super magic `pip` package manager b.t.w. o

From now on, you are done with a fully functionnal python3 runtime environment. It is recommended to check for latest version
of setuptools and pip install pyramid as well, even if Birdie app install process is expected to resolve python package dependencies
(roughly, it is not as reliable as pip).
(it is not as reliable as pip).

$ pip install -U setuptools
$ pip install pyramid
Expand Down Expand Up @@ -89,7 +92,15 @@ Install procedure is fairly easy. You have to decide for development or (limited
$ pserve production.ini


Whatever your decision, the instance of the Birdie web app is reachable at http://localhost:6543
Whatever your decision, the instance of the Birdie web app is located at [http://localhost:6543](http://localhost:6543)

#### Caveats

There are (at least) two known issues you may face when running the Birdie app.

- (1) port 6543 is assigned to another app: kill the app or change the port in the `production.ini` and/or `development.ini` file;
- (2) there is a residual cookie from a previous Birdie installation: delete it within your web browser.

Enjoy!


Expand Down
5 changes: 4 additions & 1 deletion birdie/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
Unicode,
ForeignKey,
UniqueConstraint,
TIMESTAMP,
)

from sqlalchemy.ext.declarative import declarative_base
Expand All @@ -22,6 +23,8 @@
Base = declarative_base()


from .security import Crypt

class User(Base):
__tablename__ = 'users'
id = Column(Integer, primary_key=True)
Expand All @@ -33,7 +36,7 @@ class User(Base):

def __init__(self, username, password, fullname, about, dor):
self.username = username
self.password = crypt.encode(password)
self.password = Crypt.encode(password)
self.fullname = fullname
self.about = about
self.dor = dor
Expand Down
9 changes: 3 additions & 6 deletions birdie/security.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
from pyramid.security import Authenticated
from pyramid.security import Allow

from .models import (
DBSession,
User,
)
import birdie.models

from cryptacular.bcrypt import BCRYPTPasswordManager

Expand All @@ -20,8 +17,8 @@ def __init__(self, request):


def check_login(login, password):
session = DBSession()
user = session.query(User).filter_by(username=login).first()
session = birdie.models.DBSession()
user = session.query(birdie.models.User).filter_by(username=login).first()
if user is not None:
hashed_password = user.password
if Crypt.check( hashed_password, password ):
Expand Down
6 changes: 6 additions & 0 deletions birdie/templates/birdie-bootstrap.pt
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,12 @@
</div>

<div metal:fill-slot="content-bottom" tal:omit-tag="">
<div class="well well-sm" tal:condition="latest_users is not None">
<span class="text"><i>Latest users</i></span>
<div tal:repeat="user latest_users" tal:omit-tag="">
<a href="${view.app_url}/${user.username}/view" class="btn btn-info btn-xs">@${user.username}</a>
</div>
</div>
<h1>Public Timeline</h1>
<div class="row">
<div class="col-lg-4" tal:repeat="chirp chirps">
Expand Down
10 changes: 5 additions & 5 deletions birdie/templates/layout-bootstrap.pt
Original file line number Diff line number Diff line change
Expand Up @@ -35,24 +35,24 @@
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<a class="navbar-brand" href="${view.app_url}/about">Birdie</a>
<a class="navbar-brand" href="${view.app_url}/about"><span class="glyphicon glyphicon-share-alt"></span>Birdie</a>
</div>
<div class="navbar-collapse collapse">
<ul class="nav navbar-nav">
<li>
<a href="${view.app_url}">Home</a>
<a href="${view.app_url}"><span class="glyphicon glyphicon-home"></span> Home</a>
</li>
<li>
<a tal:condition="view.logged_in is not None"
href="${view.app_url}/${view.logged_in}">My Birdie</a>
href="${view.app_url}/${view.logged_in}"><span class="glyphicon glyphicon-user"></span> My Birdie</a>
</li>
</ul>
<ul class="nav navbar-nav navbar-right">
<li tal:condition="view.logged_in is not None">
<a href="${view.app_url}/logout">Logout (${view.logged_in})</a>
<a href="${view.app_url}/logout"><span class="glyphicon glyphicon-log-out"></span> Logout (${view.logged_in})</a>
</li>
<li tal:condition="view.logged_in is None">
<a href="${view.app_url}/login">Sign In</a>
<a href="${view.app_url}/login"><span class="glyphicon glyphicon-log-in"></span> Sign In</a>
</li>
</ul>
</div><!--/.navbar-collapse -->
Expand Down
17 changes: 6 additions & 11 deletions birdie/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,10 @@
Chirp,
User,
Follower,
check_login,
)

from .security import check_login


conn_err_msg = """\
Pyramid is having a problem using your SQL database. The problem
Expand Down Expand Up @@ -68,20 +69,23 @@ def birdie_view(self):
user = None
follows = None
chirps = None
latest_users = None
friends = []
try:
if username:
user = DBSession.query(User).filter_by(username=username).one()
follows = DBSession.query(Follower).filter(Follower.follower==user.id)
friends = [friend.id for friend in follows]
chirps = DBSession.query(Chirp).order_by(Chirp.timestamp.desc()).limit(15)
latest_users = DBSession.query(User).order_by(User.dor.desc()).limit(5)
except DBAPIError:
return Response(conn_err_msg, content_type='text/plain', status_int=500)

return {'elapsed': get_elapsed,
'user': user,
'follows': friends,
'chirps': chirps}
'chirps': chirps,
'latest_users': latest_users}

@view_config(route_name='mybirdie',
permission='registered',
Expand Down Expand Up @@ -272,12 +276,3 @@ def unfollow(self):
DBSession.query(Follower).filter(Follower.follower==follower).filter(Follower.follows==follows).delete()
return HTTPFound(location = self.request.referer)



try:
one = DBSession.query(MyModel).filter(MyModel.name == 'one').first()
except DBAPIError:
return Response(conn_err_msg, content_type='text/plain', status_int=500)
return {'one': one, 'project': 'birdie'}


0 comments on commit 579beda

Please sign in to comment.