[web2py] Re: form grid Order by a Field Value in the Parent Table

2017-09-12 Thread tim . nyborg
Your grid should be using a query that brings in both tables, rather than 
just the Voyages table:
def Voyages():
Voyages = SQLFORM.grid(db.EQ_Voyages.Vessel == db.EQ_Vessels.id, fields
=[db.EQ_Vessels.VesselName, db.EQ_Voyages.VesselNumber], csv=False, orderby
=[db.EQ_Vessels.VesselName, db.EQ_Voyages.VoyageNumber])
return dict(form=Voyages)

If you're using the grid to do built in view/edit/delete, you might want to 
set field_id


On Tuesday, 5 September 2017 16:59:15 UTC+1, rafi farchi wrote:
>
> Hi
>
> I have a parent chile relationship Vessels / Voyages .
> Each vessel may have 1 or more Voyage .
>
> The Voyage Grid form attached is working fine except that i want the Order 
> to by Vessel name(from Vessels ) and then VoyageNumber (from voyages) .
> As it is written now  the order is by Vessel.id , VoyageNumber .
>
> Model
>
> -
>
> db.define_table('EQ_Vessels',
>
> Field('VesselCode', 'string' , length=3 , notnull = True,unique = True) ,
>
> Field('VesselName', 'string', length=50, notnull = True,unique = True) ,
>
> format='%(VesselName)s' )
>
> db.EQ_Vessels._plural='Vessels'
>
> db.define_table('EQ_Voyages',
>
> Field('Vessel','reference EQ_Vessels' ,required=True ) ,
>
> Field('VoyageNumber', 'string' , notnull = True , required=True )
>
> )
>
> db.EQ_Voyages._plural='Voyages'
>
> db.EQ_Voyages.VoyageNumber.requires=IS_NOT_IN_DB(
>
> db(db.EQ_Voyages.Vessel==request.vars.Vessel), 'EQ_Voyages.VoyageNumber')
>
> Controller
>
> -
>
> def Voyages():
>
> Voyages = SQLFORM.grid(db.EQ_Voyages,csv=False , 
> orderby=db.EQ_Voyages.Vessel| db.EQ_Voyages.VoyageNumber)
>
> return dict(form=Voyages)
>
>

-- 
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: {Disarmed} Re: {Disarmed} [web2py] Re: pytest and controllers protected with auth

2017-09-12 Thread Mathieu Clabaut
Thanks Antonio.
There is a lot to do, unfortunately I really lack time to make this project
advance.
For now I use a py.test to run tests for https://bback.me web site,  but it
is too much tightly coupled with the application to be used as an
independant pytest module. Hence the work in the matclab/pytest-web2py.wip

repo, but alas the availability of time to work on it is a problem.
I'll keep the list informed once (and if) the minimum required tutorial is
available.

On Mon, Sep 11, 2017 at 4:50 PM António Ramos  wrote:

> @Mathieu Clabaut
> I see a lot of space for a Testing tutorial with web2py...
>
> Please sit down and do it :)
> I will buy your book/video especially because there is nothing yet about
> it...
>
> Regards
> António
>
>
> 2017-08-21 7:56 GMT+01:00 Mathieu Clabaut :
>
>> You may have a look at my work in progress pytest plugin for web2py :
>> https://github.com/matclab/pytest-web2py.wip
>>
>> There are some example (with registration in
>> https://github.com/matclab/pytest-web2py.wip/blob/master/tests/unit-tests/test_default.py
>>
>> I'm really sorry to not be able to put more time in this project now
>> (some issues are open to identify what is missing).
>>
>> -Mathieu
>>
>> On Fri, Aug 18, 2017 at 7:35 PM Carlos Cesar Caballero Díaz <
>> carlos.caball...@cfg.jovenclub.cu> wrote:
>>
>>> I have been facing with that issue too, the error is because there are
>>> no logged in user, and the redirect is raised, the main problem with this
>>> approach is that I have been not able to correctly log in a user...
>>>
>>> Being honest, I haven't found a satisfactory way for testing web2py
>>> applications.
>>>
>>> Greetings.
>>>
>>> El 18/08/17 a las 13:11, António Ramos escribió:
>>>
>>> anybody help  please ?
>>> regards
>>>
>>> 2017-08-18 15:20 GMT+01:00 António Ramos :
>>>
 this does not work.

 *@auth.requires(True, requires_login=  request.is_local)*
 def execdal():
 return dict(ret=1)


 my pytest function
 def test_execdal(web2py):
 result = web2py.run('default', 'execdal', web2py)


 i get an error about redirected
 [image: Imagem inline 1]

 2017-08-18 12:46 GMT+01:00 António Ramos :

> Hello i+m testing a controller with pytest
>
> if my controller is protected like
>
> @auth.requires.login or @auth.requires_membership how can i test it ?
>
>
> def test_controller(client):
>
>
> client.get('/default/controller')
> ...
> ...
>
>
> Regards
>
>
>

>>> --
>>> 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 *MailScanner ha detectado un intento de fraude
>>> en la siguiente página web "groups.google.com". No confíe en esta página
>>> web:* *MailScanner ha detectado un intento de fraude en la siguiente
>>> p�gina web "groups.google.com". No conf�e en esta p�gina web:*
>>> 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.
>>>
>> --
>> 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] Re: Update value on view

