Re: [web2py] How to use XML data

2012-03-10 Thread Praveen Bhat
Hello Bruno,

Thanks a lot, that worked for me. You have been very helpful. 

Regards,
Praveen

On Saturday, March 10, 2012 1:35:51 PM UTC+5:30, rochacbruno wrote:
>
>
> https://gist.github.com/2010791
>
>
> -- 
>
> Bruno Rocha
> [http://rochacbruno.com.br]
>
>

[web2py] Re: YASQ 3: smartgrid and auth.accessible_query

2012-03-10 Thread Martin Weissenboeck
I have found a solution, but I don't know whether this solution is
efficient:

def has_membership(i):
return db.auth_user.id.belongs([k['user_id']\
for k in db(db.auth_membership.group_id==i).select()])

grid = SQLFORM.smartgrid(db.auth_user,
user_signature=False,
linked_tables=['phone'],
fields=[db.auth_user.id, db.auth_user.first_name],
constraints=dict(auth_user=has_membership(1)),
)

2012/3/9 Martin Weissenboeck 

> YASQ 3 (yet another smartgrid question):
>
> Hi, I have the tables auth_group, auth_membership and auth_permission and
> a smartgrid like
>
> grid = SQLFORM.smartgrid(db.auth_user,
> user_signature=False,
> linked_tables=['phone'],
> fields=[db.auth_user.id, db.auth_user.first_name],
> constraints=dict(auth_user=query),
> )
>
> I have tried some queries:
>
>- query = db.auth_user>0 # shows the whole table - ok
>- query=auth.accessible_query('read', db.auth_user, 1)
># User 1 is a member of group "teacher" and teachers have the
>permission to read some auth_user-records.
># The grid shows these auth_users, it is ok
>
>
> Now I want to select all "auth_user"s which are members of group #1. I
> want something like
>
>- query = auth.has_membership(group_id=1)
>- query = auth.has_membership(role='teacher')
>
> I have tried (thanks to Anthony):
>
>- query =(db.auth_user.id==db.auth_membership.user_id) &
>(db.auth_membership.group_id==1)
># yes, all members of group 1 are shown, but the link to the
>phone-table (the "phone"-button) does not work
>
> Any ideas?
> Regards, Martin
>


Re: [web2py] How to use XML data

2012-03-10 Thread Praveen Bhat
Hello,

How can i make the data in "temp" be available in every controller so that 
it can be rendered in every page in the site?

Regards
Praveen

On Saturday, March 10, 2012 1:47:20 PM UTC+5:30, Praveen Bhat wrote:
>
> Hello Bruno,
>
> Thanks a lot, that worked for me. You have been very helpful. 
>
> Regards,
> Praveen
>
> On Saturday, March 10, 2012 1:35:51 PM UTC+5:30, rochacbruno wrote:
>>
>>
>> https://gist.github.com/2010791
>>
>>
>> -- 
>>
>> Bruno Rocha
>> [http://rochacbruno.com.br]
>>
>>

Re: [web2py] How to use XML data

2012-03-10 Thread Bruno Rocha
put the code in models, /models/temp.py

>>> def get_temp():
... temp = None
... from xml.dom import minidom
... source = urllib2.urlopen('
http://free.worldweatheronline.com/feed/weather.ashx?q=udupi&format=xml&num_of_days=2&key=b019cd7d6a135850110711
')
... source_text = source.read()
... parseddata = minidom.parseString(source_
text)
... temp_c = parseddata.getElementsByTagName('temp_C')
... if temp_c:
... temp = temp_c[0].firstChild.toxml()
... return temp


So in any view you can do:

{{=get_temp()}}

also you can access it in any controller

def index():
temp = get_temp()
return dict(temp=temp)


Bruno Rocha
[http://rochacbruno.com.br]


[web2py] Re: web2py site and disabling browser right clicks

2012-03-10 Thread Rahul
Thank you all of you,
   I am thinking of linking pyjamas with my web2py project. Though I
it does not restrict users from viewing the page source, it does not
show parameters in the source to the public openly. This way if there
is someone with malicious intentions, we can prevent one from
inspecting site parameters to some extent. Per Bruno, flex and flash
or Silverlight are good alternatives but they definitely do have a
learning curve and also will take me some time to learn integrating
those with web2py. How safe is flex development from security point of
view.. I dont really have any idea.

How about SSL? I am not at all familiar with it :( Does it help in
some way? or
Some other java script frameworks that can help may be Qooxdoo etc ?

Sincerely, Rahul D (www.flockbird.com)


On Mar 10, 8:05 am, Anthony  wrote:
> On Friday, March 9, 2012 7:14:14 PM UTC-5, rochacbruno wrote:
>
> > Use flash/flex or MS Silverlight, you will have this by default :)
>
> Though even those can be decompiled.


[web2py] Re: web2py site and disabling browser right clicks

2012-03-10 Thread Rahul
...And I do agree that Pyjamas does have a learning curve aswell .. :)
It seems there is no escape but to learn new a technology :)

Sincerely, Rahul D (www.flockbird.com)

On Mar 10, 3:06 pm, Rahul  wrote:
> Thank you all of you,
>    I am thinking of linking pyjamas with my web2py project. Though I
> it does not restrict users from viewing thepagesource, it does not
> show parameters in thesourceto the public openly. This way if there
> is someone with malicious intentions, we can prevent one from
> inspecting site parameters to some extent. Per Bruno, flex and flash
> or Silverlight are good alternatives but they definitely do have a
> learning curve and also will take me some time to learn integrating
> those with web2py. How safe is flex development from security point ofview.. 
> I dont really have any idea.
>
> How about SSL? I am not at all familiar with it :( Does it help in
> some way? or
> Some other java script frameworks that can help may be Qooxdoo etc ?
>
> Sincerely, Rahul D (www.flockbird.com)
>
> On Mar 10, 8:05 am, Anthony  wrote:
>
>
>
>
>
>
>
> > On Friday, March 9, 2012 7:14:14 PM UTC-5, rochacbruno wrote:
>
> > > Use flash/flex or MS Silverlight, you will have this by default :)
>
> > Though even those can be decompiled.


[web2py] Re: Pycon Streaming

2012-03-10 Thread Alan Etkin
Great! Thank you

On 9 mar, 19:42, Bruno Rocha  wrote:
> Watch Pycon Talks here:http://streamti.me/
>
> --
>
> Bruno Rocha
> [http://rochacbruno.com.br]


[web2py] Re: web2py site and disabling browser right clicks

2012-03-10 Thread Alan Etkin
SSL is a protocol used to encrypt the data as it is sent between
machines, but it does not prevent the source to be read by a user.

I think that Chris has pointed out very well the problem: if you have
info that you won't expose publicly, that information should be stored
and processed server-side only.


On 10 mar, 07:06, Rahul  wrote:
> Thank you all of you,
>    I am thinking of linking pyjamas with my web2py project. Though I
> it does not restrict users from viewing the page source, it does not
> show parameters in the source to the public openly. This way if there
> is someone with malicious intentions, we can prevent one from
> inspecting site parameters to some extent. Per Bruno, flex and flash
> or Silverlight are good alternatives but they definitely do have a
> learning curve and also will take me some time to learn integrating
> those with web2py. How safe is flex development from security point of
> view.. I dont really have any idea.
>
> How about SSL? I am not at all familiar with it :( Does it help in
> some way? or
> Some other java script frameworks that can help may be Qooxdoo etc ?
>
> Sincerely, Rahul D (www.flockbird.com)
>
> On Mar 10, 8:05 am, Anthony  wrote:
>
>
>
>
>
>
>
> > On Friday, March 9, 2012 7:14:14 PM UTC-5, rochacbruno wrote:
>
> > > Use flash/flex or MS Silverlight, you will have this by default :)
>
> > Though even those can be decompiled.


[web2py] Re: Pycon Streaming

2012-03-10 Thread Alan Etkin
Something else:

web2py: ideas we stole and ideas we had
Massimo Di Pierro

Scheduled talk
Sunday, 1:30 PM (Santa Clara I suppose) Track 4 (E4)


[web2py] Re: installing as a window service

2012-03-10 Thread Alan Etkin
Do you get any error output or feedback from the operating system?
Does web2py start with the built-in rocket server?

On 9 mar, 13:28, Muscillo Luigi  wrote:
> i'm trying to install web2py as a window server; I followed all
> instructions issued about the argument but id doesnt'work;
> i tried both with binary distribution and source distribution but when
> i try to start service it doesn't start!
> does anybody help me?


[web2py] how to set a default user group

2012-03-10 Thread Vasile Ermicioi
hi,

currently a new user group is created for each new user after registration,
I disabled new groups to be created
auth.settings.create_user_groups = False

but actually I need to set all new users to a default user group

I know I will get a response, :) thank you in advance



[web2py] Re: how to set a default user group

2012-03-10 Thread Alan Etkin
This is one way of solving it (by binding a function to an
auth.settings attribute):

# model code

def post_register(form):
# the new user id is stored in auth.user_id
pass

auth.settings.register_onaccept = give_create_permission

On registration, you can perform auth management by accessing the new
user id

On 10 mar, 09:37, Vasile Ermicioi  wrote:
> hi,
>
> currently a new user group is created for each new user after registration,
> I disabled new groups to be created
> auth.settings.create_user_groups = False
>
> but actually I need to set all new users to a default user group
>
> I know I will get a response, :) thank you in advance


Re: [web2py] How to use XML data

2012-03-10 Thread Praveen Bhat
Hello,

How can i get the CDATA values?

I am trying this and its outputting 'None':
 
def get_weather_condition():
weathercondition = None
from xml.dom import minidom
import urllib2
source = 
urllib2.urlopen('http://free.worldweatheronline.com/feed/weather.ashx?q=udupi&format=xml&num_of_days=2&key=b019cd7d6a135850110711')
source_text = source.read()
parseddata = minidom.parseString(source_text)
weatherDesc = parseddata.getElementsByTagName('weatherDesc')
weatherDesc1 = parseddata.getElementsByTagName('![CDATA[]]')
if weatherDesc1:
weathercondition = weatherDesc1[0].firstChild.toxml()
return weathercondition

regards
Praveen


On Saturday, March 10, 2012 3:07:29 PM UTC+5:30, rochacbruno wrote:
>
> put the code in models, /models/temp.py
>
> >>> def get_temp():
> ... temp = None
> ... from xml.dom import minidom
> ... source = urllib2.urlopen('
> http://free.worldweatheronline.com/feed/weather.ashx?q=udupi&format=xml&num_of_days=2&key=b019cd7d6a135850110711
> ')
> ... source_text = source.read()
> ... parseddata = minidom.parseString(source_
> text)
> ... temp_c = parseddata.getElementsByTagName('temp_C')
> ... if temp_c:
> ... temp = temp_c[0].firstChild.toxml()
> ... return temp
>
>
> So in any view you can do:
>
> {{=get_temp()}}
>
> also you can access it in any controller
>
> def index():
> temp = get_temp()
> return dict(temp=temp)
>
>
> Bruno Rocha
> [http://rochacbruno.com.br]
>
>

Re: [web2py] iframe and pdf

2012-03-10 Thread Martin Weissenboeck
Nice solution - thank you!
Martin

2012/3/10 Bruno Rocha 

>
> def k():
> if 'showpdf' in request.args:
> return person2pdf(session.ids)
> else:
> return dict(ifr=IFRAME(_src=URL('default','k', args='showpdf')))
>
>
>
> --
>
> Bruno Rocha
> [http://rochacbruno.com.br]
>
>


[web2py] Re: web2py site and disabling browser right clicks

2012-03-10 Thread pbreit
Disabling the right-click is incredibly user-hostile and ultimately does 
not prevent your pages from exposure. Silverlight and Flash are on their 
way out and are not usable by many devices (ie iPhones, iPads and some 
Macs).

There really should not be any good reasons to hide your HTML. If it has 
sensitive data, it shouldn't.


[web2py] Latest version unable to connect to DB

2012-03-10 Thread Bruce Wade
db_users = DAL('postgres://warplyde_fto:password@localhost/warplyde_fto')

Has something been changed in how we need to make database connections
to postgres?

Traceback (most recent call last):
  File 
"/home/bruce/Development/wct_dev/web2py_dev/projects/fto/gluon/restricted.py",
line 205, in restricted
exec ccode in environment
  File 
"/home/bruce/Development/wct_dev/web2py_dev/projects/fto/applications/signon/models/db.py"
, line 14, in

db_users = DAL('postgres://warplyde_fto:password@localhost/warplyde_fto')
  File "/home/bruce/Development/wct_dev/web2py_dev/projects/fto/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/bruce/Development/wct_dev/web2py_dev/projects/fto/gluon/dal.py",
line 5955, in __init__
self._adapter = ADAPTERS[self._dbname](*args)
  File "/home/bruce/Development/wct_dev/web2py_dev/projects/fto/gluon/dal.py",
line 1999, in __init__
self.driver = drivers.get('pg8000')
AttributeError: 'list' object has no attribute 'get'


-- 
-- 
Regards,
Bruce Wade
http://ca.linkedin.com/in/brucelwade
http://www.wadecybertech.com
http://www.warplydesigned.com
http://www.fitnessfriendsfinder.com


[web2py] Differentiating between URLs in web2py controllers

2012-03-10 Thread Saurabh Kumar
Hi,

I am writing a web2py application wherein I want my controller to behave 
differently to following URLs

/user/login

/user/login#_=_

Please suggest a way to differentiate between these two.   Would it ask for 
make a modification in routes.py?

Thanks

Saurabh


[web2py] Greetings

2012-03-10 Thread hugoGee
I just came across web2py, looking forward to working with the
framework and getting to know some of the folks here.

-cheers


Re: [web2py] Re: How to call other web2py applications from within a web2py application

2012-03-10 Thread bussiere bussiere
Bruno :
Thanks for your devoting.

Bussiere



"Les nouvelles technologies offrent pleins de nouvelles possibilités,
pleins de possibilités d'erreurs surtout en fait."
insurance.aes256 : http://goo.gl/gHyAY




On Sat, Mar 10, 2012 at 4:11 AM, Bruno Rocha  wrote:
> I have a working website using two apps, hosted at different servers but
> using the same database/session. I will take it to remember the
> implementation in details and write a recipe in web2pyslices.
>
>
> On Fri, Mar 9, 2012 at 11:00 PM, Bruce Wade  wrote:
>>
>> How about you provide an example, considering you sound like the expert at
>> it :D
>>
>>
>> On Fri, Mar 9, 2012 at 5:53 PM, Bruno Rocha  wrote:
>>>
>>> **important: to share the same user/session information, you have to
>>> share the same auth.hmac_key
>>>
>>>
>>> --
>>>
>>> Bruno Rocha
>>> [http://rochacbruno.com.br]
>>>
>>
>>
>>
>> --
>> --
>> Regards,
>> Bruce Wade
>> http://ca.linkedin.com/in/brucelwade
>> http://www.wadecybertech.com
>> http://www.warplydesigned.com
>> http://www.fitnessfriendsfinder.com
>
>
>
>
> --
>
> Bruno Rocha
> [http://rochacbruno.com.br]
>


[web2py] Re: web2py site and disabling browser right clicks

2012-03-10 Thread Rahul
I think it makes sense to process sensitive data server side. I'll
think over my options and proceed to achieve my goal. I don't want to
loose out on user experience either. Thank you all for your valuable
feedback. I hope HTML5+ / (WWW) would consider adding secure parameter
to faciliate such things may be kind of tags like or something ...
[just a thought]
[
  

:)

Thanks and forgive my ignorance,
Sincerely Rahul D. (www.flockbird.com)


On Mar 10, 9:50 pm, pbreit  wrote:
> Disabling the right-click is incredibly user-hostile and ultimately does
> not prevent your pages from exposure. Silverlight and Flash are on their
> way out and are not usable by many devices (ie iPhones, iPads and some
> Macs).
>
> There really should not be any good reasons to hide your HTML. If it has
> sensitive data, it shouldn't.


[web2py] Re: web2py site and disabling browser right clicks

2012-03-10 Thread Anthony

>
> I think it makes sense to process sensitive data server side. I'll 
> think over my options and proceed to achieve my goal. I don't want to 
> loose out on user experience either.


What exactly is it that you are trying to hide? Can you give an example?
 

> Thank you all for your valuable 
> feedback. I hope HTML5+ / (WWW) would consider adding secure parameter 
> to faciliate such things may be kind of tags like or something ... 
> [just a thought] 
> [ 
>
>

How would that work? Once you deliver the content to the browser, you would 
then have to trust the browser software to maintain the security of the 
data. That means before sending the data to the browser, you first have to 
confirm the browser can be trusted and is not a spoofed or hacked version 
of a trusted browser.

Anthony



[web2py] Re: Greetings

2012-03-10 Thread Anthony
Welcome, and enjoy. :-)

On Saturday, March 10, 2012 12:37:49 PM UTC-5, hugoGee wrote:
>
> I just came across web2py, looking forward to working with the 
> framework and getting to know some of the folks here. 
>
> -cheers



[web2py] Re: Differentiating between URLs in web2py controllers

2012-03-10 Thread Anthony

>
> I am writing a web2py application wherein I want my controller to behave 
> differently to following URLs
>
> /user/login
>
> /user/login#_=_
>

The "_=_" after the # is a fragment identifier, and the browser does not 
send fragment identifiers to the server, so web2py has no way to 
differentiate between those two URLs (the server will simply receive a 
request to /user/login in both cases). You can use a query string instead, 
such as /user/login?q=_%3D_ (note, "%3D" is a url-encoded "="). In that 
case, the "_=_" will be available in request.vars.q in your app. If you 
want, I suppose you could use some Javascript on the client side to capture 
changes in the fragment identifier and automatically convert to a request 
with a query string (that's roughly how hashbang URLs work, though using 
Ajax requests to fetch the requested data).

Anthony


[web2py] Re: Differentiating between URLs in web2py controllers

2012-03-10 Thread pbreit
As Anthony noted, what you are showing won't work. What are you trying to 
do?

You can include any code you want in the user() function.


[web2py] Re: looking for tutorial extends user and related to an other app

2012-03-10 Thread Alan Etkin
If you are sharing models, there is a way of using one for all apps
stored in the applications folder, that is to make symbolic links on
each app specific folder to a single archive. I don't like using this
technique, but it's a choice anyway. Another way of extending an
application is to use plugins. Plugins are very easy to use (at least
for simple implementations). You still have to install the plugin for
each app, but it is more straightforward as it can be done trough the
administrative interface.


On 9 mar, 18:25, bussiere adrien  wrote:
> i've found this 
> :http://stackoverflow.com/questions/7121146/web2py-custom-user-profile
> But i still have problems to find how to make list:related to an ohter app
> or make a global auth extend in db for all app.
>
> Regards
> Bussiere
>
> Le jeudi 8 mars 2012 21:47:08 UTC+1, bussiere adrien a écrit :
>
>
>
>
>
>
>
>
>
> > Hello i'am looking for tutorial to :
>
> > Extends user add field to database.
>
> > Then :
> > an app street
> > an app buildint
>
> > link building field with street field
>
> > And more tutorial
>
> > Regards
>
> > Bussiere


[web2py] Re: web2py site and disabling browser right clicks

2012-03-10 Thread Cliff
Silverlight locks your users into Internet Explorer.

With the Explorer usage below 50%, why would you do that?

On Mar 10, 2:33 pm, Anthony  wrote:
> > I think it makes sense to process sensitive data server side. I'll
> > think over my options and proceed to achieve my goal. I don't want to
> > loose out on user experience either.
>
> What exactly is it that you are trying to hide? Can you give an example?
>
> > Thank you all for your valuable
> > feedback. I hope HTML5+ / (WWW) would consider adding secure parameter
> > to faciliate such things may be kind of tags like or something ...
> > [just a thought]
> > [
> >   
>
> How would that work? Once you deliver the content to the browser, you would
> then have to trust the browser software to maintain the security of the
> data. That means before sending the data to the browser, you first have to
> confirm the browser can be trusted and is not a spoofed or hacked version
> of a trusted browser.
>
> Anthony


[web2py] Website doesn't show up.

2012-03-10 Thread george3825
Hello,

I edited the following setting in tools.py in gluon:

From: auth.settings.login_next = URL('index')

To: auth.settings.login_next = URL('account')

Saved the file and restarted Apache2

I am able to successfully log in it does take me to
http://www.site.com/Main/default/account

But all the account site displays is a white page with the word "None"

It doesn't even display my layout.

Any ideas?

Thanks.



[web2py] Re: Website doesn't show up.

2012-03-10 Thread Alan Etkin
It appears that your controller sent a None object response. For using
the view's template, the return statement of the function should
return a dict object:

def mycontroller():
...
return dict(name=value)

On Mar 10, 7:28 pm, george3825  wrote:
> Hello,
>
> I edited the following setting in tools.py in gluon:
>
> From: auth.settings.login_next = URL('index')
>
> To: auth.settings.login_next = URL('account')
>
> Saved the file and restarted Apache2
>
> I am able to successfully log in it does take me 
> tohttp://www.site.com/Main/default/account
>
> But all the account site displays is a white page with the word "None"
>
> It doesn't even display my layout.
>
> Any ideas?
>
> Thanks.


[web2py] Stand alone example using DAL

2012-03-10 Thread Bruce Wade
For anyone who is interested attached is a standalone class using DAL. It
using a singleton for the database connection not sure if this is good or
bad for all applications. However I am working on classes that will remain
in memory.

As long as gluon is in your python path you can test this file with: python
body.py
PS: Make sure to edit the database connection string
-- 
-- 
Regards,
Bruce Wade
http://ca.linkedin.com/in/brucelwade
http://www.wadecybertech.com
http://www.warplydesigned.com
http://www.fitnessfriendsfinder.com
# Author: Bruce Wade
# 2012-03-10

import datetime

from gluon import DAL, Field

class Body:

db = None

def __init__(self, db):
if not Body.db:
Body.db = db
self.define_tables(Body.db)

def add_weight(self, member, weight):
now = datetime.datetime.now()
new_entry = Body.db.body_weight.insert(
member = member,
weight = weight,
updated_at = now
)
self.db.commit()

def delete_weight(self, member, weight_id):
weight = Body.db((Body.db.body_weight.member == member) & (Body.db.body_weight.id == weight_id)).select().first()
if weight:
weight.delete()

def get_body_weights(self, member):
return Body.db(Body.db.body_weight.member == member).select()

def get_last_weight(self, member):
return Body.db(Body.db.body_weight.member == member).select(orderby=~Body.db.body_weight.id).first()

def get_weight_loss(self, member):
first, last = self._get_max_last(member)

if not first and not last:
return None, "Not enough data!"

if first > last:
loss = first - last
return True, loss
else:
gained = last - first
return False, gained

def get_weight_gain(self, member):
first, last = self._get_max_last(member)

if not first and not last:
return None, "Not enough data!"

if first > last:
loss = first - last
return False, loss
else:
gained = last - first
return True, gained

def get_max_weight(self, member):
body_max = Body.db.body_weight.weight.max()
return Body.db(Body.db.body_weight.member == member).select(body_max).first()['MAX(body_weight.weight)']

def get_min_weight(self, member):
body_min = Body.db.body_weight.weight.min()
return Body.db(Body.db.body_weight.member == member).select(body_min).first()['MIN(body_weight.weight)']

def get_last_x_weights(self, member, weights_to_get = 5):
return Body.db(Body.db.body_weight.member == member).select(orderby=~Body.db.body_weight.id, limitby=(0, weights_to_get))

def _get_max_last(self, member):
max = self.get_max_weight(member)
last  = Body.db(Body.db.body_weight.member == member).select(orderby=~Body.db.body_weight.id).first()
count = Body.db(Body.db.body_weight.member == member).count()

if count >= 2:
return max, last.weight
else:
return None, None

def define_tables(self, db):
print "Trying to define tables"
if 'body_weight' not in self.db.tables:
now = datetime.datetime.now()
Body.db.define_table('body_weight',
Field('member', 'integer'),
Field('weight', 'double'),
Field('record_date', 'date', default=now),
Field('updated_at', 'datetime', update=now)
)
self.db.commit()

if __name__ == "__main__":
db = DAL('postgres:psycopg2://user_name:password@localhost/database')
body = Body(db)
member = 1
weight = 155
print "Adding body weight"
#body.add_weight(member, weight)

print "Getting body weights"
print body.get_body_weights(member)

print "Get last entry"
print body.get_last_weight(member)

lost, amount = body.get_weight_loss(member)
if lost:
print "You lost %slbs" % amount
else:
print "Sorry you gained %slbs" % amount

gain, amount = body.get_weight_gain(member)
if gain:
print "You gained %slbs" % amount
else:
print "Sorry you lost %slbs" % amount

print "Max weight", body.get_max_weight(member)
print "Min weight", body.get_min_weight(member)

print "Last weights\n", body.get_last_x_weights(member)

import random, datetime
random.seed(datetime.datetime.now())
newbody = Body(db)
member = 2
for weight in xrange(100):
weight = random.randint(0, 500)
newbody.add_weight(member, weight)
print "Get last entry"
print newbody.get_last_weight(member)
lost, amount = newbody.get_weight_loss(member)
if lost:
print "You lost %slbs" % amount
 

[web2py] Re: Latest version unable to connect to DB

2012-03-10 Thread Alan Etkin
If something changed (as now pg adapter supports pg8000 driver), old
uri strings would have to be accepted also. I'd say it's is a bug.
There seems to be a list/dict conflict in dal.

On Mar 10, 2:16 pm, Bruce Wade  wrote:
> db_users = DAL('postgres://warplyde_fto:password@localhost/warplyde_fto')
>
> Has something been changed in how we need to make database connections
> to postgres?
>
> Traceback (most recent call last):
>   File 
> "/home/bruce/Development/wct_dev/web2py_dev/projects/fto/gluon/restricted.py",
> line 205, in restricted
>     exec ccode in environment
>   File 
> "/home/bruce/Development/wct_dev/web2py_dev/projects/fto/applications/signon/models/db.py"
> , line 14, in
> 
>     db_users = DAL('postgres://warplyde_fto:password@localhost/warplyde_fto')
>   File "/home/bruce/Development/wct_dev/web2py_dev/projects/fto/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/bruce/Development/wct_dev/web2py_dev/projects/fto/gluon/dal.py",
> line 5955, in __init__
>     self._adapter = ADAPTERS[self._dbname](*args)
>   File "/home/bruce/Development/wct_dev/web2py_dev/projects/fto/gluon/dal.py",
> line 1999, in __init__
>     self.driver = drivers.get('pg8000')
> AttributeError: 'list' object has no attribute 'get'
>
> --
> --
> Regards,
> Bruce 
> Wadehttp://ca.linkedin.com/in/brucelwadehttp://www.wadecybertech.comhttp://www.warplydesigned.comhttp://www.fitnessfriendsfinder.com


[web2py] Re: Latest version unable to connect to DB

2012-03-10 Thread Alan Etkin
Line 1999 in trunk:
self.driver = drivers.get('pg8000')
Should be:
self.driver = self.drivers.get('pg8000')

On Mar 10, 8:07 pm, Alan Etkin  wrote:
> If something changed (as now pg adapter supports pg8000 driver), old
> uri strings would have to be accepted also. I'd say it's is a bug.
> There seems to be a list/dict conflict in dal.
>
> On Mar 10, 2:16 pm, Bruce Wade  wrote:
>
>
>
>
>
>
>
> > db_users = DAL('postgres://warplyde_fto:password@localhost/warplyde_fto')
>
> > Has something been changed in how we need to make database connections
> > to postgres?
>
> > Traceback (most recent call last):
> >   File 
> > "/home/bruce/Development/wct_dev/web2py_dev/projects/fto/gluon/restricted.py",
> > line 205, in restricted
> >     exec ccode in environment
> >   File 
> > "/home/bruce/Development/wct_dev/web2py_dev/projects/fto/applications/signon/models/db.py"
> > , line 14, in
> > 
> >     db_users = 
> > DAL('postgres://warplyde_fto:password@localhost/warplyde_fto')
> >   File 
> > "/home/bruce/Development/wct_dev/web2py_dev/projects/fto/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/bruce/Development/wct_dev/web2py_dev/projects/fto/gluon/dal.py",
> > line 5955, in __init__
> >     self._adapter = ADAPTERS[self._dbname](*args)
> >   File 
> > "/home/bruce/Development/wct_dev/web2py_dev/projects/fto/gluon/dal.py",
> > line 1999, in __init__
> >     self.driver = drivers.get('pg8000')
> > AttributeError: 'list' object has no attribute 'get'
>
> > --
> > --
> > Regards,
> > Bruce 
> > Wadehttp://ca.linkedin.com/in/brucelwadehttp://www.wadecybertech.comhttp:...


[web2py] Re: Stand alone example using DAL

2012-03-10 Thread Alan Etkin
Cool, something similar without passing the db instance to a class
constructor is done by gui2py. It also converts the helper objects to
wxPython

http://code.google.com/p/gui2py

gui2py aims to give a complete interface to run web2py applications on
wxPython desktop environment. I am using it in an ERP open source
project, http://code.google.com/p/gestionlibre

On Mar 10, 7:55 pm, Bruce Wade  wrote:
> For anyone who is interested attached is a standalone class using DAL. It
> using a singleton for the database connection not sure if this is good or
> bad for all applications. However I am working on classes that will remain
> in memory.
>
> As long as gluon is in your python path you can test this file with: python
> body.py
> PS: Make sure to edit the database connection string
> --
> --
> Regards,
> Bruce 
> Wadehttp://ca.linkedin.com/in/brucelwadehttp://www.wadecybertech.comhttp://www.warplydesigned.comhttp://www.fitnessfriendsfinder.com
>
>  body.py
> 6KViewDownload


[web2py] Re: web2py site and disabling browser right clicks

2012-03-10 Thread pbreit
Sliverlight works on all browsers as far as I know. But I still don't think 
it's a very smart platform to target for the vast majority of apps.

[web2py] Errors creating/reading tickets

2012-03-10 Thread Brian M
This has actually been plaguing me for a while but finally annoyed me 
enough to ask.  I have several web2py (1.99.4) apps running under 
Apache/2.2.17 (Win32) , mod_wsgi/3.3 and Python/2.6.4.  More often than not 
when an error happens and a ticket is generated, the ticket seems to be 
corrupt.  Attempting to view the ticket creates another error for which the 
ticket says something like:

 Version  web2py™ (1, 99, 4, 
datetime.datetime(2011, 12, 22, 11, 20, 45), 'stable')  Python Python 
2.6.4: C:\vantage_dashboard\xampp\apache\bin\httpd.exe  Traceback 

1.
2.
3.
4.
5.
6.
7.
8.
9.
10.
11.
12.
13.
14.
15.
16.

Traceback (most recent call last):
  File "C:\vantage_dashboard\xampp\web2py\gluon\restricted.py", line 204, in 
restricted
exec ccode in environment
  File 
"C:/vantage_dashboard/xampp/web2py/applications/admin/controllers/default.py" 
, line 1341, 
in 
  File "C:\vantage_dashboard\xampp\web2py\gluon\globals.py", line 172, in 

self._caller = lambda f: f()
  File 
"C:/vantage_dashboard/xampp/web2py/applications/admin/controllers/default.py" 
, line 1082, 
in errors
error = pickle.load(fullpath_file)
  File "C:\Python26\Lib\pickle.py", line 1370, in load
return Unpickler(file).load()
  File "C:\Python26\Lib\pickle.py", line 858, in load
dispatch[key](self)
  File "C:\Python26\Lib\pickle.py", line 880, in load_eof
raise EOFError
EOFError


Which means that I have to attempt to read the original error ticket in a 
text editor which is just slightly less than idea.  Any ideas what might be 
happening? This problem doesn't seem to happen in my dev environment (also 
Windows but just using rocket instead of apache/mod_wsgi).

Thanks,
Brian


[web2py] How to list:reference users ?

2012-03-10 Thread bussiere adrien
maybe Field('Auth','list:reference Auth'),
or ('Auth','list:reference User'),

Regards
Bussiere


[web2py] Re: How to list:reference users ?

2012-03-10 Thread pbreit
Field('user_id', db.auth_user)


[web2py] Translations in custom classes

2012-03-10 Thread Bruce Wade
Hi,

I was looking at the Auth class, why are settings like the following not
showing in the language translations files by default?

# ## these are messages that can be customized
messages = self.messages = Messages(current.T)
messages.password_reset_button = 'Request reset password'

I have no idea what Messages(current.T) is supposed to do however the above
string is not found in the languages files.

-- 
-- 
Regards,
Bruce Wade
http://ca.linkedin.com/in/brucelwade
http://www.wadecybertech.com
http://www.warplydesigned.com
http://www.fitnessfriendsfinder.com


Re: [web2py] Re: Website doesn't show up.

2012-03-10 Thread George
Putting in return dict() made it work. Thanks.

What exactly does that do? Where does it get sent to?

On Sat, Mar 10, 2012 at 4:53 PM, Alan Etkin  wrote:

> It appears that your controller sent a None object response. For using
> the view's template, the return statement of the function should
> return a dict object:
>
> def mycontroller():
>...
>return dict(name=value)
>
> On Mar 10, 7:28 pm, george3825  wrote:
> > Hello,
> >
> > I edited the following setting in tools.py in gluon:
> >
> > From: auth.settings.login_next = URL('index')
> >
> > To: auth.settings.login_next = URL('account')
> >
> > Saved the file and restarted Apache2
> >
> > I am able to successfully log in it does take me tohttp://
> www.site.com/Main/default/account
> >
> > But all the account site displays is a white page with the word "None"
> >
> > It doesn't even display my layout.
> >
> > Any ideas?
> >
> > Thanks.
>


Re: [web2py] Database trigger like django save ?

2012-03-10 Thread nick name
Le vendredi 9 mars 2012 23:48:30 UTC+1, rochacbruno a écrit :
>
> To do what Django does we need to have some "hooks' for that 3 events 
>> (dbset.insert, dbsert.update and Row.update_record)
>>
>> I can see that if you extend DAL it is possible to redefine via monkey 
>> patching the .insert method.
>>
>> But it will be very better if DAL can handle this out of the box.
>>
>> A suggestions is adding an "callback" in .insert method
>>
>> def myfunction(id):
>> .
>>
>> db(db...).insert(**., _callback=myfunction)
>>
>> But I dont know if it is possible...
>
>
I posted "Issue 354 : 
Database 
audit implementation / generalized web2py+dal triggers " a while ago (using 
monkey patching). I'm no longer maintaining that patch, but if anyone wants 
to revive it, this is a reasonable start.