Re: [web2py] Re: Converting Field of a SQLFORM.grid to local timezone of a user.....

2013-02-12 Thread Amit
Can we use "represent" callback in case of hugh number of rows(lets say
2 or more rows is there in db), will it not be causing to slow down the
whole process, means, while converting utc time to target timezone's time
one by one for each row and then displayed to UI using SQLFORM.grid()?

Please share your thought because I am also using represent callback to
convert each row's utc time to target timezone:

db.table.datefield.represent = convert_time

where convert_time function will be calculating timezone for each row and
return it, so it will be called for each row, in my case it will called for
more than 2 rows.

So will it be an optimized way of achieving this functionality OR is there
any best optimal way of achieve this?

Please provide your suggestions.


On Wed, Feb 13, 2013 at 8:50 AM, Michael Beller  wrote:

> this stores dates in UTC but displays date in alternate timezone.  You can
> set the represent property based on a timezone stored in the users profile
> or derived from locale settings ...
>
> from pytz import timezone
> import pytz
>
> db.define_table('t_date',
> Field('f_name'),
> Field('f_datetime', type='datetime', default=request.utcnow),
> Field('f_utcdatetime', type='datetime', default=request.utcnow),
> migrate=True)
>
> db.t_date.f_datetime.represent = lambda value, row :
> pytz.UTC.localize(value).astimezone(timezone('US/Eastern'))
>
>
> I used information in the following two pages for help ...
>
>
> http://stackoverflow.com/questions/7065164/how-to-make-an-unaware-datetime-timezone-aware-in-python?lq=1
> http://pypi.python.org/pypi/pytz/
>
> On Tuesday, February 12, 2013 7:40:59 AM UTC-5, Michael Beller wrote:
>
>> I've also been researching and experimenting ...
>>
>> I've come to the conclusion to only store utc dates (e.g., using utcnow)
>> in the data base and then use .represent or other means to convert for
>> display.
>>
>> Most notably, use the putz python library ...
>>
>>
>> On Tuesday, February 12, 2013 1:58:26 AM UTC-5, rochacbruno wrote:
>>>
>>> I am on mobile now and I cant ellaborate a good code example, but I can
>>> give you a hint.
>>>
>>> db.table.datefield.represent = lambda value, row :
>>> value.strftime("%Y/%m/%d")
>>>
>>> grid = SQLFORM.grid(db.table)
>>>
>>> so grid will use the represent callback to display the data.
>>>
>>> following this example you can do
>>>
>>> def set_timezone(value, row):
>>>  return value. #do the calculation
>>>
>>> db.table.field.represent = set_timezone
>>> Em 12/02/2013 04:44, "newbie"  escreveu:
>>>

 On Tuesday, 12 February 2013 11:06:00 UTC+5:30, newbie wrote:
