feat: add basic App Info view (index only)
more to come!
This commit is contained in:
parent
9ac4f7525e
commit
9a739381ae
|
@ -24,3 +24,4 @@
|
||||||
views.common
|
views.common
|
||||||
views.essential
|
views.essential
|
||||||
views.master
|
views.master
|
||||||
|
views.settings
|
||||||
|
|
6
docs/api/wuttaweb/views.settings.rst
Normal file
6
docs/api/wuttaweb/views.settings.rst
Normal file
|
@ -0,0 +1,6 @@
|
||||||
|
|
||||||
|
``wuttaweb.views.settings``
|
||||||
|
===========================
|
||||||
|
|
||||||
|
.. automodule:: wuttaweb.views.settings
|
||||||
|
:members:
|
|
@ -118,8 +118,9 @@ class MenuHandler(GenericHandler):
|
||||||
'type': 'menu',
|
'type': 'menu',
|
||||||
'items': [
|
'items': [
|
||||||
{
|
{
|
||||||
'title': "TODO!",
|
'title': "App Info",
|
||||||
'url': '#',
|
'route': 'appinfo',
|
||||||
|
'perm': 'appinfo.list',
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
}
|
}
|
||||||
|
|
|
@ -249,6 +249,7 @@ def before_render(event):
|
||||||
context['h'] = helpers
|
context['h'] = helpers
|
||||||
context['url'] = request.route_url
|
context['url'] = request.route_url
|
||||||
context['json'] = json
|
context['json'] = json
|
||||||
|
context['b'] = 'o' if request.use_oruga else 'b' # for buefy
|
||||||
|
|
||||||
# TODO: this should be avoided somehow, for non-traditional web
|
# TODO: this should be avoided somehow, for non-traditional web
|
||||||
# apps, esp. "API" web apps. (in the meantime can configure the
|
# apps, esp. "API" web apps. (in the meantime can configure the
|
||||||
|
|
56
src/wuttaweb/templates/appinfo/index.mako
Normal file
56
src/wuttaweb/templates/appinfo/index.mako
Normal file
|
@ -0,0 +1,56 @@
|
||||||
|
## -*- coding: utf-8; -*-
|
||||||
|
<%inherit file="/master/index.mako" />
|
||||||
|
|
||||||
|
<%def name="page_content()">
|
||||||
|
|
||||||
|
<nav class="panel item-panel">
|
||||||
|
<p class="panel-heading">Application</p>
|
||||||
|
<div class="panel-block">
|
||||||
|
<div style="width: 100%;">
|
||||||
|
<b-field horizontal label="Distribution">
|
||||||
|
<span>${app.get_distribution(obj=app.get_web_handler()) or f'?? - set config for `{app.appname}.app_dist`'}</span>
|
||||||
|
</b-field>
|
||||||
|
<b-field horizontal label="Version">
|
||||||
|
<span>${app.get_version(obj=app.get_web_handler()) or f'?? - set config for `{app.appname}.app_dist`'}</span>
|
||||||
|
</b-field>
|
||||||
|
<b-field horizontal label="App Title">
|
||||||
|
<span>${app.get_title()}</span>
|
||||||
|
</b-field>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</nav>
|
||||||
|
|
||||||
|
<nav class="panel item-panel">
|
||||||
|
<p class="panel-heading">Configuration Files</p>
|
||||||
|
<div class="panel-block">
|
||||||
|
<div style="width: 100%;">
|
||||||
|
<${b}-table :data="configFiles">
|
||||||
|
|
||||||
|
<${b}-table-column field="priority"
|
||||||
|
label="Priority"
|
||||||
|
v-slot="props">
|
||||||
|
{{ props.row.priority }}
|
||||||
|
</${b}-table-column>
|
||||||
|
|
||||||
|
<${b}-table-column field="path"
|
||||||
|
label="File Path"
|
||||||
|
v-slot="props">
|
||||||
|
{{ props.row.path }}
|
||||||
|
</${b}-table-column>
|
||||||
|
|
||||||
|
</${b}-table>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</nav>
|
||||||
|
|
||||||
|
</%def>
|
||||||
|
|
||||||
|
<%def name="modify_this_page_vars()">
|
||||||
|
${parent.modify_this_page_vars()}
|
||||||
|
<script>
|
||||||
|
ThisPageData.configFiles = ${json.dumps([dict(path=p, priority=i) for i, p in enumerate(config.get_prioritized_files(), 1)])|n}
|
||||||
|
</script>
|
||||||
|
</%def>
|
||||||
|
|
||||||
|
|
||||||
|
${parent.body()}
|
|
@ -1,6 +1,10 @@
|
||||||
## -*- coding: utf-8; -*-
|
## -*- coding: utf-8; -*-
|
||||||
<%inherit file="/page.mako" />
|
<%inherit file="/page.mako" />
|
||||||
|
|
||||||
|
<%def name="title()">${index_title}</%def>
|
||||||
|
|
||||||
|
<%def name="content_title()"></%def>
|
||||||
|
|
||||||
<%def name="page_content()">
|
<%def name="page_content()">
|
||||||
<p>TODO: index page content</p>
|
<p>TODO: index page content</p>
|
||||||
</%def>
|
</%def>
|
||||||
|
|
|
@ -39,6 +39,7 @@ def defaults(config, **kwargs):
|
||||||
|
|
||||||
config.include(mod('wuttaweb.views.auth'))
|
config.include(mod('wuttaweb.views.auth'))
|
||||||
config.include(mod('wuttaweb.views.common'))
|
config.include(mod('wuttaweb.views.common'))
|
||||||
|
config.include(mod('wuttaweb.views.settings'))
|
||||||
|
|
||||||
|
|
||||||
def includeme(config):
|
def includeme(config):
|
||||||
|
|
47
src/wuttaweb/views/settings.py
Normal file
47
src/wuttaweb/views/settings.py
Normal file
|
@ -0,0 +1,47 @@
|
||||||
|
# -*- coding: utf-8; -*-
|
||||||
|
################################################################################
|
||||||
|
#
|
||||||
|
# wuttaweb -- Web App for Wutta Framework
|
||||||
|
# Copyright © 2024 Lance Edgar
|
||||||
|
#
|
||||||
|
# This file is part of Wutta Framework.
|
||||||
|
#
|
||||||
|
# Wutta Framework is free software: you can redistribute it and/or modify it
|
||||||
|
# under the terms of the GNU General Public License as published by the Free
|
||||||
|
# Software Foundation, either version 3 of the License, or (at your option) any
|
||||||
|
# later version.
|
||||||
|
#
|
||||||
|
# Wutta Framework is distributed in the hope that it will be useful, but
|
||||||
|
# WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||||
|
# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
|
||||||
|
# more details.
|
||||||
|
#
|
||||||
|
# You should have received a copy of the GNU General Public License along with
|
||||||
|
# Wutta Framework. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
#
|
||||||
|
################################################################################
|
||||||
|
"""
|
||||||
|
Views for app settings
|
||||||
|
"""
|
||||||
|
|
||||||
|
from wuttaweb.views import MasterView
|
||||||
|
|
||||||
|
|
||||||
|
class AppInfoView(MasterView):
|
||||||
|
"""
|
||||||
|
Master view for the overall app, to show/edit config etc.
|
||||||
|
"""
|
||||||
|
model_name = 'AppInfo'
|
||||||
|
model_title_plural = "App Info"
|
||||||
|
route_prefix = 'appinfo'
|
||||||
|
|
||||||
|
|
||||||
|
def defaults(config, **kwargs):
|
||||||
|
base = globals()
|
||||||
|
|
||||||
|
AppInfoView = kwargs.get('AppInfoView', base['AppInfoView'])
|
||||||
|
AppInfoView.defaults(config)
|
||||||
|
|
||||||
|
|
||||||
|
def includeme(config):
|
||||||
|
defaults(config)
|
|
@ -49,7 +49,7 @@ class TestForm(TestCase):
|
||||||
self.config = WuttaConfig(defaults={
|
self.config = WuttaConfig(defaults={
|
||||||
'wutta.web.menus.handler_spec': 'tests.utils:NullMenuHandler',
|
'wutta.web.menus.handler_spec': 'tests.utils:NullMenuHandler',
|
||||||
})
|
})
|
||||||
self.request = testing.DummyRequest(wutta_config=self.config)
|
self.request = testing.DummyRequest(wutta_config=self.config, use_oruga=False)
|
||||||
|
|
||||||
self.pyramid_config = testing.setUp(request=self.request, settings={
|
self.pyramid_config = testing.setUp(request=self.request, settings={
|
||||||
'mako.directories': ['wuttaweb:templates'],
|
'mako.directories': ['wuttaweb:templates'],
|
||||||
|
|
|
@ -219,7 +219,7 @@ class TestBeforeRender(TestCase):
|
||||||
})
|
})
|
||||||
|
|
||||||
def make_request(self):
|
def make_request(self):
|
||||||
request = testing.DummyRequest()
|
request = testing.DummyRequest(use_oruga=False)
|
||||||
request.registry.settings = {'wutta_config': self.config}
|
request.registry.settings = {'wutta_config': self.config}
|
||||||
request.wutta_config = self.config
|
request.wutta_config = self.config
|
||||||
return request
|
return request
|
||||||
|
|
|
@ -18,7 +18,7 @@ class TestMasterView(TestCase):
|
||||||
'wutta.web.menus.handler_spec': 'tests.utils:NullMenuHandler',
|
'wutta.web.menus.handler_spec': 'tests.utils:NullMenuHandler',
|
||||||
})
|
})
|
||||||
self.app = self.config.get_app()
|
self.app = self.config.get_app()
|
||||||
self.request = testing.DummyRequest(wutta_config=self.config)
|
self.request = testing.DummyRequest(wutta_config=self.config, use_oruga=False)
|
||||||
self.pyramid_config = testing.setUp(request=self.request, settings={
|
self.pyramid_config = testing.setUp(request=self.request, settings={
|
||||||
'wutta_config': self.config,
|
'wutta_config': self.config,
|
||||||
'mako.directories': ['wuttaweb:templates'],
|
'mako.directories': ['wuttaweb:templates'],
|
||||||
|
|
13
tests/views/test_settings.py
Normal file
13
tests/views/test_settings.py
Normal file
|
@ -0,0 +1,13 @@
|
||||||
|
# -*- coding: utf-8; -*-
|
||||||
|
|
||||||
|
from tests.views.utils import WebTestCase
|
||||||
|
|
||||||
|
from wuttaweb.views import settings
|
||||||
|
|
||||||
|
|
||||||
|
class TestAppInfoView(WebTestCase):
|
||||||
|
|
||||||
|
def test_index(self):
|
||||||
|
# just a sanity check
|
||||||
|
view = settings.AppInfoView(self.request)
|
||||||
|
response = view.index()
|
57
tests/views/utils.py
Normal file
57
tests/views/utils.py
Normal file
|
@ -0,0 +1,57 @@
|
||||||
|
# -*- coding: utf-8; -*-
|
||||||
|
|
||||||
|
from unittest import TestCase
|
||||||
|
from unittest.mock import MagicMock
|
||||||
|
|
||||||
|
from pyramid import testing
|
||||||
|
|
||||||
|
from wuttjamaican.conf import WuttaConfig
|
||||||
|
from wuttaweb import subscribers
|
||||||
|
|
||||||
|
|
||||||
|
class WebTestCase(TestCase):
|
||||||
|
"""
|
||||||
|
Base class for test suites requiring a full (typical) web app.
|
||||||
|
"""
|
||||||
|
|
||||||
|
def setUp(self):
|
||||||
|
self.setup_web()
|
||||||
|
|
||||||
|
def setup_web(self):
|
||||||
|
self.config = WuttaConfig(defaults={
|
||||||
|
'wutta.db.default.url': 'sqlite://',
|
||||||
|
'wutta.web.menus.handler_spec': 'tests.utils:NullMenuHandler',
|
||||||
|
})
|
||||||
|
|
||||||
|
self.request = testing.DummyRequest()
|
||||||
|
|
||||||
|
self.pyramid_config = testing.setUp(request=self.request, settings={
|
||||||
|
'wutta_config': self.config,
|
||||||
|
'mako.directories': ['wuttaweb:templates'],
|
||||||
|
})
|
||||||
|
|
||||||
|
# init db
|
||||||
|
self.app = self.config.get_app()
|
||||||
|
model = self.app.model
|
||||||
|
model.Base.metadata.create_all(bind=self.config.appdb_engine)
|
||||||
|
self.session = self.app.make_session()
|
||||||
|
|
||||||
|
# init web
|
||||||
|
self.pyramid_config.include('pyramid_mako')
|
||||||
|
self.pyramid_config.include('wuttaweb.static')
|
||||||
|
self.pyramid_config.include('wuttaweb.views.essential')
|
||||||
|
self.pyramid_config.add_subscriber('wuttaweb.subscribers.before_render',
|
||||||
|
'pyramid.events.BeforeRender')
|
||||||
|
|
||||||
|
# setup new request w/ anonymous user
|
||||||
|
event = MagicMock(request=self.request)
|
||||||
|
subscribers.new_request(event)
|
||||||
|
def user_getter(request, **kwargs): pass
|
||||||
|
subscribers.new_request_set_user(event, db_session=self.session,
|
||||||
|
user_getter=user_getter)
|
||||||
|
|
||||||
|
def tearDown(self):
|
||||||
|
self.teardown_web()
|
||||||
|
|
||||||
|
def teardown_web(self):
|
||||||
|
testing.tearDown()
|
Loading…
Reference in a new issue