2017-09-12 Thread Wabbajack
Hi Anthony,

It seems that i got it working ...
The sad part is the graph flickers everytime it renders... :(

Just a dumb question...

Is it possible.. I have this on my controller py
contoller/default.py

def index():
...
return dict()

def update_value():
...
return json(new_value)


and this is on my index.html

/views/default/index.html

...html tags/divs that displays graph


graph function...

{{ need to schedule updating of new_value (1 sec interval)}}
   var new_value = {{}}






what i want to do is ajax(maybe another method not ajax) a certain value to 
my view with a different controller(update_value) updating/checking changes 
in database every 1 sec interval


Thanks in advance really it does helps a lot...


Thanks,
Jak







On Monday, September 11, 2017 at 10:26:15 PM UTC+8, Anthony wrote:
>
> Looks like your JS runs only at window.onload, but the graph data are 
> delivered via Ajax requests.
>
> Anthony
>
> On Sunday, September 10, 2017 at 10:48:31 PM UTC-4, Wabbajack wrote:
>>
>> Hi Anthony,
>>
>> I have successfully get the values from another file... thanks...
>> But for now i have another problem displaying the values into a graph...
>>
>>
>>
>> In views/default/index.html
>> {{extend 'layout.html'}}
>>
>> {{=LOAD('default', 'graph', ajax=True, timeout=500, times='infinity')}}
>>
>> {{=BEAUTIFY(response._vars)}}
>>
>> In my default.py controller
>> from gluon.serializers import json
>>
>> def index():
>> return dict()
>>
>>
>> def graph():
>> temp_graph = []
>> temp=[]
>> timet=[]
>> for x in db().select(db.temperature_table.ALL):
>> temp.append(x.temp_value)
>> timet.append(x.tm_timestamp)
>> temp_graph.append({'y':x.temp_value, 'label':x.tm_timestamp})
>>
>> return dict(temp_graph=json(temp_graph),VA=temp,VB=timet)
>>
>>
>> In views/default/graph.html
>> 
>> 
>>
>> {{=VA}}
>> {{=VB}}
>>
>>    Value In Graph  
>> {{=temp_graph}}
>>
>>
>> 
>> window.onload = function () {
>> var chart = new CanvasJS.Chart("chartContainer", {
>> theme: "theme3",
>> legend: {
>>horizontalAlign: "center", // "left" , "right"
>>verticalAlign: "bottom",  // "center" , "top"
>>fontSize: 12
>> },
>> title:{
>> text: "Temperature reader"
>> },
>> animationEnabled: false,
>> data: [
>> {
>> type: "line",
>> showInLegend: true,
>> legendText: "temperature",
>> dataPoints: {{=XML(temp_graph)}}
>> }
>> ]
>> });
>> chart.render();
>> }
>>
>>   
>>
>>
>> In Browser the  renders the graph and value completely with 
>> no problems
>>
>>
>> But the in  the graph does not render.. only Values are 
>> shown..
>>
>>
>> I have also tried increasing the value of the timeout maybe the graph is 
>> not rendered due to timeout value but still no avail...
>>
>> {{extend 'layout.html'}}
>>
>> {{=LOAD('default', 'graph', ajax=True, timeout=2, times='infinity')}}
>>
>> {{=BEAUTIFY(response._vars)}}
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>> On Friday, September 8, 2017 at 7:06:32 PM UTC+8, Anthony wrote:
>>>
>>> What does your newvalue.load view look like? Does it display the temp 
>>> and timet lists?
>>>
>>> Note, your index.html view is incorrect -- it has {{=temp}} and 
>>> {{=timet}}, but the dictionary returned by the index() function instead 
>>> uses VA and VB as keys, so the view should have {{=VA}} and {{=VB}} (should 
>>> be the same in your newvalue.load view). Actually, because the returned 
>>> values are Python lists, you probably want a more sophisticated display 
>>> than simply {{=VA}}.
>>>
>>> Also, note that there is no reason to have two identical functions. You 
>>> can instead have a single function and just use two different views and 
>>> extensions (i.e., index.html and index.load).
>>>
>>> Even better, just use an Ajax component to load the data and set it to 
>>> refresh periodically:
>>>
>>> def index():
>>> return dict()
>>>
>>> def get_data():
>>> ...
>>> return dict(VA=temp, VB=timet)
>>>
>>> In views/default/index.html:
>>>
>>> {{=LOAD('default', 'get_data.load', ajax=True, timeout=1000, times=
>>> 'infinity')}}
>>>
>>> In views/default/get_data.load:
>>>
>>> {{=VA}}
>>> {{=VB}}
>>>
>>> Keep in mind that this is an inefficient way to get realtime updates. 
>>> First, you are polling every second, whether or not the data have changed. 
>>> Second, you are sending all the data on every request instead of just the 
>>> changes. This may be fine for your use case, but a more efficient approach 
>>> would be to use a server push pubsub method (e.g., use websockets to 
>>> publish updates to the client) -- see 
>>> https://github.com/web2py/web2py/blob/master/gluon/contrib/websocket_messaging.py
>>> .
>>>
>>> Anthony
>>>
>>>
>>> On Friday, September 8, 2017 at 

[web2py] Re: How to use flatpickr in web2py in a custom form

2017-09-12 Thread Anthony
Just follow the flatpickr documentation: 
https://chmln.github.io/flatpickr/getting-started/

Keep in mind that web2py will add class "date" to date inputs and 
"datetime" to datetime inputs, so you can use those as selectors. Also, be 
sure not to load the default web2py calender.js file (otherwise, the 
default web2py picker will interfere).

Anthony

On Tuesday, September 12, 2017 at 5:54:08 AM UTC-4, Oasis Agano wrote:
>
>
> I have created a custom html form and i want to use flatpickr as the 
> datepicker inside it,
> then send the data to web2py in a date field.
> how can i integrate flatpickr on the form to work with web2py date fields.
>
> kr,
> Oasis
>

-- 
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: web2py 2.15.4 is OUT

2017-09-12 Thread 黄祥
just tested that maxtextlengths doesnt have any effects, the long field 
value still have ...
*e.g.*
grid = SQLFORM.smartgrid(..., maxtextlengths = {'table_name.field_name' : 
350} )
is it correct or should i just used maxtextlength = 350 ?

thanks and best regards,
stifan

-- 
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: HTML5 widgets on SQLFORM.factory

2017-09-12 Thread Fabiano Almeida
Great Anthony!

Field('year', 'integer', label='Year',
  widget=lambda f, v: SQLFORM.widgets.string.widget(f, v, _type='number'
))

worked perfectly!

Thanks!

2017-09-11 19:59 GMT-03:00 Anthony :

> On Monday, September 11, 2017 at 4:30:40 PM UTC-4, Fabiano Almeida wrote:
>>
>> Hi @ll!
>>
>> How to use HTML5 widgets on SQLFORM.factory?
>>
>> I have this peace of code:
>> form = SQLFORM.factory(Field('year', 'integer', label='Year'))
>>
>
>> I like use this HTML5 input type="number" widget.
>>
>
> You can do:
>
> Field('year', 'integer', label='Year',
>   widget=lambda f, v: SQLFORM.widgets.string.widget(f, v, _type=
> 'number'))
>
> You could instead use SQLFORM.widgets.integer.widget (which is the default
> for integer fields), but that would set class="integer", which would
> activate web2py's built-in integer validator, which you may not want.
>
> 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] Re: web2py 2.15.4 is OUT

