Skip to content

Commit 719b5ff

Browse files
author
khz
committed
improved scaffolding using handler hidden_fields list
1 parent a5642ea commit 719b5ff

File tree

7 files changed

+32
-32
lines changed

7 files changed

+32
-32
lines changed

pythononwheels/start/handlers/base.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ def get_format_list(self, h=None):
6161
if not h:
6262
h = self.request.headers.get("Accept")
6363
headers_raw = h.split(",")
64-
print(headers_raw)
64+
print(" raw Accept header:" + str( headers_raw ))
6565
h_final = []
6666
# example Accept-header: text/html, application/xhtml+xml, application/xml;q=0.9, */*;q=0.8
6767
for elem in headers_raw:
@@ -102,20 +102,20 @@ def get_accept_format(self):
102102
accept_header = self.request.headers.get("Accept", None)
103103
if accept_header:
104104
format_list = self.get_format_list(accept_header)
105-
print("formats from Accept-Header: " + str(format_list))
105+
print(" formats from Accept-Header: " + str(format_list))
106106
# returns the first matched format from ordered Accept-Header list.
107107
for fo in format_list:
108108
if fo in cfg.myapp["supported_formats"]:
109109
return fo
110-
111-
if format == None:
110+
#print("format: " +format)
111+
if format == None or format == "*":
112112
# take the default app format (see config.cfg.myapp)
113113
format = cfg.myapp["default_format"]
114114

