Skip to content

Commit b15c53d

Browse files
committed
nicer UI, alpha integration of topics menu into dropdown
1 parent 68267e5 commit b15c53d

17 files changed

+193
-119
lines changed

controllers/default.py

+6-2
Original file line numberDiff line numberDiff line change
@@ -26,5 +26,9 @@
2626
# return UL(menu)
2727

2828
def index():
29-
30-
return lessons_menu()
29+
response.title = "Pamokos"
30+
return dict(content=lessons_menu())
31+
32+
33+
def user():
34+
return dict(form=auth())

controllers/lesson0_py_intro.py

+5-2
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,10 @@
44
from plugin_introspect import tutor, menu
55

66

7-
def index( ):
8-
return menu()
7+
def index( ):
8+
response.view = 'default/index.html'
9+
response.title = "Temos"
10+
return dict(content=menu())
911

1012

1113
@tutor
@@ -169,3 +171,4 @@ def teksto_formatavimas_su_zodynais():
169171
age = 36
170172

171173
return "%(name)s turi %(age)s metus. %(name)s kartais vėluoja..." % locals()
174+

controllers/tutor.py

+16-12
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
# -*- coding: utf-8 -*-
22
from test_helper_4automation import *
3-
from gluon.admin import apath
43

54
def evaluate():
65

@@ -54,27 +53,32 @@ def evaluate():
5453
js_highlight_result.append( js_tpl_highlight % locals() )
5554
js_hints_result.append(js_tpl_hints % locals())
5655

57-
if evaluations.count('initial') == len(evaluations):
58-
js_hints_result.append( "alert('%s'); \n" % "Reik kažką pakeisti geltonuose laukeliuose... ;)")
5956

6057
if evaluations.count('ok') == len(evaluations):
6158
js_hints_result.append( "alert('%s'); \n" % "Puiku, gali judėti toliau!")
6259

60+
elif 'initial' in evaluations:
61+
# if evaluations.count('initial') == len(evaluations):
62+
js_hints_result.append( "alert('%s'); \n" % "Reik kažką pakeisti geltonose eilutėse... ;)")
63+
6364
if request.vars.change_placeholders: # ajax
6465
return ''.join( js_highlight_result +["\n"]+ js_hints_result )
6566

66-
return ""
6767

68-
# deprecated -- for debug purposes..
69-
if 'wrong' in evaluations:
70-
return CAT( P(B("Užuominos:")), XML(hints_result) )
7168

72-
if 'initial' in evaluations:
73-
return "kažką reikia pakeisti (geltonam fone)..."
69+
DBG = False
70+
if DBG:
71+
# deprecated -- for debug purposes..
72+
if 'wrong' in evaluations:
73+
return CAT( P(B("Užuominos:")), XML(hints_result) )
7474

75-
if not ( 'wrong' in evaluations and 'initial' in evaluations ) :
76-
return "<b>OK :)</b>"
77-
75+
if 'initial' in evaluations:
76+
return "kažką reikia pakeisti geltonose eilutėse)..."
77+
78+
if not ( 'wrong' in evaluations or 'initial' in evaluations ) :
79+
return "<b>OK :)</b>"
80+
81+
return ""
7882

7983

8084
# code = get_file_function_code( file, function )

databases/storage.sqlite

0 Bytes
Binary file not shown.

models/db.py

+2
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,7 @@
8787
auth = Auth(db, host_names=myconf.get('host.names'))
8888
service = Service()
8989
plugins = PluginManager()
90+
# auth.define_tables() ??
9091

9192
# -------------------------------------------------------------------------
9293
# create all tables needed by auth if not custom tables
@@ -109,6 +110,7 @@
109110
auth.settings.registration_requires_verification = False
110111
auth.settings.registration_requires_approval = False
111112
auth.settings.reset_password_requires_verification = True
113+
auth.settings.login_after_registration = True
112114

113115
# -------------------------------------------------------------------------
114116
# Define your tables below (or better in another model file) for example

models/menu.py

+29-32
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
# ----------------------------------------------------------------------------------------------------------------------
3030

