Andriy Kornatskyy avatar Andriy Kornatskyy committed c41b5f7

Added widgets demo page

Comments (0)

Files changed (7)

demos/public/content/static/css/site.css

 
 .clear { clear: both; }
 input[type="text"], input[type="password"], textarea { border: 1px solid #BBB; border-radius: 3px; }
-code { padding: 10px; text-align: left; display: block; overflow: auto; background: #fafafa; border: 1px solid #f2f2f2; border-left: 3px solid #5c87b2; }
-code { font: 500 1em/1.5em 'Lucida Console' , 'courier new' , monospace; }
+code, pre { padding: 10px; text-align: left; display: block; overflow: auto; background: #fafafa; border: 1px solid #f2f2f2; border-left: 3px solid #5c87b2; }
+code, pre { font: 500 1em/1.5em Consolas, monospace; }
 
 input.error, textarea.error, select.error { border: 1px solid #FF0000; background-color: #FFEEEE; }
 span.error { color: #FF0000; }

demos/public/content/templates/public/about.html

     protected by <i>@authorize(roles=['business'])</i> decorator
     and accessable for business accounts only.
     </p>
+    <p>Take a look at <a href="${path_for('widgets')}">widgets</a>
+    available.</a>
 </div>

demos/public/content/templates/public/widgets.html

+<%inherit file="/shared/master.html"/>
+<%block name="title">Widgets</%block>
+<div id="widgets">
+    <h2>Widgets!</h2>
+    <p>
+    This is demostration page of
+    <a href="http://pypi.python.org/pypi/wheezy.html">wheezy.html</a>
+    widgets.
+    Please note that
+    <a href="http://docs.makotemplates.org/en/latest/filtering.html#expression-filtering">expression filtering</a>
+    works in case
+    <a href="http://packages.python.org/wheezy.html/userguide.html#mako">widget_preprocessor</a>
+    is enabled.
+    </p>
+    % if errors:
+    Click <a href="${path_for('widgets')}">here</a> to hide errors.
+    You are looking at <b>widgets with error reported</b>.
+    % else:
+    Click <a href="${path_for('widgets-with-errors')}">here</a> to see how widget looks with errors.
+    You are looking at <b>widgets with no error</b> reported.
+    % endif
+
+    <h3>hidden</h3>
+    <p>
+<pre><%text filter="h">
+##${model.pref.hidden()}
+</%text><%block filter="h">
+${model.pref.hidden()}
+</%block></pre>
+    </p>
+
+    <h3>multiple_hidden</h3>
+    <p>
+<pre><%text filter="h">
+##${model.pref.multiple_hidden()}
+</%text><%block filter="h">
+${model.prefs.multiple_hidden()}
+</%block></pre>
+    </p>
+
+    <h3>label</h3>
+    <p>
+<pre><%text filter="h">
+##${model.username.label('Username')}
+##${model.username.label('<i>*</i>Username', class_="inline")}
+</%text><%block filter="h">
+${model.username.label('Username')}
+${model.username.label('<i>*</i>Username', class_="inline")}
+</%block></pre>
+    </p>
+
+    <h3>textbox, password and checkbox</h3>
+    <p>
+<pre><%text filter="h">
+##${model.username.textbox(autocomplete='off')}
+##${model.password.password(maxlength=10)}
+##${model.remember_me.checkbox()}
+</%text><%block filter="h">
+${model.username.textbox(autocomplete='off')}
+${model.password.password(maxlength=10)}
+${model.remember_me.checkbox()}
+</%block></pre>
+    </p>
+
+    <h3>multiple_checkbox</h3>
+    <p>
+<pre><%text filter="h">
+##${model.scm.multiple_checkbox(choices=scm)}
+</%text><%block filter="h">
+${model.scm.multiple_checkbox(choices=scm)}
+</%block></pre>
+    </p>
+
+    <h3>textarea</h3>
+    <p>
+<pre><%text filter="h">
+##${model.notes.textarea()}
+##${model.notes.textarea(rows=10)}
+</%text><%block filter="h">
+${model.notes.textarea()}
+${model.notes.textarea(rows=10)}
+</%block></pre>
+    </p>
+
+    <h3>radio</h3>
+    <p>
+<pre><%text filter="h">
+##${model.scm.radio(choices=scm)}
+</%text><%block filter="h">
+${model.scm.radio(choices=scm)}
+</%block></pre>
+
+    <h3>dropdown (select), listbox (multiple_select)</h3>
+    <p>
+<pre><%text filter="h">
+##${model.scm.dropdown(choices=scm)}
+##${model.scms.listbox(choices=scm)}
+</%text><%block filter="h">
+${model.scm.dropdown(choices=scm)}
+${model.scms.listbox(choices=scm)}
+</%block></pre>
+
+    <h3>info, warning and error</h3>
+    <p>
+<pre><%text filter="h">
+##${message.info()}
+##${message.warning()}
+##${model.error()}
+##${model.username.error()}
+##${model.password_status.warning()}
+##${model.username_status.info()}
+##${model.username_status.warning()}
+</%text><%block filter="h">
+${message.info()}
+
+${message.warning()}
+
+${model.error()}
+
+${model.username.error()}
+
+${model.password_status.warning()}
+
+${model.username_status.info()}
+
+${model.username_status.warning()}
+</%block></pre>
+    </p>
+</div>

demos/public/src/public/web/tests/benchmark_views.py

         p = Benchmark((
             self.test_home,
             self.test_about,
+            self.test_widgets,
+            self.test_widgets_with_errors,
             self.test_static_files,
             self.test_static_file_not_found,
             self.test_static_file_forbidden,
             ), 1000)
         p.report('public', baselines={
                 'test_home': 1.0,
-                'test_about': 0.926,
+                'test_about': 0.89,
+                'test_widgets': 0.52,
+                'test_widgets_with_errors': 0.51,
                 'test_static_files': 1.655,
                 'test_static_file_not_found': 0.64,
                 'test_static_file_forbidden': 0.62,

demos/public/src/public/web/tests/test_views.py

         assert 200 == self.client.get('/en/about')
         assert '- About</title>' in self.client.content
 
+    def test_widgets(self):
+        """ Ensure widgets page is rendered.
+        """
+        assert 200 == self.client.get('/en/widgets')
+        assert '- Widgets</title>' in self.client.content
+        assert 'no error</b>' in self.client.content
+
+    def test_widgets_with_errors(self):
+        """ Ensure widgets-with-errors page is rendered.
+        """
+        assert 200 == self.client.get('/en/widgets-with-errors')
+        assert '- Widgets</title>' in self.client.content
+        assert 'error reported</b>' in self.client.content
+
     def test_static_files(self):
         """ Ensure static content is served.
         """

demos/public/src/public/web/urls.py

 """
 
 from wheezy.routing import url
-from wheezy.web.handlers import template_handler
 
 from public.web.views import about
 from public.web.views import home
+from public.web.views import WidgetsHandler
 
 
 public_urls = [
     url('home', home, name='home'),
     url('about', about, name='about'),
+    url('widgets-with-errors', WidgetsHandler,
+        kwargs={'mode': 'errors'}, name='widgets-with-errors'),
+    url('widgets', WidgetsHandler,
+        kwargs={'mode': 'no-errors'}, name='widgets'),
 ]

demos/public/src/public/web/views.py

 """
 """
 
+from wheezy.core.collections import attrdict
+from wheezy.core.descriptors import attribute
+from wheezy.web.handlers import BaseHandler
 from wheezy.web.handlers import template_handler
 
 
 home = template_handler('public/home.html')
 about = template_handler('public/about.html')
+
+
+class WidgetsHandler(BaseHandler):
+
+    @attribute
+    def model(self):
+        return attrdict({
+            'username': 'John Smith',
+            'username_status': 'Taken!',
+            'password': '',
+            'password_status': '',
+            'notes': 'Lorem ipsum dolor sit amet.',
+            'pref': 'abc',
+            'prefs': ['ab', 'c'],
+            'remember_me': True,
+            'scm': 'hg',
+            'scms': ['git', 'hg']
+            })
+
+    @attribute
+    def translation(self):
+        return self.translations['membership']
+
+    def get(self):
+        if 'errors' == self.route_args.mode:
+            self.error('Error Message')
+            for k in self.model.keys():
+                self.errors[k] = ['Error Message A', 'Error Message B']
+        return self.render_response('public/widgets.html',
+                        model=self.model,
+                        message='Your changes have been saved.',
+                        scm=[('git', 'Git'),
+                            ('hg', 'Mercurial'),
+                            ('svn', 'SVN')])
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.