Skip to content

Commit

Permalink
Layout sample wip
Browse files Browse the repository at this point in the history
  • Loading branch information
mrjoes committed Mar 21, 2013
1 parent f0f0738 commit 4f1df6d
Show file tree
Hide file tree
Showing 7 changed files with 201 additions and 5 deletions.
64 changes: 64 additions & 0 deletions examples/layout/simple.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
from flask import Flask
from flask.ext.sqlalchemy import SQLAlchemy

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

# 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)


# Models
class User(db.Model):
id = db.Column(db.Integer, primary_key=True)
name = db.Column(db.Unicode(64))
email = db.Column(db.Unicode(64))

def __unicode__(self):
return self.name


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 CustomView(ModelView):
list_template = 'list.html'
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, base_template='layout.html')

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

# Create DB
db.create_all()

# Start app
app.debug = True
app.run('0.0.0.0', 8000)
3 changes: 3 additions & 0 deletions examples/layout/static/layout.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
.btn-title {
float: right;
}
1 change: 1 addition & 0 deletions examples/layout/templates/create.html
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{% extends 'admin/model/create.html' %}
1 change: 1 addition & 0 deletions examples/layout/templates/edit.html
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{% extends 'admin/model/edit.html' %}
25 changes: 25 additions & 0 deletions examples/layout/templates/layout.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
{% import 'admin/layout.html' as layout with context -%}
{% extends 'admin/base.html' %}

{% block head_css %}
{{ super() }}
<link href="{{ url_for('static', filename='layout.css') }}" rel="stylesheet">
{% endblock %}

{% block page_body %}
<div class="container">
<div class="row">
<div class="span2">
<ul class="nav nav-pills nav-stacked">
{{ layout.menu() }}
{{ layout.menu_links() }}
</ul>
</div>
<div class="span10">
{% block brand %}<h1>{{ admin_view.name|capitalize }}</h1>{% endblock %}
{{ layout.messages() }}
{% block body %}{% endblock %}
</div>
</div>
</div>
{% endblock %}
107 changes: 107 additions & 0 deletions examples/layout/templates/list.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
{% extends 'admin/model/list.html' %}
{% import 'admin/model/layout.html' as model_layout with context %}

{% block brand %}
<h1 style="float: left">{{ admin_view.name|capitalize }} model</h1>
{% if admin_view.can_create %}
<a href="{{ url_for('.create_view', url=return_url) }}" class="btn btn-primary btn-title">{{ _gettext('Create') }}</a>
{% endif %}

{% if filter_groups %}
{{ model_layout.filter_options() }}
{% endif %}

{% if actions %}
<div class="btn-group btn-title">
{{ actionlib.dropdown(actions) }}
</div>
{% endif %}

{% if search_supported %}
{{ model_layout.search_form() }}
{% endif %}
<div class="clearfix"></div>
<hr>
{% endblock %}

{% block body %}
{% if filter_groups %}
{{ model_layout.filter_form() }}
{% endif %}

<table class="table table-striped table-bordered model-list">
<thead>
<tr>
{% block list_header scoped %}
{% if actions %}
<th class="span1">
<input type="checkbox" name="rowtoggle" class="action-rowtoggle" />
</th>
{% endif %}
<th class="span1">&nbsp;</th>
{% set column = 0 %}
{% for c, name in list_columns %}
<th>
{% if admin_view.is_sortable(c) %}
{% if sort_column == column %}
<a href="{{ sort_url(column, True) }}">
{{ name }}
{% if sort_desc %}
<i class="icon-chevron-up"></i>
{% else %}
<i class="icon-chevron-down"></i>
{% endif %}
</a>
{% else %}
<a href="{{ sort_url(column) }}">{{ name }}</a>
{% endif %}
{% else %}
{{ name }}
{% endif %}
{% if admin_view.column_descriptions.get(c) %}
<a class="icon-question-sign"
title="{{ admin_view.column_descriptions[c] }}"
href="#" data-role="tooltip"
></a>
{% endif %}
</th>
{% set column = column + 1 %}
{% endfor %}
{% endblock %}
</tr>
</thead>
{% for row in data %}
<tr>
{% block list_row scoped %}
{% if actions %}
<td>
<input type="checkbox" name="rowid" class="action-checkbox" value="{{ get_pk_value(row) }}" />
</td>
{% endif %}
<td>
{% block list_row_actions scoped %}
{%- if admin_view.can_edit -%}
<a class="icon" href="{{ url_for('.edit_view', id=get_pk_value(row), url=return_url) }}">
<i class="icon-pencil"></i>
</a>
{%- endif -%}
{%- if admin_view.can_delete -%}
<form class="icon" method="POST" action="{{ url_for('.delete_view', id=get_pk_value(row), url=return_url) }}">
<button onclick="return confirm('{{ _gettext('You sure you want to delete this item?') }}');">
<i class="icon-remove"></i>
</button>
</form>
{%- endif -%}
{% endblock %}
</td>
{% for c, name in list_columns %}
<td>{{ get_value(row, c) }}</td>
{% endfor %}
{% endblock %}
</tr>
{% endfor %}
</table>
{{ lib.pager(page, num_pages, pager_url) }}

{{ actionlib.form(actions, url_for('.action_view')) }}
{% endblock %}
5 changes: 0 additions & 5 deletions examples/wysiwyg/simple.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,8 @@
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__)
Expand Down

0 comments on commit 4f1df6d

Please sign in to comment.