[web2py] Re: Custom Login View

2017-03-24 Thread Happy Rob
SOLVED

Hi Marlysson

Thanks for your help

In the end I didn't need to do any defining or anything too much.
For 1 (failed login), I put the auth settings into the controller instead 
of the model
For 2. (selecting login page) I also put the auth settings into the 
controller
For 3. (logout) I just put the logout into a separate view.

So in the end, here is the complete membership site  - yay!

To access, go to https://XX.pythonanywhere.com/c/e/b1

App: C

Model: a.py
..
db = DAL ('sqlite://storage.sqlite')
from gluon.tools import Auth
auth = Auth(db)
auth.define_tables(username=False,signature=False)
..

Controller: e.py
..
#to access, go to https://XX.pythonanywhere.com/c/e/b1

#setting stuff
auth.settings.controller = 'e'
auth.settings.on_failed_authorization = URL('e', 'b1')
auth.settings.login_url = URL('b3')

#home page
def b1():
display_page = XML('Home PageRegistrationLogin to members')
return dict(display_page = display_page)

#regn page
def b2():
display_page = XML('Registration Pageor Skip this 
page and Login to members page')
return dict(display_page = display_page, 
form=auth.register(next=URL('b4')))

#login page
def b3():
display_page = XML('Login Page')
return dict(display_page = display_page, 
form=auth.login(next=URL('b4')))

#members page
@auth.requires_login()
def b4():
display_page = XML('Members PageLogout')
return dict(display_page = display_page)

def b5():
display_page = XML('Logging Out')
return dict(display_page = display_page, 
form=auth.logout(next=URL('b1')))
..
View: e/b1
{{=display_page}}

View: e/b2
{{=display_page}}
{{=form}}

View: e/b3
{{=display_page}}
{{=form}}

View: e/b4
{{=display_page}}

View: e/b5
{{=display_page}}
{{=form}}


-- 
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] Displaying data of same date from two tables

2017-03-24 Thread Nabil Ontour
Hi, 
I want to create some small accounting program and am having some issue 
with creating a proper balance view.

I have 2 tables, one for incomes and one for expenditures, each with the 
corresponding money and the date of data entry:

db.incomes.income_USD
db.incomes.calendar_date
db.expenditures.expenditures_USD
db.expenditures.calendar_date

a) How can I create a view, that displays for example the income_USD in a 
monthly view, weekly view etc? (sum of each month,...)

b) How can I calculate the balance (income-expenditures)? My problem is, 
that sometimes, I don't have entries on one of the tables, so I cannot just 
subtract each entry.




-- 
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 make Web2py not block 'get' as well as 'post' requests from external sources?

2017-03-24 Thread Anthony
Is this in a Cordova/Phonegap app? If so, you may need to whitelist the 
web2py URL and set a content security policy. See 
https://cordova.apache.org/docs/en/latest/reference/cordova-plugin-whitelist/.

Otherwise, if it is a cross-origin request, you need to set up CORS to 
allow it.

Anthony

On Friday, March 24, 2017 at 10:10:23 AM UTC-4, Mike Stephenson wrote:
>
> $().ready(function () {
> var url = 'http://biglibrary.pythonanywhere.com/app/phonegap/temp.json';
>
>   $.get(url, function (data) {
>alert(data);
>   });
> });
>

-- 
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: validate_and_update what am I missing???

2017-03-24 Thread Anthony
On Friday, March 24, 2017 at 11:15:35 AM UTC-4, wdtnh wrote:
>
> Trying to to get the following working but for some reason getting a can't 
> use keyword in expression error.
>

Just like .update(), it should be .validate_and_update(Mobile=mobile, ...).
 

>  It's also my understanding that validate_and_update should include fields 
> that have actually changed???
>

The fields you are updating do not have to have changed.

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] RestApi

2017-03-24 Thread PK
@request.restful()
def api():
response.view = 'generic.json'
def GET(*args,**vars):
patterns = [
"/wishBoxes[wishBoxes]",
"/wishBoxes[wishBoxes]/{wishBoxes.name.startswith}",
"/boxes[Details]/{Details.Title_id}"
]
parser = db.parse_as_rest(patterns,args,vars)
if parser.status == 200:
return dict(wishBoxes=parser.response)
else:
raise HTTP(parser.status,parser.error)

