Thanks Massimo.
It works but the main problem still the same. I cannot call field
properties (I don't know if it's the right term).
For example in the loop if I call for a datetime:
for event in events:
item = {
"type": "Feature",
"properties": {
"description": "Event date: " + str(event[db.events.
event_datetime]),
},
"geometry": loads_json(event[db.events.geometry.
st_asgeojson()])
}
Description is: Event date: 2017-01-10 09:00:00
If I would like to extract the day from the datetime, ticket is <type
'exceptions.KeyError'>:
for event in events:
item = {
"type": "Feature",
"properties": {
"description": "Event date: " + str(event[db.events.
event_datetime.day]),
},
"geometry": loads_json(event[db.events.geometry.
st_asgeojson()])
}
Perhaps it's due to the fact that I ask to the DAL a field value calling it
by db.table.field, and db.events.event_datetime.day is not a field.
But how can I do it?
Calling event.event_datetime.day don't works anymore. Ticket is <type
'exceptions.AttributeError'>.
Thanks.
Il giorno lunedì 19 settembre 2016 05:05:22 UTC+2, Massimo Di Pierro ha
scritto:
>
> How about this?
>
> features = []
> for event in events:
> link = A(event[db.events.title], _href=URL('default', 'event_page',
> vars=dict(event_id=event[db.events.id]))).xml()
> item = {
> "type": "Feature",
> "popupContent": link,
> "track_quotation": str(event[db.events.track_quotation]),
> "geometry": loads_json(event[db.events.geometry.st_asgeojson()])
> }
> features.append(item)
>
>
>
>
>
> On Saturday, 17 September 2016 12:57:29 UTC-5, Gael Princivalle wrote:
>>
>> Someone have an idea?
>>
>> Here is the code that works:
>> features= [{"type": "Feature",
>> "properties": {
>> "popupContent": "<a href='" + URL('default',
>> 'event_page', vars=dict(event_id=event[db.events.id])) + "'>" +
>> event[db.events.title] + "</a>",
>> "track_quotation":
>> str(event[db.events.track_quotation])
>> },
>> "geometry":
>> loads_json(event[db.events.geometry.st_asgeojson()])} for event in events]
>>
>> But I would like to traduce it in a loop like that:
>> for event in events:
>> ...
>>
>> Il giorno martedì 13 settembre 2016 15:36:32 UTC+2, Gael Princivalle ha
>> scritto:
>>>
>>> Hello.
>>>
>>> Can someone explain me why when I use this set of rows:
>>> events= db(db.events.id>0).select(db.events.id, db.events.title,
>>> db.events.geometry.st_asgeojson())
>>> I can't call my rows with event.title but with event[db.events.title] ?
>>>
>>> It's a problem because if I would like to call for a reference field
>>> like event[db.events.category.category_name] ticket is wrong attribute.
>>>
>>> Thanks.
>>>
>>>
--
Resources:
- http://web2py.com
- http://web2py.com/book (Documentation)
- http://github.com/web2py/web2py (Source code)
- https://code.google.com/p/web2py/issues/list (Report Issues)
---
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 [email protected].
For more options, visit https://groups.google.com/d/optout.