[web2py] Re: Setting a default reference value as that of a specific group the logging in user is a member of

2020-02-25 Thread 'Annet' via web2py-users
I don't understand the use of field 'groups' and function 'get_groups()

I think you should use web2py's built in auth_ functionality: drop field
'groups' in both tables, link users and groups (each hotel its own group)
in the auth_membership table, and use this table to create a list of options
for the drop-down.

I hope this points you in the right direction to solve your problem


Kind regards,

Annet

-- 
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.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/web2py/bd2e0505-00f8-4403-9e3d-f89372e2f027%40googlegroups.com.


[web2py] Re: Setting a default reference value as that of a specific group the logging in user is a member of

2020-02-25 Thread mostwanted
How do I set it as a default if the form is not open by a link redirection? 
The form is opened directly by the main-menu.
If it were opened through the link then it'd be easy to set the hotel as a 
default coz all i'd do would be:


*hotel=db(db.hotel_profile(request.args(0, 
cast=int))db.meals.hotel.default=hotel.id*

Please pardon my limited skill but your assistance would take me to the 
next phase of this project.

Regards

On Tuesday, February 25, 2020 at 9:06:55 PM UTC+2, villas wrote:
>
> Set the default hotel value in the SQLFORM field.
>
> You could also 'force' the hotel you want by using SQLFORM onvalidation 
> 
>
>
>
> On Tuesday, 25 February 2020 07:28:31 UTC, mostwanted wrote:
>>
>> I have 2 tables about a hotel, one table registers the hotel itself & the 
>> other is about meals that are offered at the hotel but the idea is that 
>> only group members of each hotel have to & can only register meals for 
>> their hotels. So to avoid mistakes & prevent malicious intentions I was 
>> wondering if its possible to have the referencing field in the meals table 
>> pre-selected appropriately for the logged in user with their correct hotel 
>> name as per the group they belong to. I hope I make sense:
>>
>> *MODEL CODE*
>> def get_group():
>> groups = auth.user_groups
>> if not groups:
>> return None
>> group_ids = [id for id in groups if not 
>> groups[id].startswith('user_')]
>> return group_ids[0] if group_ids else None
>>
>> db.define_table('hotel_profile',
>> Field('hotel_name'),
>> Field('logo', 'upload'),
>> Field('tel1'),
>> Field('email_address'),
>> Field('directions', 'text', requires=IS_LENGTH(500)),
>> Field('google_directions'),
>> Field('posted_by', 'reference auth_user', default=auth.
>> user_id, readable=False, writable=False),
>> Field('groups', 'reference auth_group', default=get_group
>> (), readable=False, writable=False),
>> format='%(hotel_name)s'
>>)
>>
>>
>> db.define_table('meals',
>> Field('hotel', 'reference hotel_profile'),
>> Field('supper_price'),
>> Field('supper_details', 'text', requires=IS_LENGTH(200)),
>> Field('lunch_price'),
>> Field('lunch_details', 'text', requires=IS_LENGTH(200)),
>> Field('breakfast_price'),
>> Field('breakfast_details', 'text', requires=IS_LENGTH(200
>> )),
>> Field('posted_by', 'reference auth_user', default=auth.
>> user_id, readable=False, writable=False),
>> Field('groups', 'reference auth_group', default=get_group
>> (), readable=False, writable=False)
>>)
>>
>> Regards;
>>
>> Mostwanted
>>
>

-- 
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.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/web2py/c1d70cd1-a891-44dd-a73d-a0d15655c561%40googlegroups.com.


[web2py] Re: LOAD in py4web

2020-02-25 Thread RHC
Just to confirm, will that call to foo(0 return the html generated using 
that function and it's template?

My view on the various follow up questions about LOAD is that we should use 
existing frameworks where possible rather than complicating py4web. The 
appeal of py4web is that it has less of it's own javascript which in web2py 
was awkward to work around if it didn't work the way you needed it to.

On Monday, February 24, 2020 at 12:02:01 AM UTC, Val K wrote:
>
> for server side you can
> @action("foo")
> @action.uses("foo.html")
> def foo():
> return dict(...)
>
> @action("bar")
> @action.uses("bar.html")
> def bar():
> return dict(foo_content = foo())
>
> # bar.html
> [[=XML(foo_content)]]
>
>
> for the client side, I suppose, you have to do it by yourself using pure 
> js or some lib (JQuery, axios, Vue.js ... )
>
>
>
> On Sunday, February 23, 2020 at 9:18:51 PM UTC+3, RHC wrote:
>>
>> HI,
>>
>> I am beginning to experiment with py4web, I like the sound of it and I am 
>> looking to convert a web2py project to py4web to see how they compare.
>>
>> It appears that the LOAD (helper?) that was available in web2py templates 
>> is not available in py4web. I was using this to populate part of a web 
>> page, I liked the way you had the option to use LOAD to call a separate URL 
>> (within the same app) and insert the result into your page before returning 
>> the page to the client.
>>
>> What is the reason for the absence of LOAD in py4web? is there a 
>> recommended alternative method of achieving the same effect? I have used a 
>> mixture of ajax=True and ajax=False options for this feature.
>>
>> 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.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/web2py/8ffd5a19-8ad7-4d88-971b-91d1c07b0231%40googlegroups.com.


[web2py] Re: Setting a default reference value as that of a specific group the logging in user is a member of

2020-02-25 Thread villas
Set the default hotel value in the SQLFORM field.

You could also 'force' the hotel you want by using SQLFORM onvalidation 




On Tuesday, 25 February 2020 07:28:31 UTC, mostwanted wrote:
>
> I have 2 tables about a hotel, one table registers the hotel itself & the 
> other is about meals that are offered at the hotel but the idea is that 
> only group members of each hotel have to & can only register meals for 
> their hotels. So to avoid mistakes & prevent malicious intentions I was 
> wondering if its possible to have the referencing field in the meals table 
> pre-selected appropriately for the logged in user with their correct hotel 
> name as per the group they belong to. I hope I make sense:
>
> *MODEL CODE*
> def get_group():
> groups = auth.user_groups
> if not groups:
> return None
> group_ids = [id for id in groups if not groups[id].startswith('user_')]
> return group_ids[0] if group_ids else None
>
> db.define_table('hotel_profile',
> Field('hotel_name'),
> Field('logo', 'upload'),
> Field('tel1'),
> Field('email_address'),
> Field('directions', 'text', requires=IS_LENGTH(500)),
> Field('google_directions'),
> Field('posted_by', 'reference auth_user', default=auth.
> user_id, readable=False, writable=False),
> Field('groups', 'reference auth_group', default=get_group
> (), readable=False, writable=False),
> format='%(hotel_name)s'
>)
>
>
> db.define_table('meals',
> Field('hotel', 'reference hotel_profile'),
> Field('supper_price'),
> Field('supper_details', 'text', requires=IS_LENGTH(200)),
> Field('lunch_price'),
> Field('lunch_details', 'text', requires=IS_LENGTH(200)),
> Field('breakfast_price'),
> Field('breakfast_details', 'text', requires=IS_LENGTH(200
> )),
> Field('posted_by', 'reference auth_user', default=auth.
> user_id, readable=False, writable=False),
> Field('groups', 'reference auth_group', default=get_group
> (), readable=False, writable=False)
>)
>
> Regards;
>
> Mostwanted
>

-- 
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.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/web2py/6b559611-3db8-4756-8bdc-aa99103581ea%40googlegroups.com.


[web2py] Re: web2py represent_none in SQLFORM.smartgrid in combination with date field throws exception

2020-02-25 Thread villas
I've never used represent_none,  but it seems like a bug. 

Workaround:  I guess you can try setting the field individually. Something 
like this..

db.mytable.somedate.represent  = lambda v,r: v.strftime('%d %b %Y')  if v 
else 'No Date'

-- 
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.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/web2py/a2454f43-57f3-4279-b486-fddf7d2be673%40googlegroups.com.


Re: [web2py] Re: LOAD in py4web

2020-02-25 Thread Christian Varas
I think it can be usefull if you use another template not based in vue.

Cheers.

El El lun, 24 de feb. de 2020 a la(s) 03:31, Massimo Di Pierro <
massimo.dipie...@gmail.com> escribió:

> We can add it in utils. But before we do. Do other peopl find it useful?
> Is that a pattern we should encourage vs, for example, vue.js?
>
> On Sunday, 23 February 2020 10:18:51 UTC-8, RHC wrote:
>>
>> HI,
>>
>> I am beginning to experiment with py4web, I like the sound of it and I am
>> looking to convert a web2py project to py4web to see how they compare.
>>
>> It appears that the LOAD (helper?) that was available in web2py templates
>> is not available in py4web. I was using this to populate part of a web
>> page, I liked the way you had the option to use LOAD to call a separate URL
>> (within the same app) and insert the result into your page before returning
>> the page to the client.
>>
>> What is the reason for the absence of LOAD in py4web? is there a
>> recommended alternative method of achieving the same effect? I have used a
>> mixture of ajax=True and ajax=False options for this feature.
>>
>> 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.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/web2py/7cfaf6be-8be3-41dc-8745-ab59716f68af%40googlegroups.com
> 
> .
>

-- 
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.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/web2py/CA%2Bs%2BuJsTJwf1sw%3D-oR4MyZqVhyDcjkn-xYaQA-fbHyBAXyb%2Bqw%40mail.gmail.com.


[web2py] web2py represent_none in SQLFORM.smartgrid in combination with date field throws exception

2020-02-25 Thread David Zejda
Hi,

I found out that

SQLFORM.smartgrid(db.table_name, represent_none="") with a table table_name 
containing a field with date datatype throws the exception:

File "/opt/web2py3/gluon/packages/dal/pydal/validators.py", line 2335, in 
formatter
  year = value.year
AttributeError: 'str' object has no attribute 'year'

The problem occurs even if IS_DATE validator is not specified for the 
field. I have not checked it, but other validators might be affected too.

web2py 2.18.5-stable+timestamp.2019.04.08.04.22.03
python 3.7.3

Have a nice day!
David

-- 
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.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/web2py/bad6707a-aacf-47b4-801b-e3465a09bae5%40googlegroups.com.


[web2py] Re: unexpected end of stream - py4web

2020-02-25 Thread Edoardo Torrini
Hi Dave,
thanks for the reply, but I have notice that the code is wrong, I will 
explain.
Since I need three function in task I used another one to collector and 
after I redirect by an if statement.

So I have the funtion: my_task(func, filtri, *argv) and the function 
produzione(dbnow, filtri, *argv).
In the example I have synthesized the by putting only one function.

The correct one that I have test a lot of time is:

def produzione(dbnow, filtri, *argv):
object_list = []

if filtri == 0:
rows = dbnow(dbnow.Produzione.ID != None).select()
else:
data1 = fixDate(argv[Filter.DataIn.value])
data2 = fixDate(argv[Filter.DataFin.value])
rows = dbnow((dbnow.Produzione.OraInizio >= data1)&(dbnow.Produzione
.OraInizio <= data2)&(dbnow.Produzione.Macchina == argv[Filter.IdMac.value
])).select()


for record in rows:
d = collections.OrderedDict()
d['ID'] = record.ID
d['DataLoggerID'] = record.DataLoggerID
d['DataLoggerIDRiga'] = record.DataLoggerIDRiga
d['Utente'] = record.Utente if (record.Utente != None) else 0 
d['Commessa'] = str(record.Commessa)
d['Lotto'] = str(record.Lotto)
d['Fase'] =  record.Fase if (record.Fase != None) else 0 
d['Programma'] = str(record.Programma)
d['OraInizio'] = str(record.OraInizio)
d['OraProgrammazione'] = str(record.OraProgrammazione)
d['OraAttrezzaggio'] = str(record.OraAttrezzaggio)
d['OraPrimoPezzo'] = str(record.OraPrimoPezzo)
d['OraProduzione'] = str(record.OraProduzione)
d['OraFine'] = str(record.OraFine)
d['NPieghe'] = record.NPieghe if (record.NPieghe != None) else 0
d['Macchina'] = record.Macchina if (record.Macchina != None) else 0
d['PezziProdotti'] = record.PezziProdotti if (record.PezziProdotti 
!= None) else 0
object_list.append(d)


return json.dumps(return object_list)

Moreover if I run the request for a Browser and I can see the right result.

I hope I was clear in the explanation

Edoardo Torrini

Il giorno martedì 25 febbraio 2020 07:36:15 UTC+1, Dave S ha scritto:
>
>
>
> On Sunday, February 23, 2020 at 11:26:50 PM UTC-8, Edoardo Torrini wrote:
>>
>> Hi,
>> I will attach you some part of code:
>>
>>
>>
>>
>> this is the task of my app:
>>
>> [image: task prd - py4web.png]
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>> I am still surprised by that last line.
>>
>
> Wouldn't the return exit produzione() while evaluating object_list and 
> before actually calling the json.dumps() ?
>
> /dps
>
>

-- 
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.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/web2py/066365ac-d359-4224-9a40-7642eacfcabf%40googlegroups.com.


Re: [web2py] Setting a default reference value as that of a specific group the logging in user is a member of

2020-02-25 Thread AGRogers
I am interested in the best practice way to do this as well.

On Tue, 25 Feb 2020, 13:58 mostwanted,  wrote:

> I have 2 tables about a hotel, one table registers the hotel itself & the
> other is about meals that are offered at the hotel but the idea is that
> only group members of each hotel have to & can only register meals for
> their hotels. So to avoid mistakes & prevent malicious intentions I was
> wondering if its possible to have the referencing field in the meals table
> pre-selected appropriately for the logged in user with their correct hotel
> name as per the group they belong to. I hope I make sense:
>
> *MODEL CODE*
> db.define_table('hotel_profile',
> Field('hotel_name'),
> Field('logo', 'upload'),
> Field('tel1'),
> Field('email_address'),
> Field('directions', 'text', requires=IS_LENGTH(500)),
> Field('google_directions'),
> Field('posted_by', 'reference auth_user', default=auth.
> user_id, readable=False, writable=False),
> Field('groups', 'reference auth_group', default=get_group
> (), readable=False, writable=False),
> format='%(hotel_name)s'
>)
>
>
> db.define_table('meals',
> Field('hotel', 'reference hotel_profile'),
> Field('supper_price'),
> Field('supper_details', 'text', requires=IS_LENGTH(200)),
> Field('lunch_price'),
> Field('lunch_details', 'text', requires=IS_LENGTH(200)),
> Field('breakfast_price'),
> Field('breakfast_details', 'text', requires=IS_LENGTH(200
> )),
> Field('posted_by', 'reference auth_user', default=auth.
> user_id, readable=False, writable=False),
> Field('groups', 'reference auth_group', default=get_group
> (), readable=False, writable=False)
>)
>
> Regards;
>
> Mostwanted
>
> --
> 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.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/web2py/be138b98-8d67-4a8d-bb77-b4410434f882%40googlegroups.com
> 
> .
>

-- 
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.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/web2py/CACWMBMPeHbckGMOpHKYnBwgSiyG3iuH-Xrdhk7YonWaMO7%2BsGg%40mail.gmail.com.