adding character sheets
This commit is contained in:
@@ -7,8 +7,9 @@ from tg.util.bunch import Bunch
|
||||
|
||||
from wsgiref.simple_server import make_server
|
||||
import webhelpers2
|
||||
import tw2.core
|
||||
|
||||
from ttfrog.webserver import controllers
|
||||
from ttfrog.webserver.controllers import RootController
|
||||
from ttfrog.db import db
|
||||
import ttfrog.path
|
||||
|
||||
@@ -28,7 +29,7 @@ def application():
|
||||
config.update_blueprint({
|
||||
|
||||
# rendering
|
||||
'root_controller': controllers.RootController(),
|
||||
'root_controller': RootController(),
|
||||
'default_renderer': 'jinja',
|
||||
'renderers': ['jinja'],
|
||||
'tg.jinja_filters': {},
|
||||
@@ -37,7 +38,7 @@ def application():
|
||||
# helpers
|
||||
'app_globals': app_globals,
|
||||
'helpers': webhelpers2,
|
||||
'tw2.enabled': True,
|
||||
'use_toscawidgets2': True,
|
||||
|
||||
# assets
|
||||
'serve_static': True,
|
||||
@@ -51,7 +52,9 @@ def application():
|
||||
'sqlalchemy.url': db.url,
|
||||
'model': db,
|
||||
})
|
||||
return config.make_wsgi_app()
|
||||
|
||||
# wrap the core wsgi app in a ToscaWidgets2 app
|
||||
return tw2.core.make_middleware(config.make_wsgi_app(), default_engine='jinja')
|
||||
|
||||
|
||||
def start(host: str, port: int, debug: bool = False) -> None:
|
||||
|
||||
@@ -0,0 +1,3 @@
|
||||
from .root import RootController
|
||||
|
||||
__ALL__ = [RootController]
|
||||
@@ -0,0 +1,29 @@
|
||||
from tg import expose
|
||||
from tg import TGController
|
||||
from ttfrog.db import db
|
||||
from ttfrog.db.schema import Character
|
||||
from ttfrog.webserver.widgets import CharacterSheet
|
||||
|
||||
|
||||
class CharacterSheetController(TGController):
|
||||
@expose()
|
||||
def _lookup(self, *parts):
|
||||
return FormController(parts[0]), parts[1:]
|
||||
|
||||
|
||||
class FormController:
|
||||
|
||||
def __init__(self, slug: str):
|
||||
self.character = dict()
|
||||
if slug:
|
||||
self.load(slug)
|
||||
|
||||
def load(self, slug: str) -> None:
|
||||
self.character = db.query(Character).filter(Character.columns.slug == slug)[0]._mapping
|
||||
|
||||
@expose('character_sheet.html')
|
||||
def _default(self, *args, **kwargs):
|
||||
if kwargs:
|
||||
db.update(Character, **kwargs)
|
||||
self.load(self.character['slug'])
|
||||
return dict(page='sheet', form=CharacterSheet, character=self.character)
|
||||
@@ -2,11 +2,13 @@ from tg import expose
|
||||
from tg import TGController
|
||||
from tg import tmpl_context
|
||||
from ttfrog.db import db
|
||||
from ttfrog.db.schema import Character
|
||||
from ttfrog.webserver.controllers.character_sheet import CharacterSheetController
|
||||
|
||||
|
||||
class RootController(TGController):
|
||||
|
||||
sheet = CharacterSheetController()
|
||||
|
||||
def _before(self, *args, **kwargs):
|
||||
tmpl_context.project_name = 'TableTop Frog'
|
||||
|
||||
@@ -0,0 +1,13 @@
|
||||
import tw2.core
|
||||
import tw2.forms
|
||||
from tg import lurl
|
||||
|
||||
|
||||
class CharacterSheet(tw2.forms.Form):
|
||||
class child(tw2.forms.TableLayout):
|
||||
name = tw2.forms.TextField()
|
||||
level = tw2.forms.TextField()
|
||||
ancestry_name = tw2.forms.TextField(label='Ancestry')
|
||||
id = tw2.forms.HiddenField()
|
||||
|
||||
action = ''
|
||||
Reference in New Issue
Block a user