[web2py] Re: SQLFORM.factory upload field can't show link

2016-02-28 Thread killzane
So if I have this field in db.project
Field('project_pdf', 'upload', label='Project PDF', comment='', uploadfolder
='app/uploads'),

I must change to 
Field('project_pdf', 'upload', label='Project PDF', comment='', uploadfolder
='app/uploads', default=''),
what content should I put in "default" attribute?
the file name? or folder path?
records have same folder path but different file name.

Even if I change "form.var.project_pdf", the link button won't appear?


Anthony於 2016年2月29日星期一 UTC+8上午8時51分27秒寫道:
>
> The widget gets created when the form is initialized, so if you want to 
> specify a value for the file URL, you should do it by setting the "default" 
> attribute of the upload field in the db.project table *before* creating 
> the table.
>
> Anthony
>
> On Sunday, February 28, 2016 at 10:07:28 AM UTC-5, killzane wrote:
>>
>> I want to modify a record from db.project, and there are a reference 
>> field in db.project.
>> So I use SQLFORM.factory to add field to put reference list name.
>>
>> the code I paste is simplify version
>> here is full code
>> project = db((db.project.id == 1) & (db.frature.project_id == 
>> 1)).select(db.project.ALL, db.feature.ALL).first()
>>
>> form = SQLFORM.factory(Field('list_name', 'string', label='List Name'), 
>> db.project, db.feature, table_name='project',upload=URL('download'))
>>
>> for t in [db.project, db.project_feature]:
>>   query = t.id == project.id if t == db.project else t.project_id == 
>> project.id
>>   __copydata(db(query).select(limitby=(0,1)).first(), form.vars, 
>> t.fields)
>>
>> so, that me ask another question:
>> How to make SQLFORM.widgets.upload.widget work.
>> I mean make the link button appear.
>> what content I need to put in form.var?
>>
>> Anthony於 2016年2月28日星期日 UTC+8下午9時29分52秒寫道:
>>>
>>> Sorry, still not clear what you are trying to do, and you have not 
>>> explained why you are iterating over the Fields of the db.project table.
>>>
>>> On Sunday, February 28, 2016 at 3:48:26 AM UTC-5, killzane wrote:

 Because I want to add other field to the form so I use SQLFORM.factory.

 And this is my __copydata method
 def __copydata(src, dest, fields):
 if src:
 for k in fields:
 if src.has_key(k):
 dest[k] = src[k]
 return dict()



 Anthony於 2016年2月26日星期五 UTC+8下午9時08分13秒寫道:
>
>
> for t in db.project:
>> query = (t.id == request.vars.id) 
>> __copydata(db(query).select(limitby=(0,1)).first(), form.vars, 
>> t.fields)
>>
>
> The above is confusing and cannot be the actual code, as it would 
> raise an exception. When you iterate over db.project, you get its Field 
> objects (so each value of "t" is a Field object). Field objects do not 
> have 
> ".id" or ".fields" attributes, so both of the next two lines would result 
> in errors. Perhaps you instead mean to be iterating over Table objects, 
> but 
> it's not clear why you would be doing that, as the form is based on just 
> a 
> single table.
>
> Anthony
>


-- 
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 web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[web2py] Join subqueries

2016-02-28 Thread Bill Black
SELECT a.*,b.num_passed
  FROM (SELECT q.id,q.name,count(t.id) AS num_q
FROM quiz AS q
  JOIN question AS t ON q.id=t.quiz_id GROUP BY q.id)
AS a
  JOIN (SELECT quiz_id,count(passed) AS num_passed FROM result GROUP BY 
quiz_id)
AS b ON a.id=b.quiz_id;
I need to join these two selects.
I've spent all morning trying to get it to work in dal. But I don't think 
it can be done...
Just posting here in case there is a way to do this before resorting to 
executesql.
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 web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[web2py] Re: SQLFORM.factory upload field can't show link

2016-02-28 Thread Anthony
The widget gets created when the form is initialized, so if you want to 
specify a value for the file URL, you should do it by setting the "default" 
attribute of the upload field in the db.project table *before* creating the 
table.

Anthony

