Skip to content

Commit

Permalink
Merge branch 'master' into rod
Browse files Browse the repository at this point in the history
Conflicts:
	AUTHORS
	MANIFEST.in
	README.rst
	flask_mongoengine/templates/panels/mongo-panel.html
	flask_mongoengine/wtf/__init__.py
	flask_mongoengine/wtf/fields.py
	flask_mongoengine/wtf/orm.py
	setup.py
	tests.py
  • Loading branch information
rozza committed May 17, 2012
2 parents 7b9a45a + 9caf20a commit 3967c1a
Show file tree
Hide file tree
Showing 24 changed files with 299 additions and 97 deletions.
4 changes: 3 additions & 1 deletion AUTHORS
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
Ross Lawley <ross.lawley@gmail.com>
Jorge Bastida <me@jorgebastida.com>
Dan Jacob https://bitbucket.org/danjac
Marat Khabibullin https://bitbucket.org/maratfm
Jorge Bastida <me@jorgebastida.com>
Streetlife.com
atroche - https://github.com/atroche
Rodrigue Cloutier
31 changes: 31 additions & 0 deletions Flask_MongoEngine.egg-info/PKG-INFO
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
Metadata-Version: 1.0
Name: flask-mongoengine
Version: 0.1
Summary: Flask support for MongoDB and with WTF model forms
Home-page: https://github.com/mongoengine/flask-mongoengine
Author: Ross Lawley
Author-email: ross.lawley@gmail.com
License: BSD
Description:
Flask-MongoEngine
--------------

Flask support for MongoDB using MongoEngine.
Includes `WTForms`_ support.

Links
`````

* `development version
<https://github.com/mongoengine/flask-mongoengine/raw/master#egg=Flask-MongoEngine-dev>`_


Platform: any
Classifier: Development Status :: 4 - Beta
Classifier: Environment :: Web Environment
Classifier: Intended Audience :: Developers
Classifier: License :: OSI Approved :: BSD License
Classifier: Operating System :: OS Independent
Classifier: Programming Language :: Python
Classifier: Topic :: Internet :: WWW/HTTP :: Dynamic Content
Classifier: Topic :: Software Development :: Libraries :: Python Modules
31 changes: 31 additions & 0 deletions Flask_MongoEngine.egg-info/SOURCES.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
AUTHORS
LICENSE
MANIFEST.in
README.rst
setup.py
Flask_MongoEngine.egg-info/PKG-INFO
Flask_MongoEngine.egg-info/SOURCES.txt
Flask_MongoEngine.egg-info/dependency_links.txt
Flask_MongoEngine.egg-info/not-zip-safe
Flask_MongoEngine.egg-info/requires.txt
Flask_MongoEngine.egg-info/top_level.txt
docs/Makefile
docs/conf.py
docs/index.rst
docs/make.bat
docs/_themes/README
docs/_themes/flask_theme_support.py
docs/_themes/flask/theme.conf
docs/_themes/flask/static/flasky.css_t
docs/_themes/flask_small/layout.html
docs/_themes/flask_small/theme.conf
docs/_themes/flask_small/static/flasky.css_t
flask_mongoengine/__init__.py
flask_mongoengine/operation_tracker.py
flask_mongoengine/panels.py
flask_mongoengine.egg-info/SOURCES.txt
flask_mongoengine/templates/panels/mongo-panel.html
flask_mongoengine/wtf/__init__.py
flask_mongoengine/wtf/fields.py
flask_mongoengine/wtf/models.py
flask_mongoengine/wtf/orm.py
1 change: 1 addition & 0 deletions Flask_MongoEngine.egg-info/dependency_links.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@

1 change: 1 addition & 0 deletions Flask_MongoEngine.egg-info/not-zip-safe
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@

3 changes: 3 additions & 0 deletions Flask_MongoEngine.egg-info/requires.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Flask
mongoengine
flask-wtf
1 change: 1 addition & 0 deletions Flask_MongoEngine.egg-info/top_level.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
flask_mongoengine
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
Copyright (c) 2010-2011 See AUTHORS.
Copyright (c) 2010-2012 See AUTHORS.

Some rights reserved.

Expand Down
7 changes: 5 additions & 2 deletions MANIFEST.in
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
include AUTHORS LICENSE tests.py
include MANIFEST.in
include README.rst
include LICENSE
include AUTHORS
recursive-include flask_mongoengine/templates *.html
recursive-include docs *
recursive-exclude docs *.pyc
recursive-exclude docs *.pyo
prune docs/_build
prune docs/_themes/.git
prune docs/_themes/.git
13 changes: 5 additions & 8 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,15 @@ Installing Flask-MongoEngine

Install with **pip**::

pip install https://github.com/rozza/flask-mongoengine/tarball/master

pip install flask-mongoengine

Configuration
=============

Basic setup is easy, just fetch the extension::

from flask import Flask
from flaskext.mongoengine import MongoEngine
from flask_mongoengine import MongoEngine

app = Flask(__name__)
app.config.from_pyfile('the-config.cfg')
Expand Down Expand Up @@ -79,7 +78,7 @@ MongoEngine and WTForms

You can use MongoEngine and WTForms like so::

from flaskext.mongoengine.wtf import model_form
from flask_mongoengine.wtf import model_form

class User(db.Document):
email = db.StringField(required=True)
Expand Down Expand Up @@ -113,11 +112,9 @@ There are two panels for the flask-debugtoolbar included with flask-mongoengine.

Both of them track the time operations take, how many items had to be scanned, the query parameters and the collection being accessed, amongst other things. The key difference to the end user is that MongoDebugPanel records where the query was made from in your codebase.

