Skip to content

Commit

Permalink
JSON api beginnings.
Browse files Browse the repository at this point in the history
  • Loading branch information
ralphbean committed Feb 16, 2012
1 parent e5f08c1 commit e82acc3
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 71 deletions.
60 changes: 3 additions & 57 deletions README.rst
@@ -1,58 +1,4 @@
TurboGears2 on Red Hat's OpenShift Express
==========================================
Lulz App
========

This quickstart helps you get up and running with a fully-functional
TurboGears2 instance on OpenShift. It automatically handles creating a Python
virtualenv, populating a MySQL database, and deploying your application to the
cloud.

* Create an account at http://openshift.redhat.com/

Features
--------

* Completely free, thanks to Red Hat's OpenShift Express
* MySQL database automatically setup for your application
* Dynamic database configuration at runtime. No passwords stored in your configs.
* Your application's test suite is run after each push
* Automatic deployment upon git push
* No need to think about servers, let alone apache/mod_wsgi configuration

The fastest method
------------------

You can easily deploy a pre-configured TG2 + MySQL application to the OpenShift cloud with a single command, using my `openshift-quickstarter` tool: http://github.com/lmacken/openshift-quickstarter

::

./openshift-quickstarter EMAIL DOMAIN APPNAME turbogears2

That's it! You can now view your application at:

::

http://APPNAME-DOMAIN.rhcloud.com

.. image:: http://lewk.org/img/turbogears2-quickstart.png


The manual method
-----------------

If you don't want to use the `openshift-quickstarter`, you can easily create a new OpenShift WSGI application and merge this quickstart into it manually:

::

rhc-create-app -a tg2 -t wsgi-3.2 -l your@email.com
rhc-ctl-app -a tg2 -e add-mysql-5.1 -l your@email.com
cd tg2app
git remote add upstream -m master git://github.com/lmacken/turbogears2-openshift-quickstart.git
git pull -s recursive -X theirs upstream master
git push

Monitoring your logs
--------------------

::

rhc-tail-files -a tg2app -l your@email.com
Go look at http://localhost:8080/game/1
5 changes: 5 additions & 0 deletions wsgi/tg2app/tg2app/controllers/root.py
Expand Up @@ -42,6 +42,11 @@ def index(self):
"""Handle the front-page."""
return dict(page='index')

@expose('json')
def game(self, game_id):
game = model.DBSession.query(model.Game).filter_by(id=game_id).one()
return game.to_json()

@expose('tg2app.templates.about')
def about(self):
"""Handle the 'about' page."""
Expand Down
16 changes: 8 additions & 8 deletions wsgi/tg2app/tg2app/model/game.py
Expand Up @@ -33,17 +33,17 @@ class Game(DeclarativeBase):
backref="games",
)

def to_json(self, no_relations):
def to_json(self, no_relations=False):
if no_relations:
return {
id: self.id,
'id': self.id,
}
else:
return {
id: self.id,
whose_turn: self.whose_turn.to_json(),
hands: [hand.to_json() for hand in self.hands],
entities: [ent.to_json() for ent in self.entities],
cards: [card.to_json() for card in self.cards],
players: [player.to_json() for player in self.players],
'id': self.id,
'whose_turn': self.whose_turn.to_json(),
# hands: [hand.to_json() for hand in self.hands],
# entities: [ent.to_json() for ent in self.entities],
# cards: [card.to_json() for card in self.cards],
'players': [player.to_json() for player in self.players],
}
12 changes: 6 additions & 6 deletions wsgi/tg2app/tg2app/model/player.py
Expand Up @@ -29,17 +29,17 @@ class Player(DeclarativeBase):
hands = relation("Hand", backref="player")
entities = relation("Entity", backref="player")

def to_json(self, no_relations):
def to_json(self, no_relations=False):
if no_relations:
return {
id: self.id,
name: self.name,
'id': self.id,
'name': self.name,
}
else:
return {
id: self.id,
name: self.name,
friends: [
'id': self.id,
'name': self.name,
'friends': [
f.to_json(no_relations=True) for f in self.friends
],
}
Expand Down
1 change: 1 addition & 0 deletions wsgi/tg2app/tg2app/websetup/bootstrap.py
Expand Up @@ -47,6 +47,7 @@ def bootstrap(command, conf, vars):
for card in cards:
game.cards.append(card)

game.whose_turn = player1

entity1 = model.Entity(
is_avatar = True,
Expand Down

0 comments on commit e82acc3

Please sign in to comment.