3131
response.menu = [
32-
(T('Home'), False, URL('default', 'index'), [])
32+
# (T('Home'), False, URL('default', 'index'), [])
3333
]
3434

3535
DEVELOPMENT_MENU = True
@@ -39,6 +39,8 @@
3939
# provide shortcuts for development. remove in production
4040
# ----------------------------------------------------------------------------------------------------------------------
4141

42+
from plugin_introspect import lessons_menu, menu, exposed_functions_names, generate_exposed_functions_info, exposed_functions
43+
4244
def _():
4345
# ------------------------------------------------------------------------------------------------------------------
4446
# shortcuts
@@ -48,38 +50,33 @@ def _():
4850
# ------------------------------------------------------------------------------------------------------------------
4951
# useful links to internal and external resources
5052
# ------------------------------------------------------------------------------------------------------------------
53+
def current_lesson_topics():
54+
fun_names = exposed_functions_names()
55+
exposed_functions = generate_exposed_functions_info()
56+
57+
# hierarchical
58+
topics = menu(only_category=False,
59+
item_decorator=lambda item: ( T(item) , False, URL(item) ),
60+
# item_decorator=lambda item: ( T(item) + "*" * exposed_functions[item]['is_task'], False, URL(item) ),
61+
cat_decorator=lambda cat_name, items: (T(cat_name or ">"), False, items[0][2], items),
62+
plain_menu=True
63+
)
64+
from pprint import pprint
65+
pprint(str(topics), indent=4)
66+
# flat
67+
# topics = [
68+
# ( T(item) + "*" * exposed_functions[item]['is_task'], False, URL(item) )
69+
# for item in fun_names
70+
# ]
71+
72+
return topics
73+
# LI(_class="divider"),
74+
75+
topics = current_lesson_topics()
76+
5177
response.menu += [
52-
(T('My Sites'), False, URL('admin', 'default', 'site')),
53-
(T('This App'), False, '#', [
54-
(T('Design'), False, URL('admin', 'default', 'design/%s' % app)),
55-
LI(_class="divider"),
56-
(T('Controller'), False,
57-
URL(
58-
'admin', 'default', 'edit/%s/controllers/%s.py' % (app, ctr))),
59-
(T('View'), False,
60-
URL(
61-
'admin', 'default', 'edit/%s/views/%s' % (app, response.view))),
62-
(T('DB Model'), False,
63-
URL(
64-
'admin', 'default', 'edit/%s/models/db.py' % app)),
65-
(T('Menu Model'), False,
66-
URL(
67-
'admin', 'default', 'edit/%s/models/menu.py' % app)),
68-
(T('Config.ini'), False,
69-
URL(
70-
'admin', 'default', 'edit/%s/private/appconfig.ini' % app)),
71-
(T('Layout'), False,
72-
URL(
73-
'admin', 'default', 'edit/%s/views/layout.html' % app)),
74-
(T('Stylesheet'), False,
75-
URL(
76-
'admin', 'default', 'edit/%s/static/css/web2py-bootstrap3.css' % app)),
77-
(T('Database'), False, URL(app, 'appadmin', 'index')),
78-
(T('Errors'), False, URL(
79-
'admin', 'default', 'errors/' + app)),
80-
(T('About'), False, URL(
81-
'admin', 'default', 'about/' + app)),
82-
]),
78+
(T('Pamokos Temos'), False, '#', topics ),
79+
8380
('web2py.com', False, '#', [
8481
(T('Download'), False,
8582
'http://www.web2py.com/examples/default/download'),

modules/plugin_introspect.py

+27-13
Original file line numberDiff line numberDiff line change
@@ -97,25 +97,28 @@ def exposed_functions_names():
9797
data = open(fpath).read()
9898

9999
items = find_exposed_functions(data)
100-
100+
items = [i for i in items if i != 'index']
101101
return items
102102

103103

104104

105-
def menu( only_category = False ):
106-
"""gives links to all exposed functions except currently used"""
105+
def menu(only_category = False, item_decorator=None, cat_decorator=None, plain_menu=False):
106+
"""gives list with links to all exposed functions except currently used
107+
108+
optionally gives just current categorry
109+
"""
107110
fun_names = exposed_functions_names()
108111

109112
generate_exposed_functions_info()
110113
request = current.request
111114

112-
htmlized = [
113-
item if item==request.function
114-
else SPAN( A( item , _href=URL(item)), "*"*exposed_functions[item]['is_task'] )
115+
if item_decorator is None:
116+
item_decorator = lambda item: item if item == request.function else SPAN(A(item, _href=URL(item)), "*" * exposed_functions[item]['is_task'])
115117

116-
for item in fun_names
117-
if item != 'index'
118-
]
118+
if cat_decorator is None:
119+
cat_decorator = lambda cat_name, items: TOGGLABLE_CONTENT( cat_name, UL(items))
120+
121+
decorated = [item_decorator(item) for item in fun_names]
119122

120123
ctx = {'current_cat':None}
121124
def transform_to_tree():
@@ -124,9 +127,10 @@ def transform_to_tree():
124127
cat = []
125128
cat_name = ""
126129

127-
for name, html in zip( fun_names, htmlized):
130+
for name, html in zip( fun_names, decorated):
128131
if name.startswith('_'): # means category
129-
result .append ( TOGGLABLE_CONTENT( cat_name, UL(cat)) ) #
132+
result .append ( cat_decorator( cat_name, cat ) ) #
133+
# result .append ( TOGGLABLE_CONTENT( cat_name, UL(cat)) ) #
130134
cat_name = name.replace("_", " ").title()
131135
cat = [ ]
132136

@@ -135,14 +139,24 @@ def transform_to_tree():
135139

136140
cat.append( html )
137141

138-
result.append(TOGGLABLE_CONTENT(cat_name, UL(cat))) # last category
142+
result.append(cat_decorator(cat_name, cat)) # last category
143+
# result.append(TOGGLABLE_CONTENT(cat_name, UL(cat))) # last category
139144

140145
return result
141146

142147
if only_category:
148+
current_category = transform_to_tree()
149+
return current_category
150+
151+
if plain_menu:
143152
return transform_to_tree()
144153

145-
return UL( transform_to_tree() )
154+
if current.request.function in [ 'index', 'menu' ]:
155+
lesson_name = request.controller[len("lesson"):]
156+
lesson_name = " ".join(lesson_name.split("_")[1:]).title()
157+
return CAT(H3(lesson_name), UL( transform_to_tree() ))
158+
159+
return UL( transform_to_tree() )
146160
# return UL( htmlized )
147161

148162

modules/test_helper_4automation.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ def map_pyquotes_to_double( t ):
147147
a = Counter( a_tokens )
148148
b = Counter( b_tokens )
149149
if a == b:
150-
msgs =[ "Ordering is incorrect" ]
150+
msgs =[ "Kažką reiktų sukeisti vietomis..." ]
151151
# todo: tell what is not ir right place
152152

153153
else:
@@ -205,9 +205,9 @@ def messages_by_fragments(placeholder, result=None, unnecessary=[], required=[])
205205
msgs.append("")
206206

207207
for item in required:
208-
msg = "tikimasi daugiau %s"
208+
msg = "Tikimasi daugiau %s"
209209
if not item in placeholder:
210-
msg = "tikimasi %s"
210+
msg = "Tikimasi %s"
211211
# msgs .append( code_highlight(item) + " is expected " )
212212
msgs .append( msg % code_highlight(item) )
213213

private/appconfig.ini

+2-2
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,12 @@ pool_size = 10 ; ignored for sqlite
1919
; smtp address and credentials
2020
[smtp]
2121
server = smtp.gmail.com:587
22-
sender = you@gmail.com
22+
sender = jurgis.bot@gmail.com
2323
login = username:password
2424
tls = true
2525
ssl = true
2626

2727
; form styling
2828
[forms]
2929
formstyle = bootstrap3_inline
30-
separator =
30+
separator =

progress.log

+1
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
[2017-05-19 09:41:11] START
22
[2017-05-19 09:42:55] CREATE lesson1.py: 0
3+
[2017-06-04 08:11:41] EDIT tutor/private/appconfig.ini: 0

static/js/colResizable.min.js

+3
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

views/codemirror.html

+2
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,7 @@
8484
</script>
8585

8686
<form action="{{=URL('tutor', 'evaluate')}}" method="POST">
87+
<div class="code-input">
8788
{{ placeholder_nr = 0 }}
8889
{{ for nr, code in enumerate(codes):}}
8990
{{ extra = {};
@@ -96,6 +97,7 @@
9697
}}
9798
{{ =TEXTAREA( code, _rows=code.count('\n'), _cols=50, _id="code_%s"%nr, **extra) }}
9899
{{ pass }}
100+
</div>
99101

100102
{{=INPUT(_type="hidden", _name="task_key", _value=task_key)}}
101103

views/default/index.html

+10-34
Original file line numberDiff line numberDiff line change
@@ -2,51 +2,27 @@
22
{{extend 'layout.html'}}
33

44
{{block header}}
5-
<header class="container-fluid background">
6-
<div class="jumbotron text-center">
5+
<div class="text-center">
76
{{if response.title:}}
87
<h1>{{=response.title}}
98
<small>{{=response.subtitle or ''}}</small></h1>
109
{{pass}}
1110
</div>
12-
</header>
1311
{{end}}
1412

15-
{{if 'message' in globals():}}
16-
<h2>{{=message}}</h2>
17-
<p class="lead">{{=T('How did you get here?')}}</p>
18-
<ol>
19-
<li>{{=T('You are successfully running web2py')}}</li>
20-
<li>{{=XML(T('You visited the url %s', A(request.env.path_info,_href=request.env.path_info)))}}</li>
21-
<li>{{=XML(T('Which called the function %s located in the file %s',
22-
(A(request.function+'()',_href='#'),
23-
A('web2py/applications/%(application)s/controllers/%(controller)s.py' % request,
24-
_href=URL('admin','default','peek', args=(request.application,'controllers',request.controller+'.py'))))))}}</li>
25-
<li>{{=XML(T('The output of the file is a dictionary that was rendered by the view %s',
26-
A('web2py/applications/%(application)s/views/%(controller)s/index.html' % request,
27-
_href=URL('admin','default','peek',args=(request.application,'views',request.controller,'index.html')))))}}</li>
28-
<li>{{=T('You can modify this application and adapt it to your needs')}}</li>
29-
</ol>
30-
{{elif 'content' in globals():}}
13+
14+
15+
{{#if 'content' in response._vars:}}
16+
{{if 'content' in globals():}}
3117
{{=content}}
3218
{{else:}}
3319
{{=BEAUTIFY(response._vars)}}
3420
{{pass}}
3521

3622
{{block right_sidebar}}
37-
<div class="panel panel-info">
38-
<div class="panel-heading"><h3 class="panel-title"><a class="btn-block"
39-
href="{{=URL('admin','default','index')}}">
40-
<i class="glyphicon glyphicon-cog"></i>
41-
{{=T("admin")}}
42-
</a></h3></div>
43-
<div class="panel-body">
44-
{{=T("Don't know what to do?")}}
45-
</div>
46-
<ul class="list-group">
47-
<li class="list-group-item">{{=A(T("Online examples"), _href=URL('examples','default','index'))}}</li>
48-
<li class="list-group-item"><a href="http://web2py.com">web2py.com</a></li>
49-
<li class="list-group-item"><a href="http://web2py.com/book">{{=T('Documentation')}}</a></li>
50-
</ul>
51-
</div>
23+
<div class="panel panel-info">
24+
{{if 'message' in globals():}}
25+
<h2>{{=message}}</h2>
26+
{{pass}}
27+
</div>
5228
{{end}}

views/default/user.html

+6
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
{{extend 'layout.html'}}
22

3+
{{if auth.user_id is None:}}
4+
35
<h2>
46
{{=T('Sign Up') if request.args(0) == 'register' else T('Log In') if request.args(0) == 'login' else T(request.args(0).replace('_',' ').title())}}
57
</h2>
@@ -33,3 +35,7 @@ <h2>
3335
{{pass}}
3436
</script>
3537
{{end page_js}}
38+
39+
{{else:}}
40+
{{ =auth.user.email }}
41+
{{pass}}

0 commit comments

Comments
 (0)