2017-09-12 Thread Anthony
On Tuesday, September 12, 2017 at 8:39:16 AM UTC-4, 黄祥 wrote:
>
> just tested that maxtextlengths doesnt have any effects, the long field 
> value still have ...
> *e.g.*
> grid = SQLFORM.smartgrid(..., maxtextlengths = {'table_name.field_name' : 
> 350} )
> is it correct or should i just used maxtextlength = 350 ?
>

Most of the smartgrid arguments that correspond to grid arguments are 
actually dictionaries with table names as keys, so it should be:

maxtextlengths = {'tablename': {'field_name': 350}}

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: data represent in views is loaded faster using for loop python rather than using response json

2017-09-12 Thread Anthony

>
> *views/default/index.html*
> ...
> 

[web2py] Re: Has the result of a datetime Field changed?

2017-09-12 Thread Anthony
SQLFORM.factory creates a dummy DAL table via DAL(None). A change was made 
so that auto-validators no longer get applied to fields with DAL(None), so 
no fields in a SQLFORM.factory table will get the usual default DAL 
validators. Datetime fields typically get a default IS_DATETIME() validator 
(wrapped in IS_EMPTY_OR()), and that is what caused the conversion to a 
datetime object in the previous version of web2py. The IS_DATETIME() 
validator is no longer being added, so we no longer get the conversion.