On Sunday, February 28, 2016 at 10:07:28 AM UTC-5, killzane wrote:
>
> I want to modify a record from db.project, and there are a reference field 
> in db.project.
> So I use SQLFORM.factory to add field to put reference list name.
>
> the code I paste is simplify version
> here is full code
> project = db((db.project.id == 1) & (db.frature.project_id == 
> 1)).select(db.project.ALL, db.feature.ALL).first()
>
> form = SQLFORM.factory(Field('list_name', 'string', label='List Name'), db
> .project, db.feature, table_name='project',upload=URL('download'))
>
> for t in [db.project, db.project_feature]:
>   query = t.id == project.id if t == db.project else t.project_id == 
> project.id
>   __copydata(db(query).select(limitby=(0,1)).first(), form.vars, t.fields)
>
> so, that me ask another question:
> How to make SQLFORM.widgets.upload.widget work.
> I mean make the link button appear.
> what content I need to put in form.var?
>
> Anthony於 2016年2月28日星期日 UTC+8下午9時29分52秒寫道:
>>
>> Sorry, still not clear what you are trying to do, and you have not 
>> explained why you are iterating over the Fields of the db.project table.
>>
>> On Sunday, February 28, 2016 at 3:48:26 AM UTC-5, killzane wrote:
>>>
>>> Because I want to add other field to the form so I use SQLFORM.factory.
>>>
>>> And this is my __copydata method
>>> def __copydata(src, dest, fields):
>>> if src:
>>> for k in fields:
>>> if src.has_key(k):
>>> dest[k] = src[k]
>>> return dict()
>>>
>>>
>>>
>>> Anthony於 2016年2月26日星期五 UTC+8下午9時08分13秒寫道:


 for t in db.project:
> query = (t.id == request.vars.id) 
> __copydata(db(query).select(limitby=(0,1)).first(), form.vars, 
> t.fields)
>

 The above is confusing and cannot be the actual code, as it would raise 
 an exception. When you iterate over db.project, you get its Field objects 
 (so each value of "t" is a Field object). Field objects do not have ".id" 
 or ".fields" attributes, so both of the next two lines would result in 
 errors. Perhaps you instead mean to be iterating over Table objects, but 
 it's not clear why you would be doing that, as the form is based on just a 
 single table.

 Anthony

>>>

-- 
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 web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[web2py] Re: How to disable cache on client side, but keep it on server side?

2016-02-28 Thread Anthony
Looking at the code, it does not appear it is possible to turn off client 
side caching when using @cache.action. However, if you don't want 
client-side caching, you might as well just use @cache.ram.

Anthony

On Sunday, February 28, 2016 at 3:39:08 PM UTC-5, Krzysztof Socha wrote:
>
> I have a page that is sometimes (not very often) updated. The default view 
> is quite complex, so caching it in RAM significantly improves performance. 
> However, if I try to cache it in RAM using something like:
>
> @cache.action(time_expire=3600, cache_model=cache.ram, prefix='index')
>
> the browser serves the locally cached version even if the content changes 
> and I clear the cache by:
>
> cache.ram.clear('index*')
>
> Is there a way to disable browser cache, but keep server cache? The book 
> says that cache.action: "will do one or another or *both*"  So how do I 
> just do the server-side caching without client-side?
>
> This is probably something obvious, but I cannot figure it out for a while 
> now... any hints greatly appreciated.
>
> Cheers,
> Krzysztof.
>

-- 
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 web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[web2py] Re: error : socket.gethostbyname(http_host)] : gaierror: [Errno -2] Name or service not known

2016-02-28 Thread Rufus
I installed web2py on a remote ubuntu server 14.04 with Webmin package from 
APT function and the same error is happening for me.
I'll print the contents of http_host to check the value.

 Never mind, I just saw the APT function installed web2py 1.99.7 
(2012-03-04).   I imagine a couple things have changed since then.

reinstalling web2py


On Monday, July 16, 2012 at 5:25:01 PM UTC-4, Carlos wrote:
>
> Hi,
>
> Every now and then, I see the following error in my server logs:
>  
>  ERROR:web2py:Traceback (most recent call last):
>  File "/home/www-data/web2py/gluon/main.py", line 401, in wsgibase
>socket.gethostbyname(http_host)]
>gaierror: [Errno -2] Name or service not known
>
> So far today I'm getting 10+ of these errors (although not from any of my 
> requests, but other users').
>
> How can this error be fixed?.
>
> I'm using latest web2py, ubuntu 10.04, postgresql, nginx, uwsgi-python.
>
> Thanks,
>
>Carlos
>
>

-- 
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 web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[web2py] Re: constraints

2016-02-28 Thread Mark Graves
db.define_table('table_1_name',
Field('field_1_name','string'))