how shuould i return depanding on request table name 
/api/wishBoxes which return return dict(wishBoxes=parser.response) 
/api/boxes/1 which return return dict(boxes=parser.response) 

-- 
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: Extracting values of a list from the database and using them individually in a javascript array

2017-03-24 Thread Dave S


On Tuesday, March 21, 2017 at 11:18:21 AM UTC-7, Massimo Di Pierro wrote:
>
> def form1Details():
> form = db.compForm(request.args(0))
> forms = db(db.compFormPages.formName==form.id
> ).select(db.compFormPages.ALL)
> images = [{'link':URL('download',args=form.formImage), 
> 'title':form.formTitle} for form in forms]
> return dict(images=images)
>
> the images are in variable forms so i wanna display them in my view such 
> that each picture is stored individually inside a JavaScript array for a 
> slide show like below
>
> VIEW
>
> 
> {{=ASSIGNJS(IMAGES=images)}}; // magic to convert python to JS object 
> function slideShow() {
> var images = IMAGES.map(function(i){return i.link;}); // array of links
> var descriptions= IMAGES.map(function(i){return i.title;}); // array of 
> titles
> }
> 
>
>
ASSIGNJS()  doesn't seem to be in the book; is it documented somewhere?

/dps


> On Tuesday, 21 March 2017 05:45:36 UTC-5, Cypher wrote:
>>
>> Hi guys i need help, please someone out there coz I'm pulling out my 
>> hairs at this point:
>> I want to extract pictures from within a list extracted from the database 
>> and store them inside a JavaScript array for a slide show.
>>
>>
>> *CONTROLLER:*
>>
>>
>>
>>
>> *def form1Details():form=db.compForm(request.args(0))
>> forms=db(db.compFormPages.formName==form.id 
>> ).select(db.compFormPages.ALL)return locals()*the 
>> images are in variable forms so i wanna display them in my view such that 
>> each picture is stored individually inside a JavaScript array for a slide 
>> show like below
>>
>>
>> *VIEW**{{for pic in form:}}*
>>
>>
>>
>>
>>
>> *function slideShow(){images = ["{{=URL('download', 
>> args=pic.formImage)}}", "{{=URL('download', args=pic2.formImage)}}", 
>> "{{=URL('download', args=pic3.formImage)}}"];*
>>
>>
>>
>>
>>
>>
>>
>> *descriptions=['{{=pic.formTitle}}', '{{=pic2.formTitle}}', 
>> '{{=pic3.formTitle}}'];.}*How
>>  
>> do extract them individually to achieve the above, i could use all the help 
>> i could get, thank you.
>>
>

-- 
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: xml() error when BEAUTIFY globals()

2017-03-24 Thread Lars

I went for something even simpler : I bypass BEAUTIFUL.. I just wanted a 
view with everything named :
def my_beautify(component):
t = TABLE()
if isinstance(component, dict):
for k, v in component.iteritems():
if v is None or isinstance(v, (bool, str)):
t.append(TR([str(k), str(v), ' ']))
else:
t.append(TR([str(k), repr(v), str(dir(v))]))
return t

Thanks to both of you ! :)



On Friday, March 24, 2017 at 12:08:16 AM UTC+1, Anthony wrote:
>
> BEAUTIFY is not designed to take the entire global environment. The 
> problem is that globals() includes all of the web2py HTML helper classes. 
> Because BEAUTIFY is itself an HTML helper, it is serialized by recursively 
> processing its components. The serialization process checks whether a given 
> component has a callable "xml" attribute, and assuming such an attribute is 
> an instance method, it attempts to call .xml(). The problem is the helper 
> classes themselves do have a callable "xml" attribute, but it is not 
> actually an instance method in that case (it is simply an attribute that 
> belongs to the class itself) -- so calling it generates an exception.
>
> You might try something like:
>
> BEAUTIFY({k: v for k, v in globals().iteritems() if not hasattr(v, 'xml'
> )})
>
> But you're probably asking for trouble attempting to display the entire 
> global environment.
>
> 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.


Re: [web2py] Re: web2pyslices

2017-03-24 Thread Richard Vézina
For db, we can use sqlite in memory, so we don't have to keep db file with
model already defined that could make the app heavy...

Oups you mention it in the last sentence...

Richard

On Fri, Mar 24, 2017 at 11:43 AM, Carlos Costa 
wrote:

