Commits

Ralph Bean committed b203658

Building a Form

  • Participants
  • Parent commits a7c727f

Comments (0)

Files changed (4)

File myapp/myapp/controllers/movie.py

+from tg import expose, request
+
+from myapp.lib.base import BaseController
+from myapp import model
+
+__all__ = ['MovieController']
+
+import tw2.core
+import tw2.forms
+
+class MovieForm(tw2.forms.FormPage):
+    title = 'Movie'
+    resources = [tw2.core.CSSLink(link='/css/myapp.css')]
+    class child(tw2.forms.TableForm):
+        title = tw2.forms.TextField(validator=tw2.core.Required)
+        director = tw2.forms.TextField()
+        genres = tw2.forms.CheckBoxList(options=['Action', 'Comedy', 'Romance', 'Sci-fi'])
+        class cast(tw2.forms.GridLayout):
+            extra_reps = 5
+            character = tw2.forms.TextField()
+            actor = tw2.forms.TextField()
+
+class MovieController(BaseController):
+    @expose('myapp.templates.widget')
+    def movie(self, *args, **kw):
+        w = MovieForm(redirect='/movie/').req()
+        return dict(widget=w, page='movie')

File myapp/myapp/controllers/root.py

 from myapp.controllers.secure import SecureController
 
 from myapp.controllers.error import ErrorController
+from myapp.controllers.movie import MovieController
 
 __all__ = ['RootController']
 
     admin = AdminController(model, DBSession, config_type=TGAdminConfig)
 
     error = ErrorController()
+    movie = MovieController()
 
     @expose('myapp.templates.index')
     def index(self):

File myapp/myapp/public/css/myapp.css

+th {
+    vertical-align: top;
+    text-align: left;
+    font-weight: normal;
+}
+
+ul {
+    list-style-type: none;
+}
+
+.required th {
+    font-weight: bold;
+}

File myapp/myapp/templates/widget.mak

+<html>
+<%inherit file="local:templates.master"/>
+
+<%def name="title()">
+  TurboGears 2.1 and ToscaWidgets 2, like jelly and jam with no bread:  Great!
+</%def>
+
+<body>
+${widget.display()|n}
+</body>
+</html>