db.define_table('table_2_name',
Field('table_1_reference_field','reference table_1_name'))

It looks like you defined the field as an integer field and then are 
attempting to redefine it as a reference field.

-Mark

On Sunday, February 28, 2016 at 12:23:24 PM UTC-6, prashant joshi wrote:
>
>
>
> On Sunday, February 28, 2016 at 11:50:58 PM UTC+5:30, prashant joshi wrote:
>>
>> how to conecting table??
>> how to use refernce??
>>
>  
>  *Field('sid','integer', 'reference stud_person')*
> i use this
> it is correct???
>

-- 
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 web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[web2py] How to disable cache on client side, but keep it on server side?

2016-02-28 Thread Krzysztof Socha
I have a page that is sometimes (not very often) updated. The default view 
is quite complex, so caching it in RAM significantly improves performance. 
However, if I try to cache it in RAM using something like:

@cache.action(time_expire=3600, cache_model=cache.ram, prefix='index')

the browser serves the locally cached version even if the content changes 
and I clear the cache by:

cache.ram.clear('index*')

Is there a way to disable browser cache, but keep server cache? The book 
says that cache.action: "will do one or another or *both*"  So how do I 
just do the server-side caching without client-side?

This is probably something obvious, but I cannot figure it out for a while 
now... any hints greatly appreciated.

Cheers,
Krzysztof.

-- 
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 web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[web2py] Re: list-:string field and ajax

2016-02-28 Thread Niphlod
definitely your own widget with your own javascript. the default one has no 
such capability.

On Sunday, February 28, 2016 at 7:32:40 PM UTC+1, Pierre wrote:
>
> Hi everyone,
>
> trying to figure out how to return to server individual list:string 
> element(s) when form-errors occurs and the view knows what element(s) 
> caused error(s).
> Is this a job for web2py ajax /Jquery $ajax/ or a far-fetched idea ?
>

-- 
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 web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[web2py] Re: DAL: query using JSON field

2016-02-28 Thread Val K
Thank you  Anthony for your reply!
 In fact, I don't store data in json, I use it  in views only. I mean 
something like:

SELECT  person.id, person.name, row_to_json(alias.*) as person_alias FROM 
person, alias WHERE  person.id = alias.person_id
 
I've found yet another  solution - I can create a dummy view  just for query 
 using  alias field:
 
SELECT  person.id, person.name, alias.id, alias.alias  FROM person, alias 
WHERE  person.id = alias.person_id

and make the trick:

ids_select_query = db(db.dummy_vw.alias == v &/| any_extra_query )._select(
db.dummy_vw.person.id) # note _select()  - just SQL-string, no DB-processing

rows = db(db.person_vw.id.belongs(ids_select_query)).select()







On Sunday, February 28, 2016 at 4:53:06 PM UTC+3, Anthony wrote:
>
> Most databases do not have native JSON types with the ability to query 
> within the JSON columns, so the DAL does not include that functionality -- 
> it just stores and retrieves the JSON.
>
> You should be able to construct the appropriate Postgres WHERE clause 
> manually and submit that as the query:
>
> db('JSON where clause').select(db.table.ALL)
>
> Note, do not include "WHERE" in the query -- the DAL will add that. Also, 
> because this query is opaque to the DAL, you must specify fields to select 
> in the .select() call so the DAL knows what table to query.
>
> Anthony
>
> On Sunday, February 28, 2016 at 7:56:21 AM UTC-5, Val K wrote:
>>
>> Hi!
>> Is there any way to produce query using JSON field?
>> It seems that web2py  treats args  of  that query as string:
>> db(db.tabl.json_fld==[1])._select() - "... WHERE tabl.json_fld=='[1]'"
>> db(db.tabl.json_fld[0]==1)._select() - "... WHERE 
>> (SUBSTR(tabl.json_fld,1,(2 - 1)) = '1')"
>>
>> I use PostgreSQL and I have to force Postgres to hold JSON as plane text?
>>
>>
>>

-- 
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 web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[web2py] list-:string field and ajax

2016-02-28 Thread Pierre
Hi everyone,

trying to figure out how to return to server individual list:string 
element(s) when form-errors occurs and the view knows what element(s) 
caused error(s).
Is this a job for web2py ajax /Jquery $ajax/ or a far-fetched idea ?

-- 
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 web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[web2py] Re: constraints

2016-02-28 Thread prashant joshi


