Annet | 24 May 09:13

drop down menu {{if 'session.%sDropdown' %_name:}}

In a function I set up the following menu:

def menu():
    session.site_menu=[
    ['Home',request.controller=='site' and request.function=='index',URL('site','index',args=session.id)]]
    if session.wh:
        session.site_menu.append(['Over ons',request.controller=='whQ',URL('whQ','index',args=session.id)])
    if session.cal:
        session.site_menu.append(['Agenda',request.controller=='calendar',URL('calendar','index',args=session.id)])
        session.AgendaDropdown=[]
        if session.cal.opening_hours:
            session.AgendaDropdown.append(['Openingstijden',request.function=='openingHours',\
            URL('calendar','openingHours',args=session.id)])
        if session.cal.event_list:
            session.AgendaDropdown.append(['Event list',request.function=='eventList',\
            URL('calendar','eventList',args=session.id)])
        if session.cal.timetable:
            session.AgendaDropdown.append(['Lesrooster',request.function=='timetable',\
            URL('calendar','timetable',args=session.id)])
        if session.cal.course_table:
            session.AgendaDropdown.append(['Cursusrooster',request.function=='courseTable',\
            URL('calendar','courseTable',args=session.id)])
    return None

In a menu view I am trying to get this to work:

<ul class="nav">
    {{for _name,_active,_link in session.site_menu:}}
      {{if 'session.%sDropdown' %_name:}}
        <li class="dropdown" {{if _active:}} class="active" {{pass}}>
          <a href="" class="dropdown-toggle" data-toggle="dropdown">{{=_name}}
          <b class="caret"></b></a>
          <ul class="dropdown-menu">
          {{for _name,_active,_link in 'session.%sDropdown' %_name:}}
            <li {{if _active:}} class="active" {{pass}}>
              <a href="{{=_link}}">{{=_name}}</a>
             </li>
          {{pass}}
          <ul>
        </li>
      {{else:}}
        <li {{if _active:}} class="active" {{pass}}>
          <a href="{{=_link}}">{{=_name}}</a>
        </li>
      {{pass}}
    {{pass}}
  </ul>

The problem is that this doesn't work:

{{if 'session.%sdropdown' %_name:}}

It should be rendered into:

{{if session.AgendaDropdown:}}

What is the correct syntax to get this to work.


Kind regards,

Annet

Jason Brower | 24 May 07:35
Picon
Gravatar

SQL syntax error when trying to create db...

I get this:

File "/home/jason/Desktop/InterestID_4/Development_Environment/gluon/dal.py", line 1386, in log_execute ret = self.cursor.execute(*a, **b) ProgrammingError: syntax error at or near "user" LINE 4: user INTEGER REFERENCES auth_user(id) ON DELETE CASCADE,
When web2py tries creating it's mode in this file:
# -*- coding: utf-8 -*- db.define_table('attender_appointment', Field('event', db.event, label=T("Event")), Field('user', db.auth_user, label=T("Creator")), Field('pos_x', 'integer', label=T("X Position")), Field('pos_y', 'integer', label=T("Y Position")), Field('floor_plan', db.floor_plan, label=T("Floor Plan")), Field('title', 'string', label=T("Title")), Field('details', 'text', label=T("Details")), Field('start_time', 'datetime', label=T("Start Time")), Field('end_time', 'datetime', label=T("End Time")), Field('with_who', db.auth_user, label=T("Guest")) ) db.attender_appointment.title.requires = IS_NOT_EMPTY() db.attender_appointment.start_time.requires = IS_NOT_EMPTY() db.attender_appointment.event.requires = IS_IN_DB(db,db.event.id,'%(name)s') db.attender_appointment.floor_plan.requires = IS_IN_DB(db,db.floor_plan.id,'%(name)s') db.attender_appointment.user.requires = IS_IN_DB(db,db.auth_user.id,'%(nickname)s') db.attender_appointment.with_who.requires = IS_IN_DB(db,db.auth_user.id,'%(nickname)s') db.attender_appointment.details.widget = lambda field,value: \ SQLFORM.widgets.text.widget(field,value,_class='text nicedit', _style="color:red")

This is not the first one in the system to be created so it seems to work for many other objects.  I wonder if there is a reserved word or something that is cause the problem.
Any ideas why this would happen?
BR,
Jason
IVINH | 24 May 06:26
Picon

Who are logged in?



HI,

How
can i know
the users who are logged in? or number of client online?
I will use "ram cache" to store information of each request (differentiated by IP or username)?

Thanks for your suggestions.


Chris | 24 May 04:03

Strange value for HTTP_HOST when using ssh tunneling

This seems like a problem in web2py or mod_wsgi -- or else I am confused.  Would appreciate any pointers from the experts.


I'm running web2py 1.99.7 on a Red Hat (RHEL 6) server using Apache 2.2.15 and mod_wsgi 3.3.  This is all running on a small virtual server at Amazon Web Services.

