[Hejes-devel] [851] new features in ekwiki app: toc with ajax, rule keys in db

hejes-devel at nytud.hu hejes-devel at nytud.hu
Wed Jul 17 15:55:20 CEST 2013


Revision: 851
Author:   mihaltz
Date:     2013-07-17 15:55:20 +0200 (Wed, 17 Jul 2013)
Log Message:
-----------
new features in ekwiki app: toc with ajax, rule keys in db

Modified Paths:
--------------
    trunk/misc/dbekwiki/create_grmrule_pages.py
    trunk/web2py/applications/ekwiki/controllers/default.py
    trunk/web2py/applications/ekwiki/databases/c8b669d15150d7109e5f7ab36744a5b7_wiki_page.table
    trunk/web2py/applications/ekwiki/databases/sql.log
    trunk/web2py/applications/ekwiki/databases/storage.sqlite
    trunk/web2py/applications/ekwiki/models/db.py
    trunk/web2py/applications/ekwiki/progress.log

Added Paths:
-----------
    trunk/web2py/applications/ekwiki/views/default/toc.html

Modified: trunk/misc/dbekwiki/create_grmrule_pages.py
===================================================================
--- trunk/misc/dbekwiki/create_grmrule_pages.py	2013-07-12 21:09:18 UTC (rev 850)
+++ trunk/misc/dbekwiki/create_grmrule_pages.py	2013-07-17 13:55:20 UTC (rev 851)
@@ -22,7 +22,9 @@
 sys.stderr.write('Done\n')
 
 # Test
-#print( db.executesql('select title from wiki_page'))
+#print( db.executesql('select * from wiki_page limit 1'))
+#print( db.executesql('select * from wiki_page where title not like "#RULE# %";'))
+#sys.exit()
 
 # Load grammar
 parser = GrammarParser()
@@ -31,14 +33,19 @@
 sys.stderr.write('{0} line(s) read\n'.format(parser.lcnt))
 sys.stderr.write('{0} rule(s) parsed\n'.format(len(parser.rules)))
 
+# Delete rule pages from table wiki-page
+r = db.executesql('DELETE FROM wiki_page WHERE title LIKE "#RULE# %";')
+
 # Generate pages
+#TODO: add rulestr
 for rule in rules:
   print(rule.id)
-  # all columns: (id, slug, title, body, tags, can_read, can_edit, changelog, html, is_active, created_on, created_by, modified_on, modified_by)
+  rkey = ' + '.join([x[0] for x in rule.lhs])
+  # all columns: (id, rulestr, rulekey, slug, title, body, tags, can_read, can_edit, changelog, html, is_active, created_on, created_by, modified_on, modified_by)
   sql = """INSERT OR IGNORE INTO wiki_page 
-    (slug, title, body, tags, can_read, can_edit, html, is_active, created_on, created_by)
-    VALUES ('{0}', '#Rule# {1}', '#Rule {1}\n\nTODO', '||', '|everybody|', '|everybody|', '<h1>Rule {1}</h1><p>TODO</p><div class="w2p_wiki_tags"></div>', 'T', '{2}', 1);
-    """.format(rule.id, rule.id, '2013-07-11 19:00:00')
+    (slug, title, body, tags, can_read, can_edit, html, is_active, created_on, created_by, rulekey)
+    VALUES ('{0}', '#Rule# {1}', '#Rule {1}\n\nTODO', '||', '|everybody|', '|everybody|', '<h1>Rule {1}</h1><p>TODO</p><div class="w2p_wiki_tags"></div>', 'T', '{2}', 1, '{3}');
+    """.format(rule.id.replace(':','-'), rule.id, '2013-07-17 12:00:00', rkey)
   r = db.executesql(sql)
   if r != []:
     print(r)

Modified: trunk/web2py/applications/ekwiki/controllers/default.py
===================================================================
--- trunk/web2py/applications/ekwiki/controllers/default.py	2013-07-12 21:09:18 UTC (rev 850)
+++ trunk/web2py/applications/ekwiki/controllers/default.py	2013-07-17 13:55:20 UTC (rev 851)
@@ -9,6 +9,8 @@
 ## - call exposes all registered services (none by default)
 #########################################################################
 
+from gluon.tools import fetch
+
 @auth.requires_login()
 def index():
     """
@@ -23,6 +25,35 @@
     """
     return auth.wiki()    
 
+def toc():
+    """
+    Generate data for Table of Contents for the Wiki
+    Return following items in a dictionary:
+    otherpages: array of tuples, records from table wiki_page, other pages
+    termpages: array of tuples, records from table wiki_page, terminology pages (not rules or other)
+    rulepages: array of tuples, records from table wiki_page, grammar rule pages
+    TODO: require authorization (adding @auth.requires_login() breaks it!!!)
+    """
+    op, tp, rp = [], [], []
+    pages = dbekwiki.executesql('SELECT * FROM wiki_page')
+    for row in pages:
+        if row[1] in [u'index', u'toc', u'wiki-menu']:
+            op.append(row)
+        elif row[2].startswith(u'#Rule# '):
+            rp.append(row)
+        else:
+            tp.append(row)
+    return dict(otherpages = op, termpages = tp, rulepages = rp)
+
+def toc_comp():
+    """
+    This is a "component" to be embedded (inside a wiki page) via Ajax
+    Returns an XML helper that contains the HTML source of the toc page
+    """
+    return XML(fetch(URL(f='toc', host=True)))
+
+# ----------------------------------------------------------------------
+
 def user():
     """
     exposes:

Modified: trunk/web2py/applications/ekwiki/databases/c8b669d15150d7109e5f7ab36744a5b7_wiki_page.table
===================================================================
--- trunk/web2py/applications/ekwiki/databases/c8b669d15150d7109e5f7ab36744a5b7_wiki_page.table	2013-07-12 21:09:18 UTC (rev  850)
+++ trunk/web2py/applications/ekwiki/databases/c8b669d15150d7109e5f7ab36744a5b7_wiki_page.table	2013-07-17 13:55:20 UTC (rev 851)
@@ -10,7 +10,7 @@
 I00
 sS'sortable'
 p6
-I4
+I6
 sS'sql'
 p7
 S'TEXT NOT NULL'
@@ -30,7 +30,7 @@
 sg5
 I00
 sg6
-I7
+I9
 sg7
 S'TEXT'
 p14
@@ -47,7 +47,7 @@
 sg5
 I00
 sg6
-I14
+I16
 sg7
 S'INTEGER REFERENCES auth_user (id) ON DELETE CASCADE'
 p18
@@ -64,7 +64,7 @@
 sg5
 I01
 sg6
-I3
+I5
 sg7
 S'CHAR(512) UNIQUE'
 p22
@@ -73,23 +73,23 @@
 sg10
 S'string'
 p23