MongoenginePanel uses MongoDB's in-built system profiler to track operations. It supports 2.0's overhaul of the profiler.

MongoDebugPanel (adapted from https://github.com/hmarr/django-debug-toolbar-mongo) works by monkey-patching PyMongo's operation functions (insert, update, etc.). It tries to identify where the query originated, and shows the relevant stacktrace (with line numbers, filenames, etc.). At the moment, it can't do this for queries made from templates.

See: https://github.com/mvantellingen/flask-debugtoolbar
See: https://github.com/MongoEngine/flask-debugtoolbar


Supported fields
Expand Down Expand Up @@ -152,4 +149,4 @@ Credits
Inspired by two repos:

`danjac <https://bitbucket.org/danjac/flask-mongoengine>`_
`maratfm <https://bitbucket.org/maratfm/wtforms>`_
`maratfm <https://bitbucket.org/maratfm/wtforms>`_
2 changes: 1 addition & 1 deletion docs/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ It is also assumed that you have `MongoDB`_ installed and running.
API
---

.. module:: flaskext.mongoengine
.. module:: flask_mongoengine

.. _Flask: http://flask.pocoo.org
.. _Github: https://github.com/sbook/flask-mongoengine
Expand Down
5 changes: 5 additions & 0 deletions example/README.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Sample app to test the toolbar
==============================

An example flask app - run `python simpleapp.py` and point your browser to localhost:4000/

54 changes: 54 additions & 0 deletions example/simpleapp.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
from __future__ import with_statement

import datetime
import flask

from random import choice

from flask_mongoengine import MongoEngine
from flask_mongoengine.wtf import model_form
from flask_debugtoolbar import DebugToolbarExtension

app = flask.Flask(__name__)
app.config.from_object(__name__)
app.config['MONGODB_DB'] = 'testing'
app.config['TESTING'] = True
app.config['SECRET_KEY'] = 'flask+mongoengine=<3'
app.debug = True
app.config['DEBUG_TB_PANELS'] = (
'flask_debugtoolbar.panels.versions.VersionDebugPanel',
'flask_debugtoolbar.panels.timer.TimerDebugPanel',
'flask_debugtoolbar.panels.headers.HeaderDebugPanel',
'flask_debugtoolbar.panels.request_vars.RequestVarsDebugPanel',
'flask_debugtoolbar.panels.template.TemplateDebugPanel',
'flask_debugtoolbar.panels.logger.LoggingPanel',
'flask_mongoengine.panels.MongoDebugPanel'
)

app.config['DEBUG_TB_INTERCEPT_REDIRECTS'] = False

db = MongoEngine()
db.init_app(app)

DebugToolbarExtension(app)


class Todo(db.Document):
title = db.StringField(max_length=60)
text = db.StringField()
done = db.BooleanField(default=False)
pub_date = db.DateTimeField(default=datetime.datetime.now)

@app.route('/')
def index():
# As a list to test debug toolbar
Todo.objects().delete() # Removes
Todo(title="Simple todo A", text="12345678910").save() # Insert
Todo(title="Simple todo B", text="12345678910").save() # Insert
Todo.objects(title__contains="B").update(set__text="Hello world") # Update
todos = list(Todo.objects[:10])
todos = Todo.objects.all()
return flask.render_template('index.html', todos=todos)

if __name__ == "__main__":
app.run(host="0.0.0.0", port=4000)
18 changes: 18 additions & 0 deletions example/static/style.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
body { font-family: sans-serif; background: #eee; }
a, h1, h2 { color: #377BA8; }
h1, h2 { font-family: 'Georgia', serif; margin: 0; }
h1 { border-bottom: 2px solid #eee; }
h2 { font-size: 1.2em; }

.page { margin: 2em auto; width: 35em; border: 5px solid #ccc;
padding: 0.8em; background: white; }
.entries { list-style: none; margin: 0; padding: 0; }
.entries li { margin: 0.8em 1.2em; }
.entries li h2 { margin-left: -1em; }
.add-entry { font-size: 0.9em; border-bottom: 1px solid #ccc; }
.add-entry dl { font-weight: bold; }
.metanav { text-align: right; font-size: 0.8em; padding: 0.3em;
margin-bottom: 1em; background: #fafafa; }
.flash { background: #CEE5F5; padding: 0.5em;
border: 1px solid #AACBE2; }
.error { background: #F0D6D6; padding: 0.5em; }
11 changes: 11 additions & 0 deletions example/templates/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{% extends "layout.html" %}
{% block body %}
{% for todo in todos %}
<div>
<h2>{{ todo.title }}</h2>
{{ todo.text|safe }}
</div>
{% else %}
<em>Unbelievable. No todos here so far <a href="/add">Add one</a></em>
{% endfor %}
{% endblock %}
15 changes: 15 additions & 0 deletions example/templates/layout.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<!doctype html>
<html>
<head>
<title>Flask MongoEngine</title>
<link rel=stylesheet type=text/css href="{{ url_for('static', filename='style.css') }}">
</head>
<body>
<div class=page>
<h1>Toolbar example</h1>
<div>
{% block body %}{% endblock %}
</div>
</div>
</body>
</html>
5 changes: 2 additions & 3 deletions flask_mongoengine/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import mongoengine

from mongoengine.queryset import MultipleObjectsReturned, DoesNotExist, QuerySet
from mongoengine import ValidationError
from mongoengine.base import ValidationError

from flask import abort

Expand All @@ -22,9 +22,8 @@ class MongoEngine(object):

def __init__(self, app=None):

_include_mongoengine(self)

self.Document = Document
_include_mongoengine(self)

if app is not None:
self.init_app(app)
Expand Down
Loading

0 comments on commit 3967c1a

Please sign in to comment.