Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
mangoplum committed Apr 16, 2012
0 parents commit 84b6d8b
Show file tree
Hide file tree
Showing 23 changed files with 7,801 additions and 0 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
instance/
*.pyc
16 changes: 16 additions & 0 deletions manage.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
from flaskext.script import Manager

from mappy import app, db

manager = Manager(app)

@manager.command
def clear():
"""Clear the database."""
print "%i documents in collection" % db['features'].count()
db['features'].remove()
print 'database cleared.'
print "%i documents in collection" % db['features'].count()

if __name__ == "__main__":
manager.run()
33 changes: 33 additions & 0 deletions mappy/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
def _init_app():
from flask import Flask

from . import default_config

app = Flask(__name__, instance_relative_config=True)

app.config.from_object(default_config)
app.config.from_envvar(app.name.upper() + '_SETTINGS', silent=True)
app.config.from_pyfile('local_config.py', silent=True)

return app

def _init_db():
from mongokit import Connection
from .models import models

conn = Connection(app.config['MONGODB_HOST'],
app.config['MONGODB_PORT'])

db = conn[app.config['MONGODB_DBNAME']]

if all(k in app.config for k in ("MONGODB_USERNAME", "MONGODB_PASSWORD")):
db.authenticate(app.config['MONGODB_USERNAME'], app.config['MONGODB_PASSWORD'])

db.connection.register(models)

return db

app = _init_app()
db = _init_db()

from . import views
24 changes: 24 additions & 0 deletions mappy/default_config.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import os

DEBUG = True

MOBILE = True

SECRET_KEY = 'development key'

PORT = int(os.environ.get('PORT', 5000))
HOST = os.environ.get('HOST', '0.0.0.0')

MONGODB_HOST = os.environ.get('MONGODB_HOST', 'localhost')
MONGODB_PORT = os.environ.get('MONGODB_PORT', 27017)
MONGODB_DBNAME = os.environ.get('MONGODB_DBNAME')
MONGODB_USERNAME = os.environ.get('MONGODB_USERNAME')
MONGODB_PASSWORD = os.environ.get('MONGODB_PASSWORD')

PUBNUB_PUB_KEY = 'demo'
PUBNUB_SUB_KEY = 'demo'
PUBNUB_CHANNELS = {'features': '4370beb4-3888-4208-a507-82e2e2d0883b'}

TILES_URL = 'http://{s}.mqcdn.com/tiles/1.0.0/osm/{z}/{x}/{y}.png'

JSCONSOLE_KEY = ''
25 changes: 25 additions & 0 deletions mappy/models.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import datetime

from mongokit import Document

class Feature(Document):
__collection__ = 'features'

structure = {
'title': unicode,
'info': unicode,
'urgency': int,
'pos': (float, float),
'date_creation': datetime.datetime,
}

default_values = {
'urgency': 1,
'title': u'no title',
'info': u'no info',
'date_creation': datetime.datetime.utcnow
}

required_fields = ['pos', 'date_creation']

models = [Feature]
Loading

0 comments on commit 84b6d8b

Please sign in to comment.