> About fiddle, I think we can easily do the view and controller part.
> But what about the other parts like models, modules, database, etc?
> Would it be really necessary or have a reliable solution?
>
> I think we could do only view, controller and model.
> For the model maybe we should have an interface to build and and fill
> sample (virtual) tables.
> But I don´t know how to do it without the need a lot of HD.
> Maybe a virtual database driver could be implemented for DAL, for runing
> small tables in memory only or simply use sqlite temporary files.
>
>
> Em terça-feira, 21 de março de 2017 16:53:16 UTC-3, Massimo Di Pierro
> escreveu:
>
>> web2pyslices is becoming hard to maintain. Right now the best solution is
>> to create a github repo and move all the recipes into issues. We will
>> deprecate by closing them. People with gihub accounts can post and comment
>> issues/recipes. Unless you have a better solution, this will be done within
>> the next week.
>>
>> One sideffect is that we will lose some information about authorship of
>> the recipes and the comments. We will add a notice "created by {...}" but
>> the {...} name will be the web2pyslices username and that may not mean
>> anything in the gihub context.
>>
>> At this I do not have a better solution but please share your thoughts.
>>
>> --
> 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.
>

-- 
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: web2pyslices

2017-03-24 Thread Carlos Costa
About fiddle, I think we can easily do the view and controller part.
But what about the other parts like models, modules, database, etc?
Would it be really necessary or have a reliable solution?

I think we could do only view, controller and model.
For the model maybe we should have an interface to build and and fill 
sample (virtual) tables.
But I don´t know how to do it without the need a lot of HD.
Maybe a virtual database driver could be implemented for DAL, for runing 
small tables in memory only or simply use sqlite temporary files.


Em terça-feira, 21 de março de 2017 16:53:16 UTC-3, Massimo Di Pierro 
escreveu:
>
> web2pyslices is becoming hard to maintain. Right now the best solution is 
> to create a github repo and move all the recipes into issues. We will 
> deprecate by closing them. People with gihub accounts can post and comment 
> issues/recipes. Unless you have a better solution, this will be done within 
> the next week.
>
> One sideffect is that we will lose some information about authorship of 
> the recipes and the comments. We will add a notice "created by {...}" but 
> the {...} name will be the web2pyslices username and that may not mean 
> anything in the gihub context.
>
> At this I do not have a better solution but please share your thoughts. 
>
>

-- 
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: web2pyslices

2017-03-24 Thread Carlos Costa
What about this: http://www.web2pyref.com/
Who owns it?
Could we migrate slices data to it?

Em terça-feira, 21 de março de 2017 16:53:16 UTC-3, Massimo Di Pierro 
escreveu:
>
> web2pyslices is becoming hard to maintain. Right now the best solution is 
> to create a github repo and move all the recipes into issues. We will 
> deprecate by closing them. People with gihub accounts can post and comment 
> issues/recipes. Unless you have a better solution, this will be done within 
> the next week.
>
> One sideffect is that we will lose some information about authorship of 
> the recipes and the comments. We will add a notice "created by {...}" but 
> the {...} name will be the web2pyslices username and that may not mean 
> anything in the gihub context.
>
> At this I do not have a better solution but please share your thoughts. 
>
>

-- 
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: inner join taking too long

2017-03-24 Thread Marlysson Silva
Show up some error on web2py's console?

Em segunda-feira, 20 de março de 2017 13:05:12 UTC-3, John Philip escreveu:
>
> Hi there,
>
> I have two tables that I have queried using an inner join the query 
> outputs about 50,000 + records this is no problem on sqlite however it does 
> not seem to load on web2py. Is there something I am doing wrong?
>
>
> import json
> def get_dpc():
> rows = 
> db(db.plf.PLF_NAME==db.pcf.PCF_NAME).select(db.plf.PLF_NAME,db.pcf.PCF_DESCR).as_list()
> return dict(dpc_list=gluon.contrib.simplejson.dumps(rows))
>
>
>
> any help would be greatly appreciated.
>
> regards,
>
> John
>

-- 
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] Re: xml() error when BEAUTIFY globals()

2017-03-24 Thread Richard Vézina
Thanks Anthony, clearer than my explanation.

Richard

On Thu, Mar 23, 2017 at 7:08 PM, Anthony  wrote:

