Can we use "represent" callback in case of hugh number of rows(lets say
20000 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 20000 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 <mjbel...@gmail.com> 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" <neha...@gmail.com> 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<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.


Reply via email to