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,10 +229,16 @@ class BaseView(with_metaclass(AdminViewMeta, BaseViewClass)): ...@@ -229,10 +229,16 @@ class BaseView(with_metaclass(AdminViewMeta, BaseViewClass)):
if not self.url.startswith('/'): if not self.url.startswith('/'):
self.url = '%s/%s' % (self.admin.url, self.url) self.url = '%s/%s' % (self.admin.url, self.url)
# If we're working from the root of the site, set prefix to None # If we're working from the root of the site, set prefix to None
if self.url == '/': if self.url == '/':
self.url = None 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 name is not povided, use capitalized endpoint name
if self.name is None: if self.name is None:
self.name = self._prettify_class_name(self.__class__.__name__) self.name = self._prettify_class_name(self.__class__.__name__)
...@@ -383,9 +389,21 @@ class AdminIndexView(BaseView): ...@@ -383,9 +389,21 @@ class AdminIndexView(BaseView):
@expose('/') @expose('/')
def index(self): def index(self):
arg1 = 'Hello' arg1 = 'Hello'
return render_template('adminhome.html', arg1=arg1) return self.render('admin/myhome.html', arg1=arg1)
admin = Admin(index_view=MyHomeView()) 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: Default values for the index page are:
......
...@@ -69,24 +69,29 @@ class TimeField(fields.Field): ...@@ -69,24 +69,29 @@ class TimeField(fields.Field):
def _value(self): def _value(self):
if self.raw_data: if self.raw_data:
return u' '.join(self.raw_data) return u' '.join(self.raw_data)
elif self.data is not None:
return self.data.strftime(self.default_format)
else: else:
return self.data and self.data.strftime(self.default_format) or u'' return u''
def process_formdata(self, valuelist): def process_formdata(self, valuelist):
if valuelist: if valuelist:
date_str = u' '.join(valuelist) date_str = u' '.join(valuelist)
for format in self.formats: if date_str.strip():
try: for format in self.formats:
timetuple = time.strptime(date_str, format) try:
self.data = datetime.time(timetuple.tm_hour, timetuple = time.strptime(date_str, format)
timetuple.tm_min, self.data = datetime.time(timetuple.tm_hour,
timetuple.tm_sec) timetuple.tm_min,
return timetuple.tm_sec)
except ValueError: return
pass except ValueError:
pass
raise ValueError(gettext('Invalid time format'))
raise ValueError(gettext('Invalid time format'))
else:
self.data = None
class Select2Field(fields.SelectField): class Select2Field(fields.SelectField):
......
...@@ -121,7 +121,9 @@ def test_model(): ...@@ -121,7 +121,9 @@ def test_model():
eq_(rv.status_code, 200) eq_(rv.status_code, 200)
rv = client.post('/admin/model1/new/', 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) eq_(rv.status_code, 302)
model = db.session.query(Model1).first() model = db.session.query(Model1).first()
...@@ -137,6 +139,9 @@ def test_model(): ...@@ -137,6 +139,9 @@ def test_model():
url = '/admin/model1/edit/?id=%s' % model.id url = '/admin/model1/edit/?id=%s' % model.id
rv = client.get(url) rv = client.get(url)
eq_(rv.status_code, 200) 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, rv = client.post(url,
data=dict(test1='test1small', test2='test2large')) data=dict(test1='test1small', test2='test2large'))
......
from nose.tools import ok_, eq_, raises 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.views import MethodView
from flask.ext.admin import base from flask.ext.admin import base
...@@ -132,6 +132,11 @@ def test_admin_customizations(): ...@@ -132,6 +132,11 @@ def test_admin_customizations():
client = app.test_client() client = app.test_client()
rv = client.get('/foobar/') rv = client.get('/foobar/')
eq_(rv.status_code, 200) 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(): def test_baseview_registration():
...@@ -359,6 +364,11 @@ def test_root_mount(): ...@@ -359,6 +364,11 @@ def test_root_mount():
client = app.test_client() client = app.test_client()
rv = client.get('/mockview/') rv = client.get('/mockview/')
eq_(rv.data, b'Success!') 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(): def test_menu_links():
......
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