On Sunday, February 28, 2016 at 11:50:58 PM UTC+5:30, prashant joshi wrote:
>
> how to conecting table??
> how to use refernce??
>
 
 *Field('sid','integer', 'reference stud_person')*
i use this
it is correct???

-- 
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 web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [web2py] My session.counter is not counting

2016-02-28 Thread Kiran Subbaraman

Joe,
Glad the issue is sorted out.
If you haven't already, I suggest you also take a look at the web2py 
book's 'Session' section: 
http://web2py.com/books/default/chapter/29/04/the-core#session



Kiran Subbaraman
http://subbaraman.wordpress.com/about/

On Sat, 27-02-2016 7:36 PM, Joe wrote:

Hello Kiran,

Yes, I know I wont be able to track the total number of clicks across 
all users. I want to serve a targeted ad banner to a user based on 
which category of images he or she clicks the most. In other words, 
different users will see different banners based on their individual 
likes or dislikes.


Thank you so much for helping me with this. I appreciate your answer. 
*Your solution works perfectly*. My problem is solved now and I 
learned something about session variables.


Thanks again.

Cheers,

Joe

On Saturday, February 27, 2016 at 7:20:25 PM UTC+8, Kiran Subbaraman 
wrote:


So you want to keep track of the number of a times a user (in a
user's session) clicked on the images 1 to 3. Using a session to
capture this count, you won't be able to track the total number of
clicks across all users (just saying)

My understanding is:
* the url comes in as 'show/some_number'
* you use the the 'some_number' to query the database for a
matching 'image'.

The changes you would need to make are:
if image.id  == 1:
session.one_counter = (session.one_counter or 0) + 1
if image.id  == 2:
...


Kiran Subbaraman
http://subbaraman.wordpress.com/about/


On Sat, 27-02-2016 10:37 AM, Joe wrote:

Hi Kiran,
Thanks very much for your reply.
I tried to
initialize session.one_counter/two_counter/three_counter but it
seems my understanding of the session variables in this case is
not sufficient to get this right.
Basically, I am stuck with this one.
My aim is to count the clicks to image.id  *1*,
image.id  *2* and image.id  *3*
separately, so I can compare them.
If you could guide me in the right direction so I can have a
better understanding and solve this problem or if you could
correct my code, I would really appreciate it.
Thanks again.
Cheers,
Joe On Saturday, February 27, 2016 at 12:31:11 PM UTC+8, Kiran
Subbaraman wrote:

You seem to be incrementing 'counter' in the session (the
counter is user session specific then). Also, you are using
session.one_counter/two_counter/three_counter, without having
initialized it. Is that a typo?


Kiran Subbaraman
http://subbaraman.wordpress.com/about/


On Sat, 27-02-2016 6:35 AM, Joe wrote:

I am trying to use session.counter to count clicks on images
on a page.
My problem is that my session.counter is not counting...
I am doing something wrong, not sure exactly what.
I am pretty sure the issue is the/if image.id
 == 1/
I'd appreciate some help with this.
*Controller:*
def index():
images = db().select(db.image.ALL, orderby=db.image.id
)
return dict(images=images)
def show():
image = db.image(request.args(0,cast=int)) or
redirect(URL('index'))
one_counter = []
two_counter = []
three_counter = []
if image.id  == 1:
session.counter = (session.counter or 0)+1
one_counter=session.one_counter
elif image.id  == 2:
session.counter = (session.counter or 0)+1
two_counter=session.two_counter
elif image.id  == 3:
session.counter = (session.counter or 0)+1
three_counter=session.three_counter
return dict(image=image)
def download():
return response.download(request, db)
*View:*
show:
{{=0 if session.one_counter is None else
session.one_counter}}
{{=0 if session.two_counter is None else
session.two_counter}}
{{=0 if session.three_counter is None else
session.three_counter}}
-- 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 

[web2py] Re: Sublime Text? Plugins?

2016-02-28 Thread Andrew Buchan
As an aside, no editor or IDE will provide auto proper complete on your db 
object (e.g you type db. and it shows you your tables and just your tables, 
then db.my_table. and it shows you your fields) without a hack.

I made this https://github.com/andyhasit/web2py_intellisense to provide 
auto complete for IDEs which take their suggestion by understanding Python 
code, and it works perfectly in PyScripter. 

I'm not sure how Sublime picks up it's auto complete suggestions, and I 
suspect it isn't by looking into classes but rather by words in files.
If you can find out how the rules work, and borrow the code/ideas from my 
web2py_intellisense (which simply generates a fake db as an object with 
fields corresponding to the table names) then you might be able to create a 
dummy file which brings up the correct suggestions when you type "db." in 
Sublime, and get way better auto-completion support :-)