115115
if format in cfg.myapp["supported_formats"]:
116116
return format
117117
else:
118-
print("format error")
118+
print(" format error: " + str(format))
119119
return self.error(
120120
message="Format not supported. (see data.format)",
121121
data={
@@ -391,7 +391,7 @@ def write_error(status_code, **kwargs):
391391
If this error was caused by an uncaught exception
392392
(including HTTPError), an exc_info triple will be available as
393393
kwargs["exc_info"]. Note that this exception may not be the
394-
current exception for purposes of methods like sys.exc_info()
394+
current exception for purposes of methods like sys.exc_info()
395395
or traceback.format_exc.
396396
"""
397397
#if status_code == 404:

pythononwheels/start/handlers/shorties.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
import tornado.web
33
from {{appname}}.handlers.base import BaseHandler
44
from {{appname}}.application import app
5-
#
5+
66
# you can use regex in the routes as well:
77
# (r"/([^/]+)/(.+)", ObjectHandler),
88
# any regex goes. any group () will be handed to the handler
@@ -13,8 +13,8 @@
1313
@app.add_route("/thanks/([0-9]+)*", dispatch={"get": "testme"})
1414
class ThanksHandler(BaseHandler):
1515
def _get(self):
16-
print(" .. in _get: index = " + str(index))
17-
self.render("thanks.tmpl", index=index)
16+
print(" .. in _get" )
17+
self.render("thanks.tmpl")
1818

1919
def testme(self, index=0 ):
2020
print(" .. in testme: index = " + str(index))
@@ -25,7 +25,7 @@ def testme(self, index=0 ):
2525
@app.add_route("/", pos=1)
2626
class IndexdHandler(BaseHandler):
2727
def get(self, index=None):
28-
print(" index:" + str(index))
28+
print(" Calling IndexHandler from handlers/shorties.py: parameter index: " + str(index))
2929
self.render("index.tmpl")
3030

3131
# this will be the last route since it has the lowest pos.

pythononwheels/start/stubs/rest_handler_template.py

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -46,36 +46,36 @@ class {{handler_class_name}}(PowHandler):
4646
def show(self, id=None):
4747
m=Model()
4848
res=m.find_by_id(id)
49-
self.success(message="User show", data=res)
49+
self.success(message="{{handler_name}} show", data=res)
5050

5151
def list(self):
5252
m=Model()
5353
res = m.get_all()
54-
self.success(message="User, index", data=res)
54+
self.success(message="{{handler_name}}, index", data=res)
5555

5656
def page(self, page=0):
5757
m=Model()
5858
res=m.page(page=int(page), page_size=myapp["page_size"])
59-
self.success(message="user page: #" +str(page), data=res )
59+
self.success(message="{{handler_name}} page: #" +str(page), data=res )
6060

6161
def search(self):
6262
m=Model()
63-
return self.error(message="user search: not implemented yet ")
63+
return self.error(message="{{handler_name}} search: not implemented yet ")
6464

6565
@tornado.web.authenticated
6666
def edit(self, id=None):
6767
m=Model()
6868
try:
6969
print(" .. GET Edit Data (ID): " + id)
7070
res = m.find_by_id(id)
71-
self.success(message="user, edit id: " + str(id), data=res)
71+
self.success(message="{{handler_name}}, edit id: " + str(id), data=res)
7272
except Exception as e:
73-
self.error(message="user, edit id: " + str(id) + "msg: " + str(e) , data=None)
73+
self.error(message="{{handler_name}}, edit id: " + str(id) + "msg: " + str(e) , data=None)
7474

7575
@tornado.web.authenticated
7676
def new(self):
7777
m=Model()
78-
self.success(message="user, new",data=m)
78+
self.success(message="{{handler_name}}, new",data=m)
7979

8080
@tornado.web.authenticated
8181
def create(self):
@@ -84,10 +84,10 @@ def create(self):
8484
m=Model()
8585
m.init_from_json(data_json, simple_conversion=True)
8686
m.upsert()
87-
self.success(message="user, successfully created " + str(m.id),
87+
self.success(message="{{handler_name}}, successfully created " + str(m.id),
8888
data=m, format="json")
8989
except Exception as e:
90-
self.error(message="user, error updating " + str(m.id) + "msg: " + str(e),
90+
self.error(message="{{handler_name}}, error updating " + str(m.id) + "msg: " + str(e),
9191
data=m, format="json")
9292

9393
@tornado.web.authenticated
@@ -100,10 +100,10 @@ def update(self, id=None):
100100
try:
101101
#res.tags= res.tags.split(",")
102102
res.upsert()
103-
self.success(message="user, successfully updated " + str(res.id),
103+
self.success(message="{{handler_name}}, successfully updated " + str(res.id),
104104
data=res, format="json")
105105
except Exception as e:
106-
self.error(message="user, error updating: " + str(m.id) + "msg: " + str(e), data=data_json, format="json")
106+
self.error(message="{{handler_name}}, error updating: " + str(m.id) + "msg: " + str(e), data=data_json, format="json")
107107

108108

109109

pythononwheels/start/stubs/scaffold_edit_view.bs4

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@
8989
<form id="edit_form" name="edit_form">
9090

9191
{% for key in model.schema.keys() %}
92-
{% if key in cfg.myapp["internal_fields"] %}
92+
{% if key in cfg.myapp["internal_fields"] or key in hidden_list%}
9393
<input type="hidden" name="{{key}}" id="{{key}}" value="{{data.get(key)}}" />
9494
{% else %}
9595
{% set _type = elem.schema[key]["type"] %}

pythononwheels/start/stubs/scaffold_list_view.bs4

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@
6161
Create</a> a new {{model_name}} here.</p>
6262
</div>
6363
</div>
64-
64+
<div class="table-responsive">
6565
<table class="table table-bordered table-hover">
6666
<thead class="thead-inverse">
6767
<tr>
@@ -99,14 +99,15 @@
9999
{% end %}
100100

101101
{% except %}
102-
<tr>
103-
<td colspan="{{len(model.schema.keys())+1}}">
104-
<a href="/{{base_route_rest}}/new" class="btn btn-success">+</a> create a new {{model.__class__.__name__}}.
105-
</td>
106-
</tr>
102+
<tr>
103+
<td colspan="{{len(model.schema.keys())+1}}">
104+
<a href="/{{base_route_rest}}/new" class="btn btn-success">+</a> create a new {{model.__class__.__name__}}.
105+
</td>
106+
</tr>
107107
{% end %}
108-
</tbody>
109-
</table>
108+
</tbody>
109+
</table>
110+
</div> <!-- div class=table-responsive-->
110111
<hr>
111112
<h2>Info: </h2>
112113
<hr>

pythononwheels/start/stubs/scaffold_new_view.bs4

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@
7676

7777
<form id="create_form" name="create_form">
7878
{% for key in model.schema.keys() %}
79-
{% if key not in cfg.myapp["internal_fields"] %}
79+
{% if key not in cfg.myapp["internal_fields"] and key not in hide_list %}
8080
{% set _type = model.schema[key]["type"] %}
8181
{% if _type == "string" %}
8282
{% if "allowed" in model.schema[key].keys() %}

pythononwheels/start/views/footer.bs4

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313
================================================== -->
1414
<!-- Placed at the end of the document so the pages load faster -->
1515
<script src="{{ static_url("js/jquery.min.js") }}" integrity="sha384-THPy051/pYDQGanwU6poAc/hOdQxjnOEXzbT+OuUAFqNqFjL+4IGLBgCJC3ZOShY" crossorigin="anonymous"></script>
16-
<script>window.jQuery || document.write('<script src="../../assets/js/vendor/jquery.min.js"><\/script>')</script>
1716
<script src="{{ static_url("js/tether.min.js") }}" integrity="sha384-Plbmg8JY28KFelvJVai01l8WyZzrYWG825m+cZ0eDDS1f7d/js6ikvy1+X+guPIB" crossorigin="anonymous"></script>
1817
<script src="{{ static_url("js/bootstrap.min.js")}}"></script>
1918
<script src="{{ static_url("js/prism.js")}}"></script>

0 commit comments

Comments
 (0)