Skip to content

Commit

Permalink
Updated examples, added wysiwyg example
Browse files Browse the repository at this point in the history
  • Loading branch information
mrjoes committed Mar 20, 2013
1 parent 6a53076 commit 5ce29d1
Show file tree
Hide file tree
Showing 20 changed files with 104 additions and 4 deletions.
4 changes: 2 additions & 2 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ Flask-Admin
===========

.. image:: https://travis-ci.org/mrjoes/flask-admin.png?branch=master
:target: https://secure.travis-ci.org/mrjoes/flask-admin
:target: https://travis-ci.org/mrjoes/flask-admin


Introduction
Expand Down Expand Up @@ -35,4 +35,4 @@ Some ideas were taken from the `Flask-Admin <https://github.com/wilsaj/flask-adm
Examples
--------

The library comes with a few examples, you can find them in the `examples` directory.
The library comes with a few examples, you can find them in the `examples <https://github.com/mrjoes/flask-admin/tree/master/examples` directory.
1 change: 1 addition & 0 deletions examples/auth-mongoengine/README.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
This example shows how to integrate Flask-Login authentication with the Flask-Admin using MongoEngine backend.
1 change: 1 addition & 0 deletions examples/auth/README.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
This example shows how to integrate Flask-Login authentication with the Flask-Admin using SQLAlchemy backend.
2 changes: 1 addition & 1 deletion examples/auth/auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from flask.ext import admin, login, wtf
from flask.ext.admin.contrib import sqlamodel

# Create application
# Create Flask application
app = Flask(__name__)

# Create dummy secrey key so we can use sessions
Expand Down
1 change: 1 addition & 0 deletions examples/babel/README.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
This example show how to translate Flask-Admin into different language using customized version of the `Flask-Babel <https://github.com/mrjoes/flask-babel>`
1 change: 1 addition & 0 deletions examples/file/README.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Simple file management interface example.
1 change: 1 addition & 0 deletions examples/menu-external-links/README.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
External menu links example.
1 change: 1 addition & 0 deletions examples/methodview/README.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Example which shows how to integrate Flask `MethodView` with Flask-Admin.
5 changes: 4 additions & 1 deletion examples/methodview/methodview.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from flask import Flask, redirect, render_template, request
from flask import Flask, redirect, request

from flask.ext import admin
from flask.views import MethodView
Expand All @@ -13,16 +13,19 @@ def index(self):
class API_v1(MethodView):
def get(self, cls):
return cls.render('test.html', request=request, name="API_v1")

def post(self, cls):
return cls.render('test.html', request=request, name="API_v1")

@admin.expose_plugview('/_api/2')
class API_v2(MethodView):
def get(self, cls):
return cls.render('test.html', request=request, name="API_v2")

def post(self, cls):
return cls.render('test.html', request=request, name="API_v2")


# Create flask app
app = Flask(__name__, template_folder='templates')

Expand Down
1 change: 1 addition & 0 deletions examples/mongoengine/README.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
MongoEngine model backend integration.
1 change: 1 addition & 0 deletions examples/mongoengine/simple.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
db.init_app(app)


# Define mongoengine documents
class User(db.Document):
name = db.StringField(max_length=40)
tags = db.ListField(db.ReferenceField('Tag'))
Expand Down
1 change: 1 addition & 0 deletions examples/multi/README.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
This example shows how to create two separate instances of Flask-Admin for one Flask application.
1 change: 1 addition & 0 deletions examples/peewee/README.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Peewee model backend integration example.
1 change: 1 addition & 0 deletions examples/pymongo/README.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
PyMongo model backend integration example.
1 change: 1 addition & 0 deletions examples/quickstart/README.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Simple Flask-Admin examples used by the quickstart tutorial.
1 change: 1 addition & 0 deletions examples/sqla/README.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
SQLAlchemy model backend integration example.
1 change: 1 addition & 0 deletions examples/wysiwyg/README.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Simple CKEditor integration example.
71 changes: 71 additions & 0 deletions examples/wysiwyg/simple.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
import datetime

from sqlalchemy.ext.hybrid import hybrid_property

from flask import Flask
from flask.ext.sqlalchemy import SQLAlchemy

from flask.ext import admin, wtf
from flask.ext.admin.contrib import sqlamodel
from flask.ext.admin.contrib.sqlamodel import filters

# Create application
app = Flask(__name__)

# Create dummy secrey key so we can use sessions
app.config['SECRET_KEY'] = '123456790'

# Create in-memory database
app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///dummy.sqlite'
app.config['SQLALCHEMY_ECHO'] = True
db = SQLAlchemy(app)


# Define wtforms widget and field
class CKTextAreaWidget(wtf.TextArea):
def __call__(self, field, **kwargs):
kwargs.setdefault('class_', 'ckeditor')
return super(CKTextAreaWidget, self).__call__(field, **kwargs)


class CKTextAreaField(wtf.TextAreaField):
widget = CKTextAreaWidget()


# Model
class Page(db.Model):
id = db.Column(db.Integer, primary_key=True)
name = db.Column(db.Unicode(64))
text = db.Column(db.UnicodeText)

def __unicode__(self):
return self.name


# Customized admin interface
class PageAdmin(sqlamodel.ModelView):
form_overrides = dict(text=CKTextAreaField)

create_template = 'create.html'
edit_template = 'edit.html'


# Flask views
@app.route('/')
def index():
return '<a href="/admin/">Click me to get to Admin!</a>'


if __name__ == '__main__':
# Create admin
admin = admin.Admin(app)

# Add views
admin.add_view(PageAdmin(Page, db.session))

# Create DB
db.create_all()

# Start app
app.debug = True
app.run('0.0.0.0', 8000)
6 changes: 6 additions & 0 deletions examples/wysiwyg/templates/create.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{% extends 'admin/model/create.html' %}

{% block tail %}
{{ super() }}
<script src="http://cdnjs.cloudflare.com/ajax/libs/ckeditor/4.0.1/ckeditor.js"></script>
{% endblock %}
6 changes: 6 additions & 0 deletions examples/wysiwyg/templates/edit.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{% extends 'admin/model/create.html' %}

{% block tail %}
{{ super() }}
<script src="http://cdnjs.cloudflare.com/ajax/libs/ckeditor/4.0.1/ckeditor.js"></script>
{% endblock %}

0 comments on commit 5ce29d1

Please sign in to comment.