I'd be interested to see if this is possible...

-- 
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 web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[web2py] Re: SQLFORM.factory upload field can't show link

2016-02-28 Thread killzane
I want to modify a record from db.project, and there are a reference field 
in db.project.
So I use SQLFORM.factory to add field to put reference list name.

the code I paste is simplify version
here is full code
form = SQLFORM.factory(Field('list_name', 'string', label='List Name'), db.
project, db.feature, table_name='project',upload=URL('download'))

for t in [db.project, db.project_feature]:
query = t.id == project.id if t == db.project else t.project_id == 
project.id
__copydata(db(query).select(limitby=(0,1)).first(), form.vars, t.fields)



Anthony於 2016年2月28日星期日 UTC+8下午9時29分52秒寫道:
>
> Sorry, still not clear what you are trying to do, and you have not 
> explained why you are iterating over the Fields of the db.project table.
>
> On Sunday, February 28, 2016 at 3:48:26 AM UTC-5, killzane wrote:
>>
>> Because I want to add other field to the form so I use SQLFORM.factory.
>>
>> And this is my __copydata method
>> def __copydata(src, dest, fields):
>> if src:
>> for k in fields:
>> if src.has_key(k):
>> dest[k] = src[k]
>> return dict()
>>
>>
>>
>> Anthony於 2016年2月26日星期五 UTC+8下午9時08分13秒寫道:
>>>
>>>
>>> for t in db.project:
 query = (t.id == request.vars.id) 
 __copydata(db(query).select(limitby=(0,1)).first(), form.vars, 
 t.fields)

>>>
>>> The above is confusing and cannot be the actual code, as it would raise 
>>> an exception. When you iterate over db.project, you get its Field objects 
>>> (so each value of "t" is a Field object). Field objects do not have ".id" 
>>> or ".fields" attributes, so both of the next two lines would result in 
>>> errors. Perhaps you instead mean to be iterating over Table objects, but 
>>> it's not clear why you would be doing that, as the form is based on just a 
>>> single table.
>>>
>>> Anthony
>>>
>>

-- 
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 web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[web2py] Re: DAL: query using JSON field

2016-02-28 Thread Anthony
Most databases do not have native JSON types with the ability to query 
within the JSON columns, so the DAL does not include that functionality -- 
it just stores and retrieves the JSON.

You should be able to construct the appropriate Postgres WHERE clause 
manually and submit that as the query:

db('JSON where clause').select(db.table.ALL)

Note, do not include "WHERE" in the query -- the DAL will add that. Also, 
because this query is opaque to the DAL, you must specify fields to select 
in the .select() call so the DAL knows what table to query.

Anthony

On Sunday, February 28, 2016 at 7:56:21 AM UTC-5, Val K wrote:
>
> Hi!
> Is there any way to produce query using JSON field?
> It seems that web2py  treats args  of  that query as string:
> db(db.tabl.json_fld==[1])._select() - "... WHERE tabl.json_fld=='[1]'"
> db(db.tabl.json_fld[0]==1)._select() - "... WHERE 
> (SUBSTR(tabl.json_fld,1,(2 - 1)) = '1')"
>
> I use PostgreSQL and I have to force Postgres to hold JSON as plane text?
>
>
>

-- 
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 web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[web2py] Re: SQLFORM.factory upload field can't show link

2016-02-28 Thread Anthony
Sorry, still not clear what you are trying to do, and you have not 
explained why you are iterating over the Fields of the db.project table.

On Sunday, February 28, 2016 at 3:48:26 AM UTC-5, killzane wrote:
>
> Because I want to add other field to the form so I use SQLFORM.factory.
>
> And this is my __copydata method
> def __copydata(src, dest, fields):
> if src:
> for k in fields:
> if src.has_key(k):
> dest[k] = src[k]
> return dict()
>
>
>
> Anthony於 2016年2月26日星期五 UTC+8下午9時08分13秒寫道:
>>
>>
>> for t in db.project:
>>> query = (t.id == request.vars.id) 
>>> __copydata(db(query).select(limitby=(0,1)).first(), form.vars, 
>>> t.fields)
>>>
>>
>> The above is confusing and cannot be the actual code, as it would raise 
>> an exception. When you iterate over db.project, you get its Field objects 
>> (so each value of "t" is a Field object). Field objects do not have ".id" 
>> or ".fields" attributes, so both of the next two lines would result in 
>> errors. Perhaps you instead mean to be iterating over Table objects, but 
>> it's not clear why you would be doing that, as the form is based on just a 
>> single table.
>>
>> Anthony
>>
>

