Commit 5bec9db7 authored by Serge S. Koval's avatar Serge S. Koval

Fixed #39. Now it is possible to pass subdomain

parent a850544e
...@@ -126,11 +126,18 @@ class BaseView(object): ...@@ -126,11 +126,18 @@ class BaseView(object):
# If url is not provided, generate it from endpoint name # If url is not provided, generate it from endpoint name
if self.url is None: if self.url is None:
self.url = '%s/%s' % (self.admin.url, self.endpoint) if self.admin.url != '/':
self.url = '%s/%s' % (self.admin.url, self.endpoint)
else:
self.url = '/'
else: else:
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 self.url == '/':
self.url = None
# 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_name(self.__class__.__name__) self.name = self._prettify_name(self.__class__.__name__)
...@@ -138,6 +145,7 @@ class BaseView(object): ...@@ -138,6 +145,7 @@ class BaseView(object):
# Create blueprint and register rules # Create blueprint and register rules
self.blueprint = Blueprint(self.endpoint, __name__, self.blueprint = Blueprint(self.endpoint, __name__,
url_prefix=self.url, url_prefix=self.url,
subdomain=self.admin.subdomain,
template_folder='templates', template_folder='templates',
static_folder=self.static_folder) static_folder=self.static_folder)
...@@ -214,13 +222,16 @@ class AdminIndexView(BaseView): ...@@ -214,13 +222,16 @@ class AdminIndexView(BaseView):
* Automatically associates with static folder. * Automatically associates with static folder.
""" """
def __init__(self, name=None, category=None, endpoint=None, url=None): def __init__(self, name=None, category=None, endpoint=None, url=None):
if url is None:
url = '/admin'
super(AdminIndexView, self).__init__(name or babel.lazy_gettext('Home'), super(AdminIndexView, self).__init__(name or babel.lazy_gettext('Home'),
category, category,
endpoint or 'admin', endpoint or 'admin',
url or '/admin', url,
'static') 'static')
@expose('/') @expose()
def index(self): def index(self):
return self.render('admin/index.html') return self.render('admin/index.html')
...@@ -277,7 +288,9 @@ class Admin(object): ...@@ -277,7 +288,9 @@ class Admin(object):
""" """
Collection of the views. Also manages menu structure. Collection of the views. Also manages menu structure.
""" """
def __init__(self, app=None, name=None, url=None, index_view=None, def __init__(self, app=None, name=None,
url=None, subdomain=None,
index_view=None,
translations_path=None): translations_path=None):
""" """
Constructor. Constructor.
...@@ -286,6 +299,10 @@ class Admin(object): ...@@ -286,6 +299,10 @@ class Admin(object):
Flask application object Flask application object
`name` `name`
Application name. Will be displayed in main menu and as a page title. If not provided, defaulted to "Admin" Application name. Will be displayed in main menu and as a page title. If not provided, defaulted to "Admin"
`url`
Base URL
`subdomain`
Subdomain to use
`index_view` `index_view`
Home page view to use. If not provided, will use `AdminIndexView`. Home page view to use. If not provided, will use `AdminIndexView`.
`translations_path` `translations_path`
...@@ -307,6 +324,7 @@ class Admin(object): ...@@ -307,6 +324,7 @@ class Admin(object):
if url is None: if url is None:
url = '/admin' url = '/admin'
self.url = url self.url = url
self.subdomain = subdomain
# Localizations # Localizations
self.locale_selector_func = None self.locale_selector_func = None
......
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