>
> Hi,
> I have a table x, with fields name,place,timezone_offset.And
> another table y ,having  field 'servertime',which **stor**es
> the current time of the server its fetching the values from.
>
>  db.define_table('x',Field('**nam**e'),Field('place'),Field('**time**
> zone_offset'))
> db.define_table('y',Field('**nam**e'),Field('ser**vertime'))
>

 User will set the timezone offset in table x, for a particular name.
 There is one thread continuously running in background in the server which
 will save the servertime as local time using datetime.datetime.now() in
 table y for the name.

 And finally this data displayed by using SQLFORM.grid on the UI.

 Problem facing:
 We have to convert the local time saved for the name field as per saved
 timezone_offset in x table and display on the grid without modifying
 anything on database level.
 It means suppose for name ='Alex'  timezone_offset was being saved as
 -5 in x table and suppose server running on different timezone lets say on
 +5.30 so for name Alex server will save the servertime in +5.30 format as
 it is the local time for the server but when it will be displayed on the
 grid servertime should first get converted to Alex timezone_offset which is
 set as -5 and then display on the grid.

 Can anyone please suggest me how can I achieved in web2py? Is there any
 way to achieve it using SQLFORM.grid()?

 Thanks.




>
>
  --

 ---
 You received this message because you are subscribed to the Google
 Groups "web2py-users" group.
 To unsubscribe from this group and stop receiving emails from it, send
 an email to web2py+un...@googlegroups.com.
 For more options, visit 
 https://groups.google.com/**groups/opt_out
 .



>>>  --
>
> ---
> You received this message because you are subscribed to the Google Groups
> "web2py-users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to web2py+unsubscr...@googlegroups.com.
> For more options, visit https://groups.google.com/groups/opt_out.
>
>
>

-- 

--- 
You received this message because you are subscribed to the Google Groups 
"web2py-users" 

Re: [web2py] Re: Converting Field of a SQLFORM.grid to local timezone of a user.....

2013-02-12 Thread Alec Taylor
To keep things simple on the database side; how about making all times UTC?

Then use JavaScript to impose timezone on the client-side.

On Wed, Feb 13, 2013 at 2:20 PM, Michael Beller  wrote:
> this stores dates in UTC but displays date in alternate timezone.  You can
> set the represent property based on a timezone stored in the users profile
> or derived from locale settings ...
>
> from pytz import timezone
> import pytz
>
> db.define_table('t_date',
> Field('f_name'),
> Field('f_datetime', type='datetime', default=request.utcnow),
> Field('f_utcdatetime', type='datetime', default=request.utcnow),
> migrate=True)
>
> db.t_date.f_datetime.represent = lambda value, row :
> pytz.UTC.localize(value).astimezone(timezone('US/Eastern'))
>
>
> I used information in the following two pages for help ...
>
> http://stackoverflow.com/questions/7065164/how-to-make-an-unaware-datetime-timezone-aware-in-python?lq=1
> http://pypi.python.org/pypi/pytz/
>
> On Tuesday, February 12, 2013 7:40:59 AM UTC-5, Michael Beller wrote:
>>
>> I've also been researching and experimenting ...
>>
>> I've come to the conclusion to only store utc dates (e.g., using utcnow)
>> in the data base and then use .represent or other means to convert for
>> display.
>>
>> Most notably, use the putz python library ...
>>
>>
>> On Tuesday, February 12, 2013 1:58:26 AM UTC-5, rochacbruno wrote:
>>>
>>> I am on mobile now and I cant ellaborate a good code example, but I can
>>> give you a hint.
>>>
>>> db.table.datefield.represent = lambda value, row :
>>> value.strftime("%Y/%m/%d")
>>>
>>> grid = SQLFORM.grid(db.table)
>>>
>>> so grid will use the represent callback to display the data.
>>>
>>> following this example you can do
>>>
>>> def set_timezone(value, row):
>>>  return value. #do the calculation
>>>
>>> db.table.field.represent = set_timezone
>>>
>>> Em 12/02/2013 04:44, "newbie"  escreveu:


 On Tuesday, 12 February 2013 11:06:00 UTC+5:30, newbie wrote:
>
> Hi,
> I have a table x, with fields name,place,timezone_offset.And
> another table y ,having  field 'servertime',which stores the current time 
> of
> the server its fetching the values from.
>
>
> db.define_table('x',Field('name'),Field('place'),Field('timezone_offset'))
> db.define_table('y',Field('name'),Field('servertime'))


 User will set the timezone offset in table x, for a particular name.
 There is one thread continuously running in background in the server which
 will save the servertime as local time using datetime.datetime.now() in
 table y for the name.

 And finally this data displayed by using SQLFORM.grid on the UI.

 Problem facing:
 We have to convert the local time saved for the name field as per saved
 timezone_offset in x table and display on the grid without modifying
 anything on database level.
 It means suppose for name ='Alex'  timezone_offset was being saved as -5
 in x table and suppose server running on different timezone lets say on
 +5.30 so for name Alex server will save the servertime in +5.30 format as 
 it
 is the local time for the server but when it will be displayed on the grid
 servertime should first get converted to Alex timezone_offset which is set
 as -5 and then display on the grid.

 Can anyone please suggest me how can I achieved in web2py? Is there any
 way to achieve it using SQLFORM.grid()?

 Thanks.



>
>

 --

 ---
 You received this message because you are subscribed to the Google
 Groups "web2py-users" group.
 To unsubscribe from this group and stop receiving emails from it, send
 an email to web2py+un...@googlegroups.com.
 For more options, visit https://groups.google.com/groups/opt_out.


>
> --
>
> ---
> You received this message because you are subscribed to the Google Groups
> "web2py-users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to web2py+unsubscr...@googlegroups.com.
> For more options, visit https://groups.google.com/groups/opt_out.
>
>

-- 

--- 
You received this message because you are subscribed to the Google Groups 
"web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.




Re: [web2py] Re: Converting Field of a SQLFORM.grid to local timezone of a user.....

2013-02-12 Thread Michael Beller
this stores dates in UTC but displays date in alternate timezone.  You can 
set the represent property based on a timezone stored in the users profile 
or derived from locale settings ...

from pytz import timezone
import pytz

db.define_table('t_date',
Field('f_name'),
Field('f_datetime', type='datetime', default=request.utcnow),
Field('f_utcdatetime', type='datetime', default=request.utcnow),
migrate=True)

db.t_date.f_datetime.represent = lambda value, row : 
pytz.UTC.localize(value).astimezone(timezone('US/Eastern'))


I used information in the following two pages for help ...

http://stackoverflow.com/questions/7065164/how-to-make-an-unaware-datetime-timezone-aware-in-python?lq=1
http://pypi.python.org/pypi/pytz/

On Tuesday, February 12, 2013 7:40:59 AM UTC-5, Michael Beller wrote:
>
> I've also been researching and experimenting ...
>
> I've come to the conclusion to only store utc dates (e.g., using utcnow) 
> in the data base and then use .represent or other means to convert for 
> display.
>
> Most notably, use the putz python library ...
>
> On Tuesday, February 12, 2013 1:58:26 AM UTC-5, rochacbruno wrote:
>>
>> I am on mobile now and I cant ellaborate a good code example, but I can 
>> give you a hint.
>>
>> db.table.datefield.represent = lambda value, row : 
>> value.strftime("%Y/%m/%d")
>>
>> grid = SQLFORM.grid(db.table)
>>
>> so grid will use the represent callback to display the data.
>>
>> following this example you can do
>>
>> def set_timezone(value, row):
>>  return value. #do the calculation
>>
>> db.table.field.represent = set_timezone
>> Em 12/02/2013 04:44, "newbie"  escreveu:
>>
>>>
>>> On Tuesday, 12 February 2013 11:06:00 UTC+5:30, newbie wrote: 

 Hi,
 I have a table x, with fields name,place,timezone_offset.And 
 another table y ,having  field 'servertime',which **stores the current 
 time of the server its fetching the values from.
  
  db.define_table('x',Field('**name'),Field('place'),Field('**
 timezone_offset')) 
 db.define_table('y',Field('**name'),Field('ser**vertime'))  

>>>  
>>> User will set the timezone offset in table x, for a particular name. 
>>> There is one thread continuously running in background in the server which 
>>> will save the servertime as local time using datetime.datetime.now() in 
>>> table y for the name.
>>>  
>>> And finally this data displayed by using SQLFORM.grid on the UI.
>>>  
>>> Problem facing:
>>> We have to convert the local time saved for the name field as per saved 
>>> timezone_offset in x table and display on the grid without modifying 
>>> anything on database level.
>>> It means suppose for name ='Alex'  timezone_offset was being saved as -5 
>>> in x table and suppose server running on different timezone lets say on 
>>> +5.30 so for name Alex server will save the servertime in +5.30 format as 
>>> it is the local time for the server but when it will be displayed on the 
>>> grid servertime should first get converted to Alex timezone_offset which is 
>>> set as -5 and then display on the grid.
>>>  
>>> Can anyone please suggest me how can I achieved in web2py? Is there any 
>>> way to achieve it using SQLFORM.grid()?
>>>  
>>> Thanks.
>>>  
>>>  
>>>  
>>>
   

>>>  -- 
>>>  
>>> --- 
>>> You received this message because you are subscribed to the Google 
>>> Groups "web2py-users" group.
>>> To unsubscribe from this group and stop receiving emails from it, send 
>>> an email to web2py+un...@googlegroups.com.
>>> For more options, visit https://groups.google.com/groups/opt_out.
>>>  
>>>  
>>>
>>

-- 

--- 
You received this message because you are subscribed to the Google Groups 
"web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.




Re: [web2py] Re: Converting Field of a SQLFORM.grid to local timezone of a user.....

2013-02-12 Thread Michael Beller
I've also been researching and experimenting ...

I've come to the conclusion to only store utc dates (e.g., using utcnow) in 
the data base and then use .represent or other means to convert for display.

Most notably, use the locale python library 
(http://docs.python.org/2/library/locale.html) which can set the users 
local based on their browser settings and display times in their local 
timezone.  However, this is not reliable since the browser locale might not 
be set correctly but that's where you can use their locale or offset store 
in their user profile.

On Tuesday, February 12, 2013 1:58:26 AM UTC-5, rochacbruno wrote:
>
> I am on mobile now and I cant ellaborate a good code example, but I can 
> give you a hint.
>
> db.table.datefield.represent = lambda value, row : 
> value.strftime("%Y/%m/%d")
>
> grid = SQLFORM.grid(db.table)
>
> so grid will use the represent callback to display the data.
>
> following this example you can do
>
> def set_timezone(value, row):
>  return value. #do the calculation
>
> db.table.field.represent = set_timezone
> Em 12/02/2013 04:44, "newbie" > escreveu:
>
>>
>> On Tuesday, 12 February 2013 11:06:00 UTC+5:30, newbie wrote: 
>>>
>>> Hi,
>>> I have a table x, with fields name,place,timezone_offset.And another 
>>> table y ,having  field 'servertime',which **stores the current time of 
>>> the server its fetching the values from.
>>>  
>>>  db.define_table('x',Field('**name'),Field('place'),Field('**
>>> timezone_offset')) 
>>> db.define_table('y',Field('**name'),Field('ser**vertime'))  
>>>
>>  
>> User will set the timezone offset in table x, for a particular name. 
>> There is one thread continuously running in background in the server which 
>> will save the servertime as local time using datetime.datetime.now() in 
>> table y for the name.
>>  
>> And finally this data displayed by using SQLFORM.grid on the UI.
>>  
>> Problem facing:
>> We have to convert the local time saved for the name field as per saved 
>> timezone_offset in x table and display on the grid without modifying 
>> anything on database level.
>> It means suppose for name ='Alex'  timezone_offset was being saved as -5 
>> in x table and suppose server running on different timezone lets say on 
>> +5.30 so for name Alex server will save the servertime in +5.30 format as 
>> it is the local time for the server but when it will be displayed on the 
>> grid servertime should first get converted to Alex timezone_offset which is 
>> set as -5 and then display on the grid.
>>  
>> Can anyone please suggest me how can I achieved in web2py? Is there any 
>> way to achieve it using SQLFORM.grid()?
>>  
>> Thanks.
>>  
>>  
>>  
>>
>>>   
>>>
>>  -- 
>>  
>> --- 
>> You received this message because you are subscribed to the Google Groups 
>> "web2py-users" group.
>> To unsubscribe from this group and stop receiving emails from it, send an 
>> email to web2py+un...@googlegroups.com .
>> For more options, visit https://groups.google.com/groups/opt_out.
>>  
>>  
>>
>

-- 

--- 
You received this message because you are subscribed to the Google Groups 
"web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.




Re: [web2py] Re: Converting Field of a SQLFORM.grid to local timezone of a user.....

2013-02-11 Thread Bruno Rocha
I am on mobile now and I cant ellaborate a good code example, but I can
give you a hint.

db.table.datefield.represent = lambda value, row :
value.strftime("%Y/%m/%d")

grid = SQLFORM.grid(db.table)

so grid will use the represent callback to display the data.

following this example you can do

def set_timezone(value, row):
 return value. #do the calculation

db.table.field.represent = set_timezone
Em 12/02/2013 04:44, "newbie"  escreveu:

>
> On Tuesday, 12 February 2013 11:06:00 UTC+5:30, newbie wrote:
>>
>> Hi,
>> I have a table x, with fields name,place,timezone_offset.And another
>> table y ,having  field 'servertime',which **stores the current time of
>> the server its fetching the values from.
>>
>>  db.define_table('x',Field('**name'),Field('place'),Field('**
>> timezone_offset'))
>> db.define_table('y',Field('**name'),Field('ser**vertime'))
>>
>
> User will set the timezone offset in table x, for a particular name. There
> is one thread continuously running in background in the server which will
> save the servertime as local time using datetime.datetime.now() in table y
> for the name.
>
> And finally this data displayed by using SQLFORM.grid on the UI.
>
> Problem facing:
> We have to convert the local time saved for the name field as per saved
> timezone_offset in x table and display on the grid without modifying
> anything on database level.
> It means suppose for name ='Alex'  timezone_offset was being saved as -5
> in x table and suppose server running on different timezone lets say on
> +5.30 so for name Alex server will save the servertime in +5.30 format as
> it is the local time for the server but when it will be displayed on the
> grid servertime should first get converted to Alex timezone_offset which is
> set as -5 and then display on the grid.
>
> Can anyone please suggest me how can I achieved in web2py? Is there any
> way to achieve it using SQLFORM.grid()?
>
> Thanks.
>
>
>
>
>>
>>
>  --
>
> ---
> You received this message because you are subscribed to the Google Groups
> "web2py-users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to web2py+unsubscr...@googlegroups.com.
> For more options, visit https://groups.google.com/groups/opt_out.
>
>
>

-- 

--- 
You received this message because you are subscribed to the Google Groups 
"web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.




[web2py] Re: Converting Field of a SQLFORM.grid to local timezone of a user.....

2013-02-11 Thread newbie

On Tuesday, 12 February 2013 11:06:00 UTC+5:30, newbie wrote: 
>
> Hi,
> I have a table x, with fields name,place,timezone_offset.And another 
> table y ,having  field 'servertime',which stores the current time of the 
> server its fetching the values from.
>  
>  db.define_table('x',Field('name'),Field('place'),Field('timezone_offset'
> )) 
> db.define_table('y',Field('name'),Field('servertime'))  
>
 
User will set the timezone offset in table x, for a particular name. There 
is one thread continuously running in background in the server which will 
save the servertime as local time using datetime.datetime.now() in table y 
for the name.
 
And finally this data displayed by using SQLFORM.grid on the UI.
 
Problem facing:
We have to convert the local time saved for the name field as per saved 
timezone_offset in x table and display on the grid without modifying 
anything on database level.
It means suppose for name ='Alex'  timezone_offset was being saved as -5 in 
x table and suppose server running on different timezone lets say on +5.30 
so for name Alex server will save the servertime in +5.30 format as it is 
the local time for the server but when it will be displayed on the 
grid servertime should first get converted to Alex timezone_offset which is 
set as -5 and then display on the grid.
 
Can anyone please suggest me how can I achieved in web2py? Is there any way 
to achieve it using SQLFORM.grid()?
 
Thanks.
 
 
 

>   
>

-- 

--- 
You received this message because you are subscribed to the Google Groups 
"web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.