> BEAUTIFY is not designed to take the entire global environment. The
> problem is that globals() includes all of the web2py HTML helper classes.
> Because BEAUTIFY is itself an HTML helper, it is serialized by recursively
> processing its components. The serialization process checks whether a given
> component has a callable "xml" attribute, and assuming such an attribute is
> an instance method, it attempts to call .xml(). The problem is the helper
> classes themselves do have a callable "xml" attribute, but it is not
> actually an instance method in that case (it is simply an attribute that
> belongs to the class itself) -- so calling it generates an exception.
>
> You might try something like:
>
> BEAUTIFY({k: v for k, v in globals().iteritems() if not hasattr(v, 'xml'
> )})
>
> But you're probably asking for trouble attempting to display the entire
> global environment.
>
> 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.
>

-- 
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] lazy_tables + 'reference tablename' = referenced table not lazy

2017-03-24 Thread Richard Vézina
I want also share I little tricks I found... I had some globals id
represent variables that I reuse in many part of the app... I know globals
vars is bad idea, but it the only way I found to make things DRY and fast
(caching those vars in redis) instead of redoing the same query over and
over to revocer ID representation.

So, the trick is to by pass the DAL with db.executesql() as I only need 2
fields, slicing remain managable and don't degrad to much the readability,
but it prevent many tables definitions at every request.

I could prevent those globals var, but create them only in controller that
need them, but I need those python dict also in many model definition, so...

Richard

On Fri, Mar 24, 2017 at 11:11 AM, Richard Vézina <
ml.richard.vez...@gmail.com> wrote:

> Thanks for your answer Joe...
>
> My problem though is not quite that I don't want to define linked table,
> but avoid define tables that should be lazy as they are not required in the
> context of a given html request... I have over 150 tables in my app (some
> should be merged as one as they exist cause of some original design flaw
> but time and ressources had always prevent me to do it). But many
> IS_IN_DB() validator involve db set which trigger linked table definition
> fine, but trigger also table definition at every request, on_define
> define_table() attribute is in part a solution to this problem... I suggest
> that we could use smart_query() to parse "string set" to prevent triggering
> table definition when someone need db set inside an IS_IN_DB() validator.
> But this would only work for this particular case, on_define would remain
> usefull for other cases, so it make sens to keep using it and not refactor
> IS_IN_DB(), though considering that I never needed on_define callback
> before but for db set IS_IN_DB() validator, and that it make code more
> readable and maintainable to be able to create db_set variable inside
> models files to be reused in differents validators definition for
> differents tables I guess it could worth it at least in my case.
>
> But as it not possible to define a db_set vars and reuse it I make my app
> less DRY to improve performance. If such feature come avaible later, I
> would refactor again to bring back DRYness that I had before...
>
> But you are right it always good to step back and figure out what the big
> picture.
>
> On Thu, Mar 23, 2017 at 4:59 PM, Joe Barnhart 
> wrote:
>
>> Just a couple of philosophical comments...
>>
>> Whenever I find that the web2py platform is "forcing" me to code in large
>> volumes and produce ugly, quirky code which I *know* will be hard to
>> maintain, I stop myself and take another look at how I'm trying to
>> accomplish my task.  I have this philosophy that using a platform like
>> web2py (or Python, or Linux, or anything) involves a certain mindset.
>> Those who created and maintain the platform envisioned working with it in a
>> certain way.  I call that the "swimming downstream" way of working.  When I
>> find I am "swimming upstream" I realize that I'm not using the platform as
>> intended.
>>
>> In this case, for instance, you want to instantiate one table but NOT
>> another table which is linked to this table.  That seems like a logic error
>> to me.  It looks like a FEATURE that lazy table instantiation will create
>> BOTH tables in this case -- certainly the linked table and its definition
>> should be available wherever its linker table exists.  Standing on your
>> head to get around this is "swimming upstream".
>>
>> There are numerous ways to make your site more efficient,* if efficiency
>> turns out to be a problem*.  Believe me, I get it.  I, too, am guilty of
>> "premature optimization" more often that I like to admit.  But the best
>> course of action is to steam ahead and get your application working the
>> easiest way possible (downstream swimming).  Then, and only then, locate
>> any performance trouble spots and apply optimization.  Lazy tables are only
>> one such optimization.
>>
>> You heard mention of putting tables in a module.  I have about 50 tables
>> in my app, some with 50 fields.  To instantiate all of them all of the time
>> would be somewhat of a burden.  So I have opted to put table creation in
>> modules.  If that isn't enough, I'll worry about that when I have a problem.
>>
>> Swim downstream.  It's the only way!
>>
>> -- Joe
>>
>>
>> On Monday, March 13, 2017 at 11:03:46 AM UTC-7, Richard wrote:
>>>
>>> Hello,
>>>
>>> I am analysing my app and found that many tables that I thought were
>>> lazy (lazy_tables = True) are actually not... Investigating why was that...
>>> I found (I think) that 'reference table_name' cause a table to be not be
>>> lazy anymore as mostly all table that are referenced are not lazy... There
>>> is no insight about that in the book, or I didn't find any...
>>>
>>> Is referenced tables can be lazy?
>>>
>>> I use web2py 2.14.6 build...
>>>
>>> There is old issue in pyDAL repo about reference and

