-
Notifications
You must be signed in to change notification settings - Fork 8
/
newsitt.txt
132 lines (94 loc) · 2.59 KB
/
newsitt.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
newsitt progressions
# newsitt1
##### models.py
from .common import db, Field
from pydal.validators import *
db.define_table('post',
Field('title','string'),
Field('body', 'text'))
db.commit()
##### controllers.py
from py4web import action, request, abort, redirect, URL
from yatl.helpers import A
from .common import db, session, T, cache, auth, logger, authenticated, unauthenticated
# TODO: Doesn't work for some reason
# from py4web.utils.form import FormStyleBootstrap4
from py4web.utils.form import Form, FormStyleBulma
@unauthenticated()
@action("index")
@action.uses('index.html')
#@action.uses(auth, "index.html")
def index():
query=db(db.post).select()
return dict(query=query)
@action("new",method=['GET','POST'])
@action.uses('new.html')
def new():
#form=Form(db.post,formstyle=FormStyleBulma)
form=Form(db.post)
return dict(form=form)
##### templates/index.html
[[extend 'layout.html']]
<table>
[[for q in query:]]
<tr><td>[[=q.title]]</td></tr>
[[pass]]
</table>
[[=A('New post', _href=URL('new'))]]
##### templates/new.html
[[extend 'layout.html']]
<h1>New Post</h1>
[[=form]]
[[=A('Home', _href=URL('index'))]]
# newsitt2
##### models.py
from .common import db, Field
from pydal.validators import *
db.define_table('post',
Field('title','string'),
Field('body', 'text'))
db.commit()
##### controllers.py
from py4web import action, request, abort, redirect, URL
from yatl.helpers import A
from .common import db, session, T, cache, auth, logger, authenticated, unauthenticated
# TODO: Doesn't work for some reason
# from py4web.utils.form import FormStyleBootstrap4
from py4web.utils.form import Form, FormStyleBulma
@unauthenticated()
@action("index")
@action.uses('index.html')
#@action.uses(auth, "index.html")
def index():
query=db(db.post).select()
return dict(query=query)
@action("new",method=['GET','POST'])
@action.uses('new.html')
def new():
form=Form(db.post)
if form.accepted:
redirect(URL('index'))
return dict(form=form)
@action("post/<id>")
@action.uses('post.html')
def post(id):
post=db.post(id)
form=Form(db.post,post)
return dict(post=post,form=form)
##### templates/index.html
[[extend 'layout.html']]
<table>
[[for q in query:]]
<tr><td><a href="[[=URL('post',q.id)]]">[[=q.title]]</a></td></tr>
[[pass]]
</table>
[[=A('New post', _href=URL('new'))]]
##### templates/new.html
[[extend 'layout.html']]
<h1>New Post</h1>
[[=form]]
[[=A('Home', _href=URL('index'))]]
##### templates/post.html
[[extend 'layout.html']]
<h1>[[=post.title]]</h1>
[[=A('Home', _href=URL('index'))]]