This should be corrected somehow. I've posted on the developers list to get 
a discussion going: 
https://groups.google.com/forum/#!topic/web2py-developers/aX6CiPi4Dh0.

In the meantime, you can explicitly add the validator:

SQLFORM.factory(Field('startzeit', 'datetime', requires=IS_EMPTY_OR(
IS_DATETIME(

Alternatively, you can do something like this:

def sqlform_factory(*fields, **attributes):
from gluon.dal import _default_validators
db = DAL(None)
db.validators_method = lambda f: _default_validators(db, f)
table = db.define_table('no_table', *fields)
return SQLFORM.factory(*table, **attributes)

And then:

form = sqlform_factory(Field('startzeit', 'datetime'))

Anthony

On Monday, September 11, 2017 at 3:53:52 PM UTC-4, mweissen wrote:
>
> What is the type of the result of a Field(...;'datetime') ?
>
> I think, it should be "datetime" (and I am shure it has been in version 
> 2.14.x), but web2py 2.15.4 delivers a "str".
>
> def dttest2():
> form = SQLFORM.factory(Field('startzeit', 'datetime'))
> if form.process().accepted:
> return \
>   str(isinstance(form.vars.startzeit,datetime.datetime))
> return dict(form=form)
>
>
> The result is "False"
>
> ​Regards Martin​
>
>
>

-- 
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: Has the result of a datetime Field changed?

2017-09-12 Thread Martin Weissenboeck
Thank you for this explanation and the workaround.
I have found the next *problem with "common_filter"*: it seems, that a
common_filter is not applied in the following situation:


db.define_table("test",
Field("name"),
common_filter = lambda query: db.test.id==1)


def show1():
nlist = [p.name for p in db().select(db.test.name)]
form = SQLFORM.factory(
Field('name', 'list:reference test', requires=IS_IN_SET(nlist)))
return dict(form=form)

def show2():
nlist = [p.name for p in db(db.test.id==1).select(db.test.name)]
form = SQLFORM.factory(
Field('name', 'list:reference test', requires=IS_IN_SET(nlist)))
return dict(form=form)


Both functions should only show the first name for the "requires"-selection.
But only the second functions works as expected, show1 allows all names.

The same construction worked in web2py 2.14

2017-09-12 18:15 GMT+02:00 Anthony :

> SQLFORM.factory creates a dummy DAL table via DAL(None). A change was made
> so that auto-validators no longer get applied to fields with DAL(None), so
> no fields in a SQLFORM.factory table will get the usual default DAL
> validators. Datetime fields typically get a default IS_DATETIME() validator
> (wrapped in IS_EMPTY_OR()), and that is what caused the conversion to a
> datetime object in the previous version of web2py. The IS_DATETIME()
> validator is no longer being added, so we no longer get the conversion.
>
> This should be corrected somehow. I've posted on the developers list to
> get a discussion going: https://groups.google.com/forum/#!topic/web2py-
> developers/aX6CiPi4Dh0.
>
> In the meantime, you can explicitly add the validator:
>
> SQLFORM.factory(Field('startzeit', 'datetime', requires=IS_EMPTY_OR(IS_
> DATETIME(
>
> Alternatively, you can do something like this:
>
> def sqlform_factory(*fields, **attributes):
> from gluon.dal import _default_validators
> db = DAL(None)
> db.validators_method = lambda f: _default_validators(db, f)
> table = db.define_table('no_table', *fields)
> return SQLFORM.factory(*table, **attributes)
>
> And then:
>
> form = sqlform_factory(Field('startzeit', 'datetime'))
>
> Anthony
>
>
> On Monday, September 11, 2017 at 3:53:52 PM UTC-4, mweissen wrote:
>>
>> What is the type of the result of a Field(...;'datetime') ?
>>
>> I think, it should be "datetime" (and I am shure it has been in version
>> 2.14.x), but web2py 2.15.4 delivers a "str".
>>
>> def dttest2():
>> form = SQLFORM.factory(Field('startzeit', 'datetime'))
>> if form.process().accepted:
>> return \
>>   str(isinstance(form.vars.startzeit,datetime.datetime))
>> return dict(form=form)
>>
>>
>> The result is "False"
>>
>> ​Regards Martin​
>>
>>
>> --
> 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.