Since I don't want to open that box up to the world, I have been using ssh tunneling to allow processes on my local machine to connect to the AWS machine as if that is my local host.

That is done via sshe command lines that look like this:

ssh -i hs-test-000001.pem -L *:55080:localhost:80 -N root-6AcKVCUEOO6U0XCCZ3mAFg@public.gmane.org &
ssh -i hs-test-000001.pem -L *:55443:localhost:443 -N root-6AcKVCUEOO6U0XCCZ3mAFg@public.gmane.org &

The -L option has ssh create a listener on local port 55080 and forward all traffic to that port to IP address 107.21.240.172 / its localhost port 80.  The second command line is the same for port 443 (https).

This works well.  I can open a browser on my local machine, type localhost:55080 in the address bar, and it does indeed connect with the remote server and serve up the Welcome app.  (The AWS machine -- Apache and web2py -- function just as if the request came from that localhost.  The response is the same if I use a prompt on the AWS host and run 'curl localhost:80'.  It all checks out.  So far so good.

The problem has to do with how port numbers are interpreted on the AWS machine.  Browsing locally to http://localhost:55080 worked fine, but https://localhost:55443 resulted in an error.  After reading the error dump file and putting a little debug code in applications / admin / models / access.py, I could see the failure was caused by access.py trying to open a local password file 'parameters_55443.py'.  And indeed, when I copied the existing parameters_443.py file and names the copy parameters_55443.py, everything worked -- https://localhost:55443/admin brought up the admin add as I had expected.

I don't understand why the AWS web2py process would care about the port number from the client machine that initiated the request.  More than that, I don't understand how web2py even knows what the port number from the client is, since supposedly that is all handled in the ssh client side / sshd server side process that ssh -L provides.

To look further into this, I made a change in access.py to dump the entire 'request' structure to the Apache error log and paged through this.  The port number 55443 shows up several times:

-- 'HTTP_REFERER': 'https://localhost:55443/admin/default/site'
-- 'SERVER_SIGNATURE': '<address>Apache/2.2.15 (Red Hat) Server at localhost Port 55443</address>
-- 'SERVER_PORT': '55443'
-- 'HTTP_HOST': 'localhost:55443'
-- 'mod_wsgi.application_group': 'ip-10-114-191-91.ec2.internal:55443|

This is concerning because it means I may need to create new / redundant parameters_*.py files for multiple port numbers on a production machine if we use multiple port numbers in the ssh -L bridging.

More than that, it makes me wonder if there is something wrong with mod_wsgi or WSGI or how I have set them up -- and will this cause other problems.

Does it make sense that Apache and web2py would be aware of / use the port number from the remote client when it is mapped to a local port?

It seems like a bug to me.

Thanks
Ricardo Pedroso | 24 May 02:11
Picon

gweb2py

Hi,

I've made lot's of changes. Lot's of bug fixes and
new features, mainly:
 reload webserver
 ability to create new application
 session files viewer
 cache file viewer
 error files viewer
 file/new and file/open
 better syntax highlight when using StyledTextCtrl

On Linux there is possible to use vim(default) or StyledTextCtrl.

To run on Windows or Mac:
  $ python gweb2py

Linux:
  $ python gweb2py
or
  $ python gweb2py --editor stc
(will use the StyledTextCtrl)

If you have some spare time give it a try, but do not use it
in a real project until some more testing.

Some feedback will be welcome.

Ricardo

CtrlSoft | 24 May 01:38
Picon

pass table name in rows

hi, i have this controller:

def index():
    
    rows1 = db(db.news.public == True).select(orderby=~db.news.added_on, limitby=(0,10))
    rows2 = db(db.articles.public == True).select(orderby=~db.articles.added_on, limitby=(0,10))   
    rows = rows1.as_list()+rows2.as_list() 
    return dict(rows=rows)

the view:
in view i need to know table name to generate url

{{if rows:}}
    {{for row in rows:}}
        #if row.table_name == aritlces

        {{=H4(A(row['title_'+lang], _href=URL('default', 'article', args=row['id'])))}} 

        #else
         {{=H4(A(row['title_'+lang], _href=URL('default', 'news_content', args=row['id'])))}} 
    
                     
    {{pass}}
{{pass}}


article and news functions:
def article():
     return dict(row=db.articles[request.args(0)])

def news_content():
     return dict(row=db.news[request.args(0)])

any sugestions?

adohertyd | 24 May 00:22
Picon
Favicon

Send form submission to python script

I'm new to both python and web2py. I'm trying to build a meta-search engine and I need the search box to send the user input to a python script which will pre-process the query and obtain the results from 3 different search engines. I've created a very basic HTML form as in the example in the book, but I need it to be sent to the python script (controller? default.py ??) instead of redirecting to a new HTML page. Any help would be really appreciated

RKS | 23 May 22:32

Redirecting to a mobile website?

What is the best way to redirect uses to the mobile version of your site? I.e. redirecting to http://m.yoursite.com when it detects a mobile viewport?
I tried to do this the normal way that I redirect in other places but I keep getting invalid errors. We're just using js to detect the browser and then we can collect that data in w2p and redirect from there, correct?

Jason Brower | 23 May 18:55
Picon
Gravatar

Problem tranfering to a new database...

I now have the database up and running, but when I try to do this:

db.export_to_csv_file(open('/home/www-data/web2py/applications/welcome/uploads/file.csv', 'wb'))
db2.import_from_csv_file(open('/home/www-data/web2py/applications/welcome/uploads/file.csv', 'rb'))

It tells me:
Traceback (most recent call last): File "/home/www-data/web2py/gluon/restricted.py", line 205, in restricted exec ccode in environment File "/home/www-data/web2py/applications/welcome/models/wiki_page.py", line 23, in <module> db2.import_from_csv_file(open('/home/www-data/web2py/applications/welcome/uploads/file.csv', 'rb')) File "/home/www-data/web2py/gluon/dal.py", line 6446, in import_from_csv_file raise SyntaxError, 'invalid file format' SyntaxError: invalid file format I opened the file and it seems to look ok.  Ends with END :)
BR,
Jason
Jason Brower | 23 May 18:01
Picon
Gravatar