-- 
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 web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[web2py] Re: I'm struggling to get password reset links to use https not http

2016-02-28 Thread Anthony
Hmm, maybe that's not set when using IIS for some reason. I suppose you 
could always do something like this in a model:

request.env.wsgi_url_scheme = 'https'

Anthony

On Saturday, February 27, 2016 at 7:39:16 PM UTC-5, Tim Richardson wrote:
>
> I have an https app which send password reset emails as http even when the 
> user is visiting https.
> The links don't work. I think that by default, the links should use the 
> same scheme as the URL visited by the user, but this isn't happening, at 
> least for me
>
> The code base is R-2.13.4 
>
> When I look at gluon/tools.py I see that the URL is constructed with 
> scheme=True
>
> This scheme is propagated to the URL helper, which eventually arrives in 
> rewrite.py/url_out(...)
> which does this
>
> if not scheme or scheme is True:
>  scheme = request.env.get('wsgi_url_scheme', 'http').lower() \
>  if request else 'http'
>
>
> so I guess there is no key wsgi_url_scheme
>
>
> I do this in db.py so the user is guaranteed to be on an https site.
>
>
> (This server is Windows IIS 8 )
>
>
> request.requires_https()
>
>
>
>
>

-- 
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 web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[web2py] DAL: query using JSON field

2016-02-28 Thread Val K
Hi!
Is there any way to produce query using JSON field?
It seems that web2py  treats args  of  that query as string:
db(db.tabl.json_fld==[1])._select() - "... WHERE tabl.json_fld=='[1]'"
db(db.tabl.json_fld[0]==1)._select() - "... WHERE 
(SUBSTR(tabl.json_fld,1,(2 - 1)) = '1')"

I use PostgreSQL and I have to force Postgres to hold JSON as plane text?


-- 
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 web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[web2py] Re: I'm struggling to get password reset links to use https not http

2016-02-28 Thread Niphlod
it'd pretty easy to check. either you print somewhere wsgi_url_scheme or 
you include response.toolbar() to check what's being passed on.

On Sunday, February 28, 2016 at 1:39:16 AM UTC+1, Tim Richardson wrote:
>
> I have an https app which send password reset emails as http even when the 
> user is visiting https.
> The links don't work. I think that by default, the links should use the 
> same scheme as the URL visited by the user, but this isn't happening, at 
> least for me
>
> The code base is R-2.13.4 
>
> When I look at gluon/tools.py I see that the URL is constructed with 
> scheme=True
>
> This scheme is propagated to the URL helper, which eventually arrives in 
> rewrite.py/url_out(...)
> which does this
>
> if not scheme or scheme is True:
>  scheme = request.env.get('wsgi_url_scheme', 'http').lower() \
>  if request else 'http'
>
>
> so I guess there is no key wsgi_url_scheme
>
>
> I do this in db.py so the user is guaranteed to be on an https site.
>
>
> (This server is Windows IIS 8 )
>
>
> request.requires_https()
>
>
>
>
>

-- 
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 web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[web2py] Re: SQLFORM.factory upload field can't show link

2016-02-28 Thread killzane
Because I want to add other field to the form so I use SQLFORM.factory.

And this is my __copydata method
def __copydata(src, dest, fields):
if src:
for k in fields:
if src.has_key(k):
dest[k] = src[k]
return dict()



Anthony於 2016年2月26日星期五 UTC+8下午9時08分13秒寫道:
>
>
> for t in db.project:
>> query = (t.id == request.vars.id) 
>> __copydata(db(query).select(limitby=(0,1)).first(), form.vars, 
>> t.fields)
>>
>
> The above is confusing and cannot be the actual code, as it would raise an 
> exception. When you iterate over db.project, you get its Field objects (so 
> each value of "t" is a Field object). Field objects do not have ".id" or 
> ".fields" attributes, so both of the next two lines would result in errors. 
> Perhaps you instead mean to be iterating over Table objects, but it's not 
> clear why you would be doing that, as the form is based on just a single 
> table.
>
> Anthony
>

-- 
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 web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.