[web2py] validate_and_update what am I missing???

2017-03-24 Thread wdtnh
Trying to to get the following working but for some reason getting a can't 
use keyword in expression error.  It's also my understanding that 
validate_and_update should include fields that have actually changed??? 
 Since this would be coming in as an ajax request, I'd rather not go 
through a bunch of gymnastics on the client to figure out what's changed 
and what's not change.  Any clarification would help.  Thanks in advance.

def testSQL():
leadID  = 1
mobile  = '555.555.'
email   = 't...@test.com'
website = 'www.test.com'
db(db.Leads.id==leadID).validate_and_update(db.Leads.Mobile=mobile,
db.Leads.Email=email,
db.Leads.Website=website)

recs = db(db.Leads.id==1).select(db.Leads.ALL)
rec = recs[0]
return dict(rec=rec)

-- 
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] lazy_tables + 'reference tablename' = referenced table not lazy

2017-03-24 Thread Richard Vézina
Thanks for your answer Joe...

My problem though is not quite that I don't want to define linked table,
but avoid define tables that should be lazy as they are not required in the
context of a given html request... I have over 150 tables in my app (some
should be merged as one as they exist cause of some original design flaw
but time and ressources had always prevent me to do it). But many
IS_IN_DB() validator involve db set which trigger linked table definition
fine, but trigger also table definition at every request, on_define
define_table() attribute is in part a solution to this problem... I suggest
that we could use smart_query() to parse "string set" to prevent triggering
table definition when someone need db set inside an IS_IN_DB() validator.
But this would only work for this particular case, on_define would remain
usefull for other cases, so it make sens to keep using it and not refactor
IS_IN_DB(), though considering that I never needed on_define callback
before but for db set IS_IN_DB() validator, and that it make code more
readable and maintainable to be able to create db_set variable inside
models files to be reused in differents validators definition for
differents tables I guess it could worth it at least in my case.

But as it not possible to define a db_set vars and reuse it I make my app
less DRY to improve performance. If such feature come avaible later, I
would refactor again to bring back DRYness that I had before...

But you are right it always good to step back and figure out what the big
picture.

On Thu, Mar 23, 2017 at 4:59 PM, Joe Barnhart 
wrote:

> Just a couple of philosophical comments...
>
> Whenever I find that the web2py platform is "forcing" me to code in large
> volumes and produce ugly, quirky code which I *know* will be hard to
> maintain, I stop myself and take another look at how I'm trying to
> accomplish my task.  I have this philosophy that using a platform like
> web2py (or Python, or Linux, or anything) involves a certain mindset.
> Those who created and maintain the platform envisioned working with it in a
> certain way.  I call that the "swimming downstream" way of working.  When I
> find I am "swimming upstream" I realize that I'm not using the platform as
> intended.
>
> In this case, for instance, you want to instantiate one table but NOT
> another table which is linked to this table.  That seems like a logic error
> to me.  It looks like a FEATURE that lazy table instantiation will create
> BOTH tables in this case -- certainly the linked table and its definition
> should be available wherever its linker table exists.  Standing on your
> head to get around this is "swimming upstream".
>
> There are numerous ways to make your site more efficient,* if efficiency
> turns out to be a problem*.  Believe me, I get it.  I, too, am guilty of
> "premature optimization" more often that I like to admit.  But the best
> course of action is to steam ahead and get your application working the
> easiest way possible (downstream swimming).  Then, and only then, locate
> any performance trouble spots and apply optimization.  Lazy tables are only
> one such optimization.
>
> You heard mention of putting tables in a module.  I have about 50 tables
> in my app, some with 50 fields.  To instantiate all of them all of the time
> would be somewhat of a burden.  So I have opted to put table creation in
> modules.  If that isn't enough, I'll worry about that when I have a problem.
>
> Swim downstream.  It's the only way!
>
> -- Joe
>
>
> On Monday, March 13, 2017 at 11:03:46 AM UTC-7, Richard wrote:
>>
>> Hello,
>>
>> I am analysing my app and found that many tables that I thought were lazy
>> (lazy_tables = True) are actually not... Investigating why was that... I
>> found (I think) that 'reference table_name' cause a table to be not be lazy
>> anymore as mostly all table that are referenced are not lazy... There is no
>> insight about that in the book, or I didn't find any...
>>
>> Is referenced tables can be lazy?
>>
>> I use web2py 2.14.6 build...
>>
>> There is old issue in pyDAL repo about reference and lazyness but they
>> are closed.
>>
>> Thanks
>>
>> Richard
>>
> --
> 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.
>

-- 
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 rec

[web2py] Re: How to make Web2py not block 'get' as well as 'post' requests from external sources?

2017-03-24 Thread Marlysson Silva
What's happening?

Em sexta-feira, 24 de março de 2017 11:10:23 UTC-3, Mike Stephenson 
escreveu:
>
> $().ready(function () {
> var url = 'http://biglibrary.pythonanywhere.com/app/phonegap/temp.json';
>
>   $.get(url, function (data) {
>alert(data);
>   });
> });
>

-- 
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] Re: web2pyslices

2017-03-24 Thread Richard Vézina
That what I thought, but I wasn't so sure as I never used gitter...

So let fucos over web2py-fiddle if there is some taker to make such thing
happen...

Richard

On Thu, Mar 23, 2017 at 6:15 PM, Anthony  wrote:

> There is also another things that could be done, as we had discussed that
>> in the pass I mean move away from google group... Recently there is gitter (
>> https://gitter.im/) that have been open sourced, so we could, if gitter
>> sufficient for proper web2py community communications, use it instead of
>> google group...
>>
>
> Gitter is for chat -- it would not be a good replacement for Google
> Groups. If we wanted to move off of Google Groups, something like
> Discourse, NodeBB, or Flarum would be more appropriate alternatives.
>
> 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.
>

-- 
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] Call a javascript function from SQLFORM.smartgrid

2017-03-24 Thread 'FERNANDO VILLARROEL' via web2py-users
Dear Nico.
Thank you for you answer.
I use a sqlform.smart grid for show records from database, i want to do a call 
Restful for show especific record clicked using ajax
My problem is i not know how i implement onclick function on sqlform.smart grid
Regards 

On Friday, March 24, 2017 6:20 AM, Nico de Groot  
wrote:
 

 A client-side javascript function can't be triggered by a link. You can define 
a onclick attribute containing a call to a javascript function. If you want to 
use a row id as a parameter you have to make it available as a data attribute.

It's not clear what you want and why.  Maybe you have to grasp the serverside - 
clientside concept better first. Lookup 'javascript' and play around with tools 
like jsfiddle.

Nico de Groot

-- 
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.


   

-- 
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 make Web2py not block 'get' as well as 'post' requests from external sources?

2017-03-24 Thread Mike Stephenson
$().ready(function () {
//here any https will work but below is not working because of cross origin 
..code is correct, just change url or put some json string or file
  var url = 'http://biglibrary.pythonanywhere.com/app/phonegap/temp.json';

  $.get(url, function (data) {
   alert(data);
  });
});

-- 
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: Custom Login View

2017-03-24 Thread Marlysson Silva
1. By analysing the web2py's code I find this line:

https://github.com/web2py/web2py/blob/master/gluon/tools.py#L1520


Basically you should define a url to redirect when login fails. And 
internally açthe parameter ( next=??) that you want to do.

https://github.com/web2py/web2py/blob/master/gluon/tools.py#L4309-L4311


Steps:

1.1 Search by "fail login" string.

https://github.com/web2py/web2py/blob/master/gluon/tools.py#L1520


1.2 Here it call the function call_or_redirect.

https://github.com/web2py/web2py/blob/master/gluon/tools.py#L4310


1.3 That call a function and redirect

https://github.com/web2py/web2py/blob/master/gluon/tools.py#L93


That you can pass a url in string format or a function URL() using 
parameters..

I don't was tested but I think that it so:

auth.settings.on_failed_authentication = URL("YOUR ACTION")

or

auth.settings.on_failed_authentication = "YOUR ACTION"


2. In these section have what you want.
:

> http://web2py.com/books/default/chapter/29/09/access-control#Authentication


Especifically this code:

def mylogin(): return dict(form=auth.login())
def myregister(): return dict(form=auth.register())
def myprofile(): return dict(form=auth.profile())


You can expose auth action that youself created .

3. Logout instantly?

Em quinta-feira, 23 de março de 2017 13:35:25 UTC-3, Happy Rob escreveu:
>
>
> Hi guys
> I'm trying to make a membership site but I'm struggling a little and would 
> love a little help
> # 1. How can I select where go if login fails? Can I add something next to 
> the 'next=URL' that's similar?
> # 2. How can I select so uses c/b/b3 to login instead of 
> c/default/user/login?
> # 3. When I login, it logs me out instantly - how can I not logout 
> instantly?
>
> I'm on Pythonanywhere, and I've got an app called "c"
> APP: c
> --
> MODEL: a.py...
> db = DAL ('sqlite://storage.sqlite')
> from gluon.tools import Auth
> auth = Auth(db, controller='b')
>
> auth.settings.controller = 'b'
> auth.settings.on_failed_authorization = URL('c',args='b/b3')
> auth.settings.login_url = URL(request.application, 'c', 'b3')
> auth.define_tables(username=False,signature=False)
> --
> CONTROLLER: b.py...
> #home page
> def b1():
> display_page = XML('Home Page')
> return dict(display_page = display_page)
>
> #regn page
> def b2():
> display_page = XML('Registration Page')
> return dict(display_page = display_page, 
> form=auth.register(next=URL('b3')))
>
> #login page
> def b3():
> display_page = XML('Login Page')
> return dict(display_page = display_page, 
> form=auth.login(next=URL('b4')))
> # 1. How can I select where go if login fails? Can I add something next to 
> the 'next=URL' that's similar?
>
> #members page
> @auth.requires_login()
> # 2. How can I select so uses c/b/b3 to login instead of 
> c/default/user/login?
> def b4():
> auth.settings.login_url = URL('b', 'b3')
> display_page = XML('Members Page')
> return dict(display_page = display_page, 
> form=auth.logout(next=URL('b1')))
> # 3. When I login, it logs me out instantly (and sends me to b1) - how can 
> I not logout instantly?
> --
> VIEW: b/b1.html...
> {{=display_page}}
>
> VIEW: b/b2 and b3 and b4 are the same...
> {{=display_page}}
> {{=form}}
> --
>
> Any help would be greatly appreciated - especially with question 2.
>

-- 
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] Should I modify response.headers in order to get nginx's uwsgi_cache work properly?

2017-03-24 Thread Lisandro
I'm running a web2py website with public articles, and there are ocasional 
peaks in traffic. 
I use Nginx as a webserver, and uWsgi to run my web2py application.

Considering the articles are public (the HTML page of an article is the 
same for every visitor), I'm already doing some caching in order to improve 
performance (I'm using @cache.action decorator with Redis model).
However, and please correct me if I'm wrong, for every request made to the 
URL of an article, before the caching can be done, the models need to be 
executed.
So I thought I could improve performance even more, caching the HTML 
directly from Nginx, that way I would save resources in my server.

However I'm having a hard time getting it, and I wanted to know if I should 
modify the response.headers.
I've read that they come set by default:
http://web2py.com/books/default/chapter/29/04/the-core#response

To do some tests, I have this simple web2py function:

def test():
from datetime import datetime

return datetime.now().strftime('%H:%M:%S')



In the ngin'x side, the server block configuration is this:

uwsgi_cache_path /tmp/nginx_cache/ levels=1:2 keys_zone=mycache:10m max_size
=10g inactive=10m use_temp_path=off;

server {
...

location / {
# response header to check if cache is a HIT or a MISS
add_header  X-uWSGI-Cache $upstream_cache_status;

# server cache
uwsgi_cache  mycache;
uwsgi_cache_valid  15m;
uwsgi_cache_key  $request_uri;

# client cache
expires 3m;

uwsgi_pass  unix:///tmp/web2py.socket;
include uwsgi_params;
uwsgi_param UWSGI_SCHEME $scheme;
}
}


But every time I hit the test page, I check the response headers and I see 
always a MISS.
In other words, nginx still sends the requests to uwsgi, and the page is 
generated in every request.
I've found this forum post where someone says this:

*"...it looks to me like the issue is that the upstream server is just not 
sending response that contain an expiration date (Expires:) or a cache 
validator (for instance, Last-Modified:). (The cookie expiration time has 
nothing to do with caching.)*
*The HTTP 1.1 spec 
 says: 'If 
there is neither a cache validator nor an explicit expiration time 
associated with a response, we do not expect it to be cached, but certain 
caches MAY violate this expectation (for example, when little or no network 
connectivity is available).'"*


So I thought I would still needed to use the @cache.action decorator (with 
model=None in order to only set response headers to allow client caching):

@cache.action(time_expire=222, cache_model=None, session=False, vars=False, 
public=True)
def test():
from datetime import datetime

return datetime.now().strftime('%H:%M:%S')


However I sill can't get it to work.
I set up time_expire=222 to check if the directive "expires 3m;" in nginx's 
configuration would overwrite it, and yes it does, the responses have a 
Cache-Control: max-age=180 (that is 3 minutes, not 222 seconds).

*I don't intend to talk about nginx's configuration variables, but I'm 
tempted to ask: am I missing something on the web2py's side?* 
Do I need to modify response.headers in another way to let nginx cache the 
response from uwsgi?


-- 
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] Call a javascript function from SQLFORM.smartgrid

2017-03-24 Thread Nico de Groot
A client-side javascript function can't be triggered by a link. You can define 
a onclick attribute containing a call to a javascript function. If you want to 
use a row id as a parameter you have to make it available as a data attribute.

It's not clear what you want and why.  Maybe you have to grasp the serverside - 
clientside concept better first. Lookup 'javascript' and play around with tools 
like jsfiddle.

Nico de Groot

-- 
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: Extracting values of a list from the database and using them individually in a javascript array

2017-03-24 Thread Cypher


gracias Massimo



On Tuesday, March 21, 2017 at 8:18:21 PM UTC+2, Massimo Di Pierro wrote:
>
> def form1Details():
> form = db.compForm(request.args(0))
> forms = db(db.compFormPages.formName==form.id
> ).select(db.compFormPages.ALL)
> images = [{'link':URL('download',args=form.formImage), 
> 'title':form.formTitle} for form in forms]
> return dict(images=images)
>
> the images are in variable forms so i wanna display them in my view such 
> that each picture is stored individually inside a JavaScript array for a 
> slide show like below
>
> VIEW
>
> 
> {{=ASSIGNJS(IMAGES=images)}}; // magic to convert python to JS object 
> function slideShow() {
> var images = IMAGES.map(function(i){return i.link;}); // array of links
> var descriptions= IMAGES.map(function(i){return i.title;}); // array of 
> titles
> }
> 
>
>
> On Tuesday, 21 March 2017 05:45:36 UTC-5, Cypher wrote:
>>
>> Hi guys i need help, please someone out there coz I'm pulling out my 
>> hairs at this point:
>> I want to extract pictures from within a list extracted from the database 
>> and store them inside a JavaScript array for a slide show.
>>
>>
>> *CONTROLLER:*
>>
>>
>>
>>
>> *def form1Details():form=db.compForm(request.args(0))
>> forms=db(db.compFormPages.formName==form.id 
>> ).select(db.compFormPages.ALL)return locals()*the 
>> images are in variable forms so i wanna display them in my view such that 
>> each picture is stored individually inside a JavaScript array for a slide 
>> show like below
>>
>>
>> *VIEW**{{for pic in form:}}*
>>
>>
>>
>>
>>
>> *function slideShow(){images = ["{{=URL('download', 
>> args=pic.formImage)}}", "{{=URL('download', args=pic2.formImage)}}", 
>> "{{=URL('download', args=pic3.formImage)}}"];*
>>
>>
>>
>>
>>
>>
>>
>> *descriptions=['{{=pic.formTitle}}', '{{=pic2.formTitle}}', 
>> '{{=pic3.formTitle}}'];.}*How
>>  
>> do extract them individually to achieve the above, i could use all the help 
>> i could get, thank you.
>>
>

-- 
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.