Trying to create a DAL connection and getting some errors...

In the console I type this:
db2 = DAL('postgres://postgres:******** <at> localhost:5432/postgres')
And I get this:
In [7] : print "hi"
hi

In [8] : db2 = DAL('postgres://postgres:******** <at> localhost:5432/postgres')
DEBUG: connect attempt 0, connection error:
Traceback (most recent call last):
   File "/home/www-data/web2py/gluon/dal.py", line 5955, in __init__
     self._adapter = ADAPTERS[self._dbname](*args)
   File "/home/www-data/web2py/gluon/dal.py", line 1999, in __init__
     self.driver = drivers.get('pg8000')
AttributeError: 'list' object has no attribute 'get'
DEBUG: connect attempt 1, connection error:
Traceback (most recent call last):
   File "/home/www-data/web2py/gluon/dal.py", line 5955, in __init__
     self._adapter = ADAPTERS[self._dbname](*args)
   File "/home/www-data/web2py/gluon/dal.py", line 1999, in __init__
     self.driver = drivers.get('pg8000')
AttributeError: 'list' object has no attribute 'get'
DEBUG: connect attempt 2, connection error:
Traceback (most recent call last):
   File "/home/www-data/web2py/gluon/dal.py", line 5955, in __init__
     self._adapter = ADAPTERS[self._dbname](*args)
   File "/home/www-data/web2py/gluon/dal.py", line 1999, in __init__
     self.driver = drivers.get('pg8000')
AttributeError: 'list' object has no attribute 'get'
DEBUG: connect attempt 3, connection error:
Traceback (most recent call last):
   File "/home/www-data/web2py/gluon/dal.py", line 5955, in __init__
     self._adapter = ADAPTERS[self._dbname](*args)
   File "/home/www-data/web2py/gluon/dal.py", line 1999, in __init__
     self.driver = drivers.get('pg8000')
AttributeError: 'list' object has no attribute 'get'
DEBUG: connect attempt 4, connection error:
Traceback (most recent call last):
   File "/home/www-data/web2py/gluon/dal.py", line 5955, in __init__
     self._adapter = ADAPTERS[self._dbname](*args)
   File "/home/www-data/web2py/gluon/dal.py", line 1999, in __init__
     self.driver = drivers.get('pg8000')
AttributeError: 'list' object has no attribute 'get'
Traceback (most recent call last):
   File "/home/www-data/web2py/gluon/contrib/shell.py", line 233, in run
     exec compiled in statement_module.__dict__
   File "<string>", line 1, in <module>
   File "/home/www-data/web2py/gluon/dal.py", line 5968, in __init__
     raise RuntimeError, "Failure to connect, tried %d times:\n%s" % 
(attempts, tb)
RuntimeError: Failure to connect, tried 5 times:
Traceback (most recent call last):
   File "/home/www-data/web2py/gluon/dal.py", line 5955, in __init__
     self._adapter = ADAPTERS[self._dbname](*args)
   File "/home/www-data/web2py/gluon/dal.py", line 1999, in __init__
     self.driver = drivers.get('pg8000')
AttributeError: 'list' object has no attribute 'get'

The server is located locally on an amazon system running ubuntu.  I 
created the postres user and it seems to be open and connectable.  I 
have also created the database postgres.
Any ideas why it wouldn't work?
BR,
Jason Brower

Jason Brower | 23 May 17:06
Picon
Gravatar

Development Environments vs Live Environment

Locally I only want to use SQLite.  And on the deployment I want to use 
Postgres.
Is there a way to make this happen automatically?
BR,
Jason Brower


Gmane