Commit 2a69c428 authored by Serge S. Koval's avatar Serge S. Koval

Merge branch 'master' of github.com:mrjoes/flask-admin

parents e66debf0 339a239a
......@@ -229,9 +229,15 @@ class BaseView(with_metaclass(AdminViewMeta, BaseViewClass)):
if not self.url.startswith('/'):
self.url = '%s/%s' % (self.admin.url, self.url)
# If we're working from the root of the site, set prefix to None
if self.url == '/':
self.url = None
# prevent admin static files from conflicting with flask static files
if not self.static_url_path:
self.static_folder='static'
self.static_url_path='/static/admin'
# If name is not povided, use capitalized endpoint name
if self.name is None:
......@@ -383,10 +389,22 @@ class AdminIndexView(BaseView):
@expose('/')
def index(self):
arg1 = 'Hello'
return render_template('adminhome.html', arg1=arg1)
return self.render('admin/myhome.html', arg1=arg1)
admin = Admin(index_view=MyHomeView())
Also, you can change the root url from /admin to / with the following::
admin = Admin(
app,
index_view=AdminIndexView(
name='Home',
template='admin/myhome.html',
url='/'
)
)
Default values for the index page are:
* If a name is not provided, 'Home' will be used.
......
......@@ -69,13 +69,16 @@ class TimeField(fields.Field):
def _value(self):
if self.raw_data:
return u' '.join(self.raw_data)
elif self.data is not None:
return self.data.strftime(self.default_format)
else:
return self.data and self.data.strftime(self.default_format) or u''
return u''
def process_formdata(self, valuelist):
if valuelist:
date_str = u' '.join(valuelist)
if date_str.strip():
for format in self.formats:
try:
timetuple = time.strptime(date_str, format)
......@@ -87,6 +90,8 @@ class TimeField(fields.Field):
pass
raise ValueError(gettext('Invalid time format'))
else:
self.data = None
class Select2Field(fields.SelectField):
......
......@@ -121,7 +121,9 @@ def test_model():
eq_(rv.status_code, 200)
rv = client.post('/admin/model1/new/',
data=dict(test1='test1large', test2='test2'))
data=dict(test1='test1large',
test2='test2',
time_field=time(0,0,0)))
eq_(rv.status_code, 302)
model = db.session.query(Model1).first()
......@@ -138,6 +140,9 @@ def test_model():
rv = client.get(url)
eq_(rv.status_code, 200)
# verify that midnight does not show as blank
ok_(u'00:00:00' in rv.data.decode('utf-8'))
rv = client.post(url,
data=dict(test1='test1small', test2='test2large'))
eq_(rv.status_code, 302)
......
from nose.tools import ok_, eq_, raises
from flask import Flask, request, abort
from flask import Flask, request, abort, url_for
from flask.views import MethodView
from flask.ext.admin import base
......@@ -133,6 +133,11 @@ def test_admin_customizations():
rv = client.get('/foobar/')
eq_(rv.status_code, 200)
# test custom static_url_path
with app.test_request_context('/'):
rv = client.get(url_for('admin.static', filename='bootstrap/bootstrap2/css/bootstrap.css'))
eq_(rv.status_code, 200)
def test_baseview_registration():
admin = base.Admin()
......@@ -360,6 +365,11 @@ def test_root_mount():
rv = client.get('/mockview/')
eq_(rv.data, b'Success!')
# test static files when url='/'
with app.test_request_context('/'):
rv = client.get(url_for('admin.static', filename='bootstrap/bootstrap2/css/bootstrap.css'))
eq_(rv.status_code, 200)
def test_menu_links():
app = Flask(__name__)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment