0

Good day everyone!

Is this possible in Web2py?

View Students First Year (populate from the database)

  • Section A (populate from the database)
  • Section B and so on
  • Section C

Second Year (populate from the database)

  • Section A and so on
  • Section B
  • Section C

and so on

now to the code

myDB.py

db.define_table('stud_info', 
            Field('firstname'),
            Field('lastname'))

db.define_table('section', 
            Field('section_name', requires=IS_NOT_EMPTY()))

db.define_table('yearstanding', 
            Field('year_level'),
            Field('section', 'reference section'))

menu.py

response.menu = [(T('Home'), False, URL('icthome', 'home'), []),]

def _():
# shortcuts
app = request.application
ctr = request.controller
# useful links to internal and external resources

for row in db(db.year_standing).select():
    response.menu += [
        ((T('View Students'), False, '#', [
                    ((T(row.year_level), False, '#', [
                                (T(row.section), False, URL('',''), [])]))
                ]))
    ]

and I got error:

Traceback (most recent call last): <br><br>
File "D:\Kuya Files\My Videos\Tutorial\Python\web2py_win\gluon\restricted.py", line 227, in restricted
    exec ccode in environment <br><br>
File "D:/Kuya Files/My Videos/Tutorial/Python/web2py_win/applications/ClearanceSystem/models/menu.py", line 168, in <module>
    if DEVELOPMENT_MENU: _() <br><br>
  File "D:/Kuya Files/My Videos/Tutorial/Python/web2py_win/applications/ClearanceSystem/models/menu.py", line 53, in _
    for row in db(db.year_standing).select():<br><br>
  File "D:\Kuya Files\My Videos\Tutorial\Python\web2py_win\gluon\packages\dal\pydal\base.py", line 906, in __getattr__
    return super(DAL, self).__getattr__(key)<br><br>
  File "D:\Kuya Files\My Videos\Tutorial\Python\web2py_win\gluon\packages\dal\pydal\helpers\classes.py", line 348, in __getattr__
    raise AttributeError<br><br>
AttributeError
doru
  • 9,022
  • 2
  • 33
  • 43
MeSH
  • 101
  • 1
  • 10

1 Answers1

0

Files in the top level of the /models folder are executed in alphabetical order, so your menu.py file is being executed before the db.year_standing table is defined in the myDB.py file. Just change the file names so the menu is created after the tables have been defined.

Also, it might be a good idea to cache this query in order to avoid hitting the database on every request.

Anthony
  • 25,466
  • 3
  • 28
  • 57
  • Good day I change myDB to db1. Still I got error. Based on my research in web2py the sub-sub-menu features are not implemented in bootstrap 3? here is the link [link](http://comments.gmane.org/gmane.comp.python.web2py/140468) so I decided that the menu will be like this: First Year - Section A, B, C, D Second Year - Section A, B, C and so on. The Year Level and Sections are in loop. Year Level is the outer loop and the Section is the nested loop. I saw on my instructor web2py project that the Movie Category (table in database) are the nav menu and he use `for row in db(db.category).select():`. – MeSH Aug 09 '15 at 00:33
  • (continuation) so how can I do that in loop with the section as the sub menu? – MeSH Aug 09 '15 at 00:42
  • Are you saying you got the *same* error, or now have a different problem? If the latter, then I believe the above is the answer to the question you originally asked, and you should now open a new question (or at least update the question to reflect your current code and issue). – Anthony Aug 09 '15 at 12:40