-ssS'tags'
+ssS'rulestr'
 p24
 (dp25
 g4
-I512
+I32768
 sg5
 I00
 sg6
-I5
+I2
 sg7
 S'TEXT'
 p26
 sg9
 I00
 sg10
-g15
-ssS'is_active'
+g11
+ssS'tags'
 p27
 (dp28
 g4
@@ -97,32 +97,32 @@
 sg5
 I00
 sg6
-I10
+I7
 sg7
-S'CHAR(1)'
+S'TEXT'
 p29
 sg9
 I00
 sg10
-S'boolean'
+g15
+ssS'is_active'
 p30
-ssS'changelog'
-p31
-(dp32
+(dp31
 g4
 I512
 sg5
 I00
 sg6
-I8
+I12
 sg7
-S'CHAR(512)'
-p33
+S'CHAR(1)'
+p32
 sg9
 I00
 sg10
-g23
-ssS'created_by'
+S'boolean'
+p33
+ssS'changelog'
 p34
 (dp35
 g4
@@ -130,15 +130,15 @@
 sg5
 I00
 sg6
-I12
+I10
 sg7
-S'INTEGER REFERENCES auth_user (id) ON DELETE CASCADE'
+S'CHAR(512)'
 p36
 sg9
 I00
 sg10
-g19
-ssS'slug'
+g23
+ssS'created_by'
 p37
 (dp38
 g4
@@ -146,15 +146,15 @@
 sg5
 I00
 sg6
-I2
+I14
 sg7
-S'CHAR(512)'
+S'INTEGER REFERENCES auth_user (id) ON DELETE CASCADE'
 p39
 sg9
 I00
 sg10
-g23
-ssS'can_read'
+g19
+ssS'id'
 p40
 (dp41
 g4
@@ -162,48 +162,48 @@
 sg5
 I00
 sg6
-I6
+I1
 sg7
-S'TEXT'
+S'INTEGER PRIMARY KEY AUTOINCREMENT'
 p42
 sg9
 I00
 sg10
-g15
-ssS'created_on'
+S'id'
 p43
-(dp44
+ssS'rulekey'
+p44
+(dp45
 g4
-I512
+I32768
 sg5
 I00
 sg6
-I11
+I3
 sg7
-S'TIMESTAMP'
-p45
+S'TEXT'
+p46
 sg9
 I00
 sg10
-S'datetime'
-p46
-ssS'html'
+g11
+ssS'can_read'
 p47
 (dp48
 g4
-I32768
+I512
 sg5
 I00
 sg6
-I9
+I8
 sg7
 S'TEXT'
 p49
 sg9
 I00
 sg10
-g11
-ssS'modified_on'
+g15
+ssS'created_on'
 p50
 (dp51
 g4
@@ -218,21 +218,54 @@
 sg9
 I00
 sg10
-g46
-ssS'id'
+S'datetime'
 p53
-(dp54
+ssS'html'
+p54
+(dp55
 g4
+I32768
+sg5
+I00
+sg6
+I11
+sg7
+S'TEXT'
+p56
+sg9
+I00
+sg10
+g11
+ssS'modified_on'
+p57
+(dp58
+g4
 I512
 sg5
 I00
 sg6
-I1
+I15
 sg7
-S'INTEGER PRIMARY KEY AUTOINCREMENT'
-p55
+S'TIMESTAMP'
+p59
 sg9
 I00
 sg10
 g53
+ssS'slug'
+p60
+(dp61
+g4
+I512
+sg5
+I00
+sg6
+I4
+sg7
+S'CHAR(512)'
+p62
+sg9
+I00
+sg10
+g23
 ss.
\ No newline at end of file

Modified: trunk/web2py/applications/ekwiki/databases/sql.log
===================================================================
--- trunk/web2py/applications/ekwiki/databases/sql.log	2013-07-12 21:09:18 UTC (rev 850)
+++ trunk/web2py/applications/ekwiki/databases/sql.log	2013-07-17 13:55:20 UTC (rev 851)
@@ -96,3 +96,7 @@
     modified_by INTEGER REFERENCES auth_user (id) ON DELETE CASCADE
 );
 success!
+timestamp: 2013-07-17T15:44:37.540730
+ALTER TABLE wiki_page ADD rulestr TEXT;
+timestamp: 2013-07-17T15:44:37.618520
+ALTER TABLE wiki_page ADD rulekey TEXT;

Modified: trunk/web2py/applications/ekwiki/databases/storage.sqlite
===================================================================
(Binary files differ)

Modified: trunk/web2py/applications/ekwiki/models/db.py
===================================================================
--- trunk/web2py/applications/ekwiki/models/db.py	2013-07-12 21:09:18 UTC (rev 850)
+++ trunk/web2py/applications/ekwiki/models/db.py	2013-07-17 13:55:20 UTC (rev 851)
@@ -84,8 +84,13 @@
 ## after defining tables, uncomment below to enable auditing
 # auth.enable_record_versioning(db)
 
+# Added by MM:
 
-# Make sure this is called after the auth instance is created
-# and before any change to the wiki tables
+# Add custom fields to the wiki pages
+auth.settings.extra_fields["wiki_page"] = [Field("rulestr", "text"), Field("rulekey", "text")]
+
 # See http://www.web2py.com/books/default/chapter/29/03#Extending-the-auth.wiki-feature
 auth.wiki(resolve=False)
+
+# DB connection object
+dbekwiki = DAL('sqlite://storage.sqlite')

Modified: trunk/web2py/applications/ekwiki/progress.log
===================================================================
--- trunk/web2py/applications/ekwiki/progress.log	2013-07-12 21:09:18 UTC (rev 850)
+++ trunk/web2py/applications/ekwiki/progress.log	2013-07-17 13:55:20 UTC (rev 851)
@@ -24,3 +24,62 @@
 [2013-07-11 19:20:41] EDIT ekwiki/controllers/default.py: 0
 [2013-07-11 19:20:43] EDIT ekwiki/controllers/default.py: 0
 [2013-07-11 19:21:01] EDIT ekwiki/controllers/default.py: 0
+[2013-07-11 20:32:33] EDIT ekwiki/controllers/default.py: 11
+[2013-07-11 20:35:51] EDIT ekwiki/controllers/default.py: 2
+[2013-07-11 20:38:58] CREATE default/toc.html: 0
+[2013-07-11 20:39:07] EDIT ekwiki/views/default/toc.html: -1
+[2013-07-11 20:41:28] EDIT ekwiki/models/db.py: 1
+[2013-07-11 20:43:15] EDIT ekwiki/controllers/default.py: 0
+[2013-07-11 20:43:43] EDIT ekwiki/controllers/default.py: 0
+[2013-07-11 20:43:44] EDIT ekwiki/controllers/default.py: 0
+[2013-07-11 21:26:02] EDIT ekwiki/controllers/default.py: 0
+[2013-07-11 21:29:35] EDIT ekwiki/views/default/toc.html: 5
+[2013-07-11 21:31:52] EDIT ekwiki/views/default/toc.html: 0
+[2013-07-11 21:32:26] EDIT ekwiki/views/default/toc.html: 1
+[2013-07-11 21:32:36] EDIT ekwiki/views/default/toc.html: 0
+[2013-07-11 21:33:01] EDIT ekwiki/views/default/toc.html: 0
+[2013-07-11 21:35:09] EDIT ekwiki/views/default/toc.html: 0
+[2013-07-11 21:36:12] EDIT ekwiki/views/default/toc.html: 0
+[2013-07-11 21:36:46] EDIT ekwiki/views/default/toc.html: 6
+[2013-07-11 21:38:10] EDIT ekwiki/views/default/toc.html: 1
+[2013-07-11 21:41:38] EDIT ekwiki/views/default/toc.html: 0
+[2013-07-11 21:49:48] EDIT ekwiki/controllers/default.py: 8
+[2013-07-11 21:49:49] EDIT ekwiki/controllers/default.py: 0
+[2013-07-11 21:57:11] EDIT ekwiki/controllers/default.py: 2
+[2013-07-11 21:57:13] EDIT ekwiki/controllers/default.py: 0
+[2013-07-11 21:58:10] EDIT ekwiki/controllers/default.py: 0
+[2013-07-11 21:59:02] EDIT ekwiki/views/default/toc.html: 0
+[2013-07-11 22:06:58] EDIT ekwiki/controllers/default.py: 1
+[2013-07-11 22:08:35] EDIT ekwiki/controllers/default.py: 1
+[2013-07-11 22:10:35] EDIT ekwiki/controllers/default.py: 0
+[2013-07-11 22:11:13] EDIT ekwiki/controllers/default.py: -1
+[2013-07-11 22:11:28] EDIT ekwiki/controllers/default.py: 0
+[2013-07-11 22:11:33] EDIT ekwiki/controllers/default.py: 0
+[2013-07-11 22:12:20] EDIT ekwiki/controllers/default.py: -1
+[2013-07-17 15:06:32] EDIT ekwiki/controllers/default.py: -2
+[2013-07-17 15:06:59] EDIT ekwiki/views/default/toc.html: 0
+[2013-07-17 15:09:15] EDIT ekwiki/controllers/default.py: 8
+[2013-07-17 15:09:32] EDIT ekwiki/controllers/default.py: 0
+[2013-07-17 15:10:12] EDIT ekwiki/controllers/default.py: 0
+[2013-07-17 15:10:19] EDIT ekwiki/controllers/default.py: 0
+[2013-07-17 15:11:41] EDIT ekwiki/views/default/toc.html: 6
+[2013-07-17 15:11:56] EDIT ekwiki/views/default/toc.html: -1
+[2013-07-17 15:11:58] EDIT ekwiki/views/default/toc.html: 0
+[2013-07-17 15:15:45] EDIT ekwiki/controllers/default.py: 2
+[2013-07-17 15:15:47] EDIT ekwiki/controllers/default.py: 0
+[2013-07-17 15:16:13] EDIT ekwiki/controllers/default.py: -2
+[2013-07-17 15:16:41] EDIT ekwiki/views/default/toc.html: 0
+[2013-07-17 15:17:26] EDIT ekwiki/controllers/default.py: 0
+[2013-07-17 15:17:37] EDIT ekwiki/controllers/default.py: 0
+[2013-07-17 15:18:12] EDIT ekwiki/controllers/default.py: -4
+[2013-07-17 15:18:22] EDIT ekwiki/controllers/default.py: 0
+[2013-07-17 15:18:34] EDIT ekwiki/controllers/default.py: 0
+[2013-07-17 15:19:30] EDIT ekwiki/controllers/default.py: 1
+[2013-07-17 15:20:12] EDIT ekwiki/controllers/default.py: -1
+[2013-07-17 15:20:27] EDIT ekwiki/controllers/default.py: 1
+[2013-07-17 15:20:49] EDIT ekwiki/controllers/default.py: -1
+[2013-07-17 15:21:21] EDIT ekwiki/controllers/default.py: -1
+[2013-07-17 15:21:35] EDIT ekwiki/controllers/default.py: 1
+[2013-07-17 15:23:01] EDIT ekwiki/controllers/default.py: 1
+[2013-07-17 15:38:27] EDIT ekwiki/models/db.py: 1
+[2013-07-17 15:44:08] EDIT ekwiki/models/db.py: 0

Added: trunk/web2py/applications/ekwiki/views/default/toc.html
===================================================================
--- trunk/web2py/applications/ekwiki/views/default/toc.html	                        (rev 0)
+++ trunk/web2py/applications/ekwiki/views/default/toc.html	2013-07-17 13:55:20 UTC (rev 851)
@@ -0,0 +1,24 @@
+<h1>Tartalom</h1>
+
+<p>Szócikkek oldalai:</p>
+<ul>
+    {{for row in termpages:}}
+    	<li>{{=A(row[2], _href=URL(f='wiki', args=row[1]))}}</li>
+    {{pass}}
+</ul>
+
+<p>Szabályok oldalai (grm fájlbeli sorrendben):</p>
+<ul>
+    {{for row in rulepages:}}
+    	<li>{{=A(row[2], _href=URL(f='wiki', args=row[1]))}}</li>
+    {{pass}}
+</ul>
+
+<p>Egyéb oldalak:</p>
+<ul>
+    {{for row in otherpages:}}
+    	<li>{{=A(row[2], _href=URL(f='wiki', args=row[1]))}}</li>
+    {{pass}}
+</ul>
+
+{{#=BEAUTIFY(response._vars)}}




More information about the Hejes-devel mailing list