RE: [web2py] Re: Fixes for uWSGI + ngnix install script in Ubuntu 20.04.01 LTS?

2021-01-07 Thread Tim Nyborg
Agreed that the web2py itself shouldn’t require python 3, but python 2 is no 
longer the default for Ubuntu, and a public configuration recipe should reflect 
that.A user who really needs 2.7 for their projects will be able to adapt 
it without much effort.

From: web2py@googlegroups.com  On Behalf Of 
david...@gmail.com
Sent: 07 January 2021 10:34
To: web2py-users 
Subject: [web2py] Re: Fixes for uWSGI + ngnix install script in Ubuntu 20.04.01 
LTS?

OK - thanks for the feedback. I've read around on similar comments and I 
completely get that there is a groundswell against making web2py code require 
python 3 (essentially other frameworks should be used instead), but this would 
just be removing a barrier to getting it working with python 3 on Ubuntu 20.04 
without requiring python 2 to run the setup script. I'll submit it.
On Thursday, 7 January 2021 at 10:28:14 UTC 
tim.n...@conted.ox.ac.uk wrote:
Agree that the changes merit a pull request, and the script should now be 
py3-specific, since we're past py2 EOL.

Re. problem 3, I think the script once handled ubuntu/debian versions with 
initd OR systemd, and that the init config is long obsolete and should be 
removed.  It was useful having both back when some of us were on Debian 7 or 
other versions without systemd, but that's no longer the case.

And yes, the Execstart in the uwsgi service should match the options in the 
upstart config.  On my Debian servers, I have `ExecStart = /usr/local/bin/uwsgi 
--emperor /etc/uwsgi/apps-enabled --logto /var/log/uwsgi/uwsgi.log`, and it 
works just fine.

On Friday, 18 December 2020 at 11:14:41 UTC david...@gmail.com wrote:
Just to add: I fixed the unresolved issues as I typed the email and then forgot 
to change the opening paragraph, so ignore part (b). Part (a) and part (c) from 
the first paragraph still apply.

On Friday, 18 December 2020 at 11:12:40 UTC 
david...@gmail.com wrote:
Hi there,

I'm trying to set up Web2Py in Ubuntu 20.04.01 LTS using the scripts:

https://github.com/web2py/web2py/blob/master/scripts/setup-web2py-nginx-uwsgi-ubuntu.sh

It doesn't work. I've been going through it some details and have almost got it 
working but wanted to (a) check I'm not being an idiot (b) ask about a couple 
of unresolved issues and (c) does this merit a pull request?

# Problem 1:

https://github.com/web2py/web2py/blob/master/scripts/setup-web2py-nginx-uwsgi-ubuntu.sh#L31-34

Python 2 is no longer shipped in 20.04 and --no-build-wheel is deprecated. 
Rather than install it, it makes sense to me to switch this section and use the 
installed Python 3.8. I understand that this makes the script Python 3 
specific, but that seems a sane thing to offer as a script with Ubuntu 20.04

```
apt-get -y install build-essential python3-dev libxml2-dev python-pip3 
unzippip3 install setuptools --no-binary :all: --upgrade
PIPPATH=`which pip3`
$PIPPATH install --upgrade uwsgi
```

# Problem 2:

https://github.com/web2py/web2py/blob/master/scripts/setup-web2py-nginx-uwsgi-ubuntu.sh#L133-136

OpenSSL no longer accepts 1024 bit keys, so this needs to be altered. I think 
these two lines do the same job with a 2048 bit key.

```
openssl req -x509 -nodes -sha256 -days 365 -newkey rsa:2048 -keyout web2py.key 
-out web2py.crt
openssl x509 -noout -text -in web2py.crt -out web2py.info
```

# Problem 3:

https://github.com/web2py/web2py/blob/master/scripts/setup-web2py-nginx-uwsgi-ubuntu.sh#L185

I'm really out on a limb here, but I don't think this is creating the services 
correctly on 20.04, which I think is to do with the removal of Upstart (?). If 
I _manually_ start uwsgi from the command line on my server, then I can access 
the web2py Welcome page:

```
sudo uwsgi --master --die-on-term --emperor /etc/uwsgi --logto 
/var/log/uwsgi/uwsgi.log
```

The script does create a uwsgi service:

https://github.com/web2py/web2py/blob/master/scripts/setup-web2py-nginx-uwsgi-ubuntu.sh#L144

This doesn't seem to work as expected and I think this is because the ExecStart 
statement isn't correct. If I substitute the ExecStart command with the one in 
the upstart config at line 201 and restart the services, then it works. I 
suspect that makes lines 185 to 202 redundant?

And I think that is it - I get an instance running on Ubuntu 20.04 with:

2.21.1-stable+timestamp.2020.11.28.04.10.44
(Running on nginx/1.18.0, Python 3.8.5)
Thoughts / Comments / Have you never read about this massive security hole 
you've just opened up?
--
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 a topic in the Google 
Groups "web2py-users" group.
To unsubscribe from this topic, visit 
https://groups.google.com/d/topic/web2py/Kp2kTz-X_Lo/unsubscribe.
To unsubscribe from this group and all 

[web2py] Re: Fixes for uWSGI + ngnix install script in Ubuntu 20.04.01 LTS?

2021-01-07 Thread Tim Nyborg
Agree that the changes merit a pull request, and the script should now be 
py3-specific, since we're past py2 EOL.

Re. problem 3, I think the script once handled ubuntu/debian versions with 
initd OR systemd, and that the init config is long obsolete and should be 
removed.  It was useful having both back when some of us were on Debian 7 
or other versions without systemd, but that's no longer the case.

And yes, the Execstart in the uwsgi service should match the options in the 
upstart config.  On my Debian servers, I have `ExecStart = 
/usr/local/bin/uwsgi --emperor /etc/uwsgi/apps-enabled --logto 
/var/log/uwsgi/uwsgi.log`, and it works just fine.

On Friday, 18 December 2020 at 11:14:41 UTC david...@gmail.com wrote:

> Just to add: I fixed the unresolved issues as I typed the email and then 
> forgot to change the opening paragraph, so ignore part (b). Part (a) and 
> part (c) from the first paragraph still apply.
>
> On Friday, 18 December 2020 at 11:12:40 UTC david...@gmail.com wrote:
>
>> Hi there,
>>
>> I'm trying to set up Web2Py in Ubuntu 20.04.01 LTS using the scripts:
>>
>>
>> https://github.com/web2py/web2py/blob/master/scripts/setup-web2py-nginx-uwsgi-ubuntu.sh
>>
>> It doesn't work. I've been going through it some details and have almost 
>> got it working but wanted to (a) check I'm not being an idiot (b) ask about 
>> a couple of unresolved issues and (c) does this merit a pull request?
>>
>> # Problem 1:
>>
>>
>> https://github.com/web2py/web2py/blob/master/scripts/setup-web2py-nginx-uwsgi-ubuntu.sh#L31-34
>>
>> Python 2 is no longer shipped in 20.04 and --no-build-wheel is 
>> deprecated. Rather than install it, it makes sense to me to switch this 
>> section and use the installed Python 3.8. I understand that this makes the 
>> script Python 3 specific, but that seems a sane thing to offer as a script 
>> with Ubuntu 20.04
>>
>> ```
>> apt-get -y install build-essential python3-dev libxml2-dev python-pip3 
>> unzippip3 install setuptools --no-binary :all: --upgrade
>> PIPPATH=`which pip3`
>> $PIPPATH install --upgrade uwsgi
>> ```
>>
>> # Problem 2:
>>
>>
>> https://github.com/web2py/web2py/blob/master/scripts/setup-web2py-nginx-uwsgi-ubuntu.sh#L133-136
>>
>> OpenSSL no longer accepts 1024 bit keys, so this needs to be altered. I 
>> think these two lines do the same job with a 2048 bit key.
>>
>> ```
>> openssl req -x509 -nodes -sha256 -days 365 -newkey rsa:2048 -keyout 
>> web2py.key -out web2py.crt
>> openssl x509 -noout -text -in web2py.crt -out web2py.info
>> ```
>>
>> # Problem 3:
>>
>>
>> https://github.com/web2py/web2py/blob/master/scripts/setup-web2py-nginx-uwsgi-ubuntu.sh#L185
>>
>> I'm really out on a limb here, but I don't think this is creating the 
>> services correctly on 20.04, which I think is to do with the removal of 
>> Upstart (?). If I _manually_ start uwsgi from the command line on my 
>> server, then I can access the web2py Welcome page:
>>
>> ```
>> sudo uwsgi --master --die-on-term --emperor /etc/uwsgi --logto 
>> /var/log/uwsgi/uwsgi.log
>> ```
>>
>> The script does create a uwsgi service:
>>
>>
>> https://github.com/web2py/web2py/blob/master/scripts/setup-web2py-nginx-uwsgi-ubuntu.sh#L144
>>
>> This doesn't seem to work as expected and I think this is because the 
>> ExecStart statement isn't correct. If I substitute the ExecStart command 
>> with the one in the upstart config at line 201 and restart the services, 
>> then it works. I suspect that makes lines 185 to 202 redundant?
>>
>> And I think that is it - I get an instance running on Ubuntu 20.04 with:
>>
>> 2.21.1-stable+timestamp.2020.11.28.04.10.44
>> (Running on nginx/1.18.0, Python 3.8.5)
>>
>> Thoughts / Comments / Have you never read about this massive security 
>> hole you've just opened up?
>>
>

-- 
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/4dc69ca7-a65c-453f-bd75-07b9be70f927n%40googlegroups.com.


[web2py] Re: Likely causes of admin server error?

2020-05-13 Thread Tim Nyborg
I'd look at the apache logs.  I ran into the same problem with an 
nginx/uwsgi config, and uwsgi's logs pointed me to the fact that I had the 
wrong group on the application's file permissions.

On Friday, 1 May 2020 18:52:02 UTC+1, Ian W. Scott wrote:
>
> What are the "likely culprits" I should be looking at when I get an 
> "Internal server error" accessing admin or appadmin on a fresh web2py 
> installation? Here's what I've been trying so far. 
>
> - Apache2 config file correctly configured?
> - Am I blocking access to admin?
> - Is https access configured?
> - accessing over https?
> - admin password set?
> - parameters_443.py file present in web2py folder and accessible?
>
> I've confirmed that all of these are working properly. (The apache2 config 
> is identical to one working fine on an identical server.) 
>
> So what else could be blocking admin? What else should I be looking at?
>
> Thanks ahead of time 
>
>
> - newest web2py source, py3.7, apache 2.4 with mod_wsgi
>

-- 
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/d8919438-dec6-4936-98b6-36cb1e446173%40googlegroups.com.


[web2py] Mirroring/multiple URIs broken in 2.19.1

2020-04-06 Thread Tim Nyborg
The new pyDAL version included in 2.19.1 causes problems where multiple 
URIs are provided to the DAL, but the first is non-functional (e.g. a 
mirror)

See details at:
https://github.com/web2py/pydal/issues/620


-- 
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/15b69fbe-a56e-499c-8820-da0c4306a534%40googlegroups.com.


[web2py] Re: web2py with python 2.7 and web2py running on python 3

2020-03-20 Thread Tim Nyborg
Should be, but it can depend on what other tools you're using in web 
stack.  E.g., the steps it'll take to get Apache running two different 
environments are different from the steps to get NGINX/Uwsgi, or Gunicorn.

On Saturday, 14 March 2020 19:06:20 UTC, Andrea Fae' wrote:
>
> Is it possible to have 2 differents environment on the same PC?
> web2py running python2.7 and web2py running ppython 3 separated...?
> 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.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/web2py/9034e711-5314-4a58-8538-1590694482d8%40googlegroups.com.


[web2py] Re: Displaying for loop results only once

2020-01-21 Thread Tim Nyborg
Simplest fix: use "any" instead:

{{for bookings in bookings:}}

  {{if any(bookings.company in q.customer.company for q in quotes):}}
Quoted
  {{pass}}

{{pass}}


To avoid all this looping, you could have a separate query join the two 
tables and count the matches.

On Saturday, 18 January 2020 23:00:04 UTC, mostwanted wrote:
>
> In my quotation system I have come up with a way to remind users of 
> UN-deleted quotations. This helps them from creating new quotations on top 
> of old quotations.
> How it works is that when a company has been quoted its name is added to a 
> list called the control list and a selected company's name is checked 
> against this control list, if it is in the control list it will mean that 
> it has been quoted and a blue badge titled quoted will be displayed next to 
> the company's name. The problem I am facing now is that if the company has 
> several items quoted under it it means that its name will appear several  
> times in the control list, this causes the green badge to appear as many 
> times as the company name appears in the control list, I want avoid this, 
> is there a way to get the badge to appear only once regardless of the 
> number of times the company name appears in the control list?
>
> *CONTROLLER*
> def registeredClients():
> bookings=db(db.Client_Details).select(db.Client_Details.ALL, orderby=
> db.Client_Details.company)
> quotes=db(db.quotation).select()
> return locals()
>
> *CSS*
> .disc
> {
> border: solid 2px transparent;
> border-radius: 50%;
> width: 40px;
> padding: 5px;
> }
>
> .blue
> {
> background-color: blue;
> color: white;
> font-weight: bold;
> font-size: x-small;
> }
>
> *VIEW*
> {{for bookings in bookings:}}
>
> {{for q in quotes:}}
> {{quoted=[q.customer.company]}}
>  >Quoted
> {{pass}}
>
> {{pass}}
>
> Please help!!!
>
> 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/0bf81607-b9d6-4255-b5b5-bab17b29cc1c%40googlegroups.com.


[web2py] Re: running two web2py instances on the same server under apache wsgi mod

2020-01-21 Thread Tim Nyborg
Yes, that should work.

I have three web2py instances on a server running nginx/uwsgi, and the 
principle's the same: slightly different configs for each instance, 
pointing to separate source files.

On Tuesday, 21 January 2020 11:37:55 UTC, Manuele wrote:
>
> Hi! 
>
> If I need to manage on the same server two different web2py instances 
> (for example for having two distinct versions of web2py running) what 
> are the differences I have to consider with what reported in 
> documentation[1]? 
>
> At the moment I already have the first instance running through wsgi mod 
> using this configuration 
>
>  
>
>ServerAdmin d...@colouree.com  
>ServerName apps.mycompany.com 
>
>RewriteEngine On 
>RewriteCond %{HTTPS} !=on 
>RewriteRule ^/?(.*) https://%{SERVER_NAME}/$1 [R,L] 
>
>CustomLog /var/log/apache2/access-apps.log common 
>ErrorLog /var/log/apache2/apps.error.log 
>  
>
>  
>
>ServerAdmin d...@colouree.com  
>ServerName apps.mycompany.com 
>
>SSLEngine on 
>
>WSGIDaemonProcess web2py python-home=/path/to/pyenv27 user=myuser 
> group=mygroup processes=1 threads=1 
>WSGIProcessGroup web2py 
>WSGIScriptAlias / /path/to/web2py/wsgihandler.py 
>WSGIPassAuthorization On 
>
> 
>  AllowOverride None 
>  Require all denied 
>   
>Require all granted 
>   
> 
>
>AliasMatch ^/([^/]+)/static/(?:_[\d]+.[\d]+.[\d]+/)?(.*) 
> /path/to/web2py/applications/$1/static/$2 
>
> 
>  Options -Indexes 
>  ExpiresActive On 
>  ExpiresDefault "access plus 1 hour" 
>  Require all granted 
> 
>
>Include /etc/letsencrypt/options-ssl-apache.conf 
>
>CustomLog /var/log/apache2/ssl-apps-access.log common 
>ErrorLog /var/log/apache2/apps-error.log 
>ServerAlias applications.colouree.com 
>SSLCertificateFile /etc/letsencrypt/live/
> apps.mycompany.com/fullchain.pem 
>SSLCertificateKeyFile 
> /etc/letsencrypt/live/apps.mycompany.com/privkey.pem 
>  
>
> can I simply duplicate it changing essentials informations such 
> WSGIDaemonProcess definition (I'd like to specify even the path to a 
> different virtualenv based on python 3 in the second case) and other 
> stuff? 
>
> Thank you very much 
>
> Best regards 
>
>  Manuele 
>
> [1] http://web2py.com/books/default/chapter/29/13/deployment-recipes 
>
>

-- 
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/7619ac9c-549f-49fb-87b8-3cb6d10a3747%40googlegroups.com.


[web2py] Re: Splitting long controller file

2019-08-22 Thread Tim Nyborg
Admittedly, splitting a lot of the functions into a module would be the 
best solution.

We recently had the same challenge, and moved a bunch of functions from our 
default controller into their own functions, without having to change 
frontend calls.  This only worked because the functions were in the default 
controller, which was hidden in URLs by default. Function "whatever" in 
default.py became function "index" in whatever.py.  so any call to 
website.com/whatever still worked

Alternately, you can move the support functions into a model file(s) that 
only gets loaded for that controller.

On Wednesday, 21 August 2019 21:45:38 UTC+1, clara wrote:
>
> Hello,
>
> Maybe this may sound trivial (bear with me, please) but here is my 
> question: I have a long controller module that I would want to split up or 
> make more manageable . Most of the functions in this controllers are 
> controller functions called from the frontend. 
>
> Now, I guess I could refactor the module and have some support functions 
> and create a new module in the "modules" folder. This has brought me 
> problems in windows environment, so I would try to avoid it. 
>
> I could create other controller modules and move some controller functions 
> to them, but then I would need to update the frontend ajax calls. 
>
> Any ideas?
>
> Thanks in advance.
>
>

-- 
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/d69eef3d-cac8-4a9f-9c91-468cc7ab766a%40googlegroups.com.


[web2py] Re: Could this problem in production be related to web2py?

2019-06-07 Thread Tim Nyborg
You're exactly right - I'll probably wind up with two instances, once 
RAM-only for caching, and a persistent one for sessions.

On Friday, 7 June 2019 14:15:35 UTC+1, Lisandro wrote:
>
> I'm not exactly sure how many sessions my app is handling, but this 
> numbers will give you an idea:
>
>  - My websites receive about 500k visits (sessions) in an average day.
>  - The server handles about 2.5 million requests in an average day.
>  - I use RedisSession(session_expiry=36000), that is, sessions handled by 
> Redis expire after 10 hours.
>  - I also use Redis to store in cache the final HTML of public pages for 5 
> minutes.
>  - My Redis instance uses about 12gb of RAM. 
>  - My Redis instance consumes only about 8% of CPU (that is the 8% of one 
> single CPU, notice Redis is single-threaded).
>
>
> When you say "I'd want to ensure disk-persistence for them (but not for 
> cached things like search results)", how do you plan to achieve that? I'm 
> no expert, but I think the disk-persistance option in Redis is global. If 
> you want persistance for sessions and not for other cached things, I think 
> you will need to different instances of Redis. 
>
>
> El viernes, 7 de junio de 2019, 7:09:26 (UTC-3), Tim Nyborg escribió:
>>
>> Thanks for this.  Let me know if you find a resolution to the 'saving to 
>> disk' latency issue.  Redis sessions would be an improvement, but I'd want 
>> to ensure disk-persistence for them (but not for cached things like search 
>> results).  How many sessions are you storing, and how much RAM does it 
>> consume?
>>
>> On Thursday, 6 June 2019 20:33:28 UTC+1, Lisandro wrote:
>>>
>>> If you're going to add Redis, let me add a couple of comments about my 
>>> own experience:
>>>
>>>  - Using Redis to store sessions (not only to cache) was a huge 
>>> improvement in my case. I have public websites, some of them with much 
>>> traffic, so my app handles many sessions. I was using the database for 
>>> handling sessions, but when I changed to Redis, the performance improvement 
>>> was considerable. 
>>>
>>>  - Do some tests with the argument "with_lock" available in RedisCache 
>>> and RedisSessions (from gluon.contrib). In my specific case, using 
>>> with_lock=False is better, but of course this depends on each specific 
>>> scenario.
>>>
>>>  - An advise: choose proper values for "maxmemory" and 
>>> "maxmemory-policy" options from Redis configuration. The first one sets the 
>>> max amount of memory that Redis is allowed to use, and "maxmemory-policy" 
>>> allows you to choose how Redis should evict keys when it hits the 
>>> maxmemory: https://redis.io/topics/lru-cache. 
>>>
>>>
>>> El jueves, 6 de junio de 2019, 12:15:38 (UTC-3), Tim Nyborg escribió:
>>>>
>>>> This is really good to know.  I've a similar architecture to you, and 
>>>> am planning to add redis to the stack soon.  Knowing about issues to be on 
>>>> the lookout for is very helpful.
>>>>
>>>> On Friday, 24 May 2019 16:26:50 UTC+1, Lisandro wrote:
>>>>>
>>>>> I've found the root cause of the issue: the guilty was Redis.
>>>>>
>>>>> This is what was happening: Redis has an option for persistance 
>>>>> <https://redis.io/topics/persistence> wich stores the DB to the disk 
>>>>> every certain amount of time. The configuration I had was the one that 
>>>>> comes by default with Redis, that stores the DB every 15 minutes if at 
>>>>> least 1 key changed, every 5 minutes if at least 10 keys changed, and 
>>>>> every 
>>>>> 60 seconds if 1 keys changed. My Redis instance was saving DB to the 
>>>>> disk every minute, and the saving process was taking about 70 seconds. 
>>>>> Apparently, during that time, many of the requests were hanging. What I 
>>>>> did 
>>>>> was to simply disable the saving process (I can do it in my case because 
>>>>> I 
>>>>> don't need persistance). 
>>>>>
>>>>> I'm not sure why this happens. I know that Redis is single-threaded, 
>>>>> but its documentation states that many tasks (such as saving the DB) run 
>>>>> in 
>>>>> a separate thread that Redis creates. So I'm not sure how is that the 
>>>>> process of saving DB to the disk is making the other Redis operations 
>>>>> hang. 
>>>>> Bu

[web2py] Re: Could this problem in production be related to web2py?

2019-06-07 Thread Tim Nyborg
Thanks for this.  Let me know if you find a resolution to the 'saving to 
disk' latency issue.  Redis sessions would be an improvement, but I'd want 
to ensure disk-persistence for them (but not for cached things like search 
results).  How many sessions are you storing, and how much RAM does it 
consume?

On Thursday, 6 June 2019 20:33:28 UTC+1, Lisandro wrote:
>
> If you're going to add Redis, let me add a couple of comments about my own 
> experience:
>
>  - Using Redis to store sessions (not only to cache) was a huge 
> improvement in my case. I have public websites, some of them with much 
> traffic, so my app handles many sessions. I was using the database for 
> handling sessions, but when I changed to Redis, the performance improvement 
> was considerable. 
>
>  - Do some tests with the argument "with_lock" available in RedisCache and 
> RedisSessions (from gluon.contrib). In my specific case, using 
> with_lock=False is better, but of course this depends on each specific 
> scenario.
>
>  - An advise: choose proper values for "maxmemory" and "maxmemory-policy" 
> options from Redis configuration. The first one sets the max amount of 
> memory that Redis is allowed to use, and "maxmemory-policy" allows you to 
> choose how Redis should evict keys when it hits the maxmemory: 
> https://redis.io/topics/lru-cache. 
>
>
> El jueves, 6 de junio de 2019, 12:15:38 (UTC-3), Tim Nyborg escribió:
>>
>> This is really good to know.  I've a similar architecture to you, and am 
>> planning to add redis to the stack soon.  Knowing about issues to be on the 
>> lookout for is very helpful.
>>
>> On Friday, 24 May 2019 16:26:50 UTC+1, Lisandro wrote:
>>>
>>> I've found the root cause of the issue: the guilty was Redis.
>>>
>>> This is what was happening: Redis has an option for persistance 
>>> <https://redis.io/topics/persistence> wich stores the DB to the disk 
>>> every certain amount of time. The configuration I had was the one that 
>>> comes by default with Redis, that stores the DB every 15 minutes if at 
>>> least 1 key changed, every 5 minutes if at least 10 keys changed, and every 
>>> 60 seconds if 1 keys changed. My Redis instance was saving DB to the 
>>> disk every minute, and the saving process was taking about 70 seconds. 
>>> Apparently, during that time, many of the requests were hanging. What I did 
>>> was to simply disable the saving process (I can do it in my case because I 
>>> don't need persistance). 
>>>
>>> I'm not sure why this happens. I know that Redis is single-threaded, but 
>>> its documentation states that many tasks (such as saving the DB) run in a 
>>> separate thread that Redis creates. So I'm not sure how is that the process 
>>> of saving DB to the disk is making the other Redis operations hang. But 
>>> this is what was happening, and I'm able to confirm that, after disabling 
>>> the DB saving process, my application response times have decreased to 
>>> expected values, no more timeouts :)
>>>
>>> I will continue to investigate this issue with Redis in the proper 
>>> forum. 
>>> I hope this helps anyone facing the same issue.
>>>
>>> Thanks for the help!
>>>
>>> El lunes, 13 de mayo de 2019, 13:49:26 (UTC-3), Lisandro escribió:
>>>>
>>>> After doing a lot of reading about uWSGI, I've discovered that "uWSGI 
>>>> cores are not CPU cores" (this was confirmed by unbit developers 
>>>> <https://github.com/unbit/uwsgi/issues/233#issuecomment-16456919>, the 
>>>> ones that wrote and mantain uWSGI). This makes me think that the issue I'm 
>>>> experiencing is due to a misconfiguration of uWSGI. But as I'm a developer 
>>>> and not a sysadmin, it's being hard for me to figure out exactly what 
>>>> uWSGI 
>>>> options should I tweak. 
>>>>
>>>> I know this is out of the scope of this group, but I'll post my uWSGI 
>>>> app configuration anyway, in case someone still wants to help:
>>>>
>>>> [uwsgi]
>>>> pythonpath = /var/www/medios/
>>>> mount = /=wsgihandler:application
>>>> master = true
>>>> workers = 40
>>>> cpu-affinity = 3
>>>> lazy-apps = true
>>>> harakiri = 60
>>>> reload-mercy = 8
>>>> max-requests = 4000
>>>> no-orphans = true
>>>> vacuum = true
>>>> buffer-size = 32768
>>>> disable-logging = true
>>>> ignore-sigp

[web2py] Re: Could this problem in production be related to web2py?

2019-06-06 Thread Tim Nyborg
This is really good to know.  I've a similar architecture to you, and am 
planning to add redis to the stack soon.  Knowing about issues to be on the 
lookout for is very helpful.

On Friday, 24 May 2019 16:26:50 UTC+1, Lisandro wrote:
>
> I've found the root cause of the issue: the guilty was Redis.
>
> This is what was happening: Redis has an option for persistance 
>  wich stores the DB to the disk 
> every certain amount of time. The configuration I had was the one that 
> comes by default with Redis, that stores the DB every 15 minutes if at 
> least 1 key changed, every 5 minutes if at least 10 keys changed, and every 
> 60 seconds if 1 keys changed. My Redis instance was saving DB to the 
> disk every minute, and the saving process was taking about 70 seconds. 
> Apparently, during that time, many of the requests were hanging. What I did 
> was to simply disable the saving process (I can do it in my case because I 
> don't need persistance). 
>
> I'm not sure why this happens. I know that Redis is single-threaded, but 
> its documentation states that many tasks (such as saving the DB) run in a 
> separate thread that Redis creates. So I'm not sure how is that the process 
> of saving DB to the disk is making the other Redis operations hang. But 
> this is what was happening, and I'm able to confirm that, after disabling 
> the DB saving process, my application response times have decreased to 
> expected values, no more timeouts :)
>
> I will continue to investigate this issue with Redis in the proper forum. 
> I hope this helps anyone facing the same issue.
>
> Thanks for the help!
>
> El lunes, 13 de mayo de 2019, 13:49:26 (UTC-3), Lisandro escribió:
>>
>> After doing a lot of reading about uWSGI, I've discovered that "uWSGI 
>> cores are not CPU cores" (this was confirmed by unbit developers 
>> , the 
>> ones that wrote and mantain uWSGI). This makes me think that the issue I'm 
>> experiencing is due to a misconfiguration of uWSGI. But as I'm a developer 
>> and not a sysadmin, it's being hard for me to figure out exactly what uWSGI 
>> options should I tweak. 
>>
>> I know this is out of the scope of this group, but I'll post my uWSGI app 
>> configuration anyway, in case someone still wants to help:
>>
>> [uwsgi]
>> pythonpath = /var/www/medios/
>> mount = /=wsgihandler:application
>> master = true
>> workers = 40
>> cpu-affinity = 3
>> lazy-apps = true
>> harakiri = 60
>> reload-mercy = 8
>> max-requests = 4000
>> no-orphans = true
>> vacuum = true
>> buffer-size = 32768
>> disable-logging = true
>> ignore-sigpipe = true
>> ignore-write-errors = true
>> listen = 65535
>> disable-write-exception = true
>>
>>
>> Just to remember, this is running on a machine with 16 CPUs.
>> Maybe I should *enable-threads*, set *processes* options and maybe tweak 
>> *cpu-affinity. *
>> My application uses Redis for caching, so I think I can enable threads 
>> safely. 
>> What do you think?
>>
>>
>> El jueves, 9 de mayo de 2019, 21:10:57 (UTC-3), Lisandro escribió:
>>>
>>> I've checked my app's code once again and I can confirm that it doesn't 
>>> create threads. It only uses subprocess.cal() within functions that are 
>>> called in the scheduler environment, I understand that's the proper way to 
>>> do it because those calls don't run in uwsgi environment.
>>>
>>> In the other hand, I can't disable the master process, I use "lazy-apps" 
>>> and "touch-chain-reload" options of uwsgi in order to achieve graceful 
>>> reloading, because acordingly to the documentation about graceful 
>>> reloading 
>>> 
>>> :
>>> *"All of the described techniques assume a modern (>= 1.4) uWSGI release 
>>> with the master process enabled."*
>>>
>>> Graceful reloading allows me to update my app's code and reload uwsgi 
>>> workers smoothly, without downtime or errors. What can I do if I can't 
>>> disable master process?
>>>
>>> You mentioned the original problem seems to be a locking problem due to 
>>> threads. If my app doesn't open threads, where else could be the cause of 
>>> the issue? 
>>>
>>> The weirdest thing for me is that the timeouts are always on core 0. I 
>>> mean, uwsgi runs between 30 and 45 workers over 16 cores, isn't too much of 
>>> a coincidence that requests that hang correspond to a few workers always 
>>> assigned on core 0?
>>>
>>>
>>> El jueves, 9 de mayo de 2019, 17:10:19 (UTC-3), Leonel Câmara escribió:

 Yes I meant stuff exactly like that.

>>>

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

[web2py] Re: nginx, basic auth: internal error

2019-05-08 Thread Tim Nyborg
My guess is that something is wrong with the file permissions on the 
sessions folder/subfolders.  If uwsgi is trying to write a session file and 
failing, you'll get an unrecoverable error.

On Wednesday, 8 May 2019 07:49:34 UTC+1, tomasz bandura wrote:
>
> Hello,
>
> I use web2py (2.16.1) on 2 environments:
> 1. Embedded Rocket wsgi server
> 2. Deployed on nginx+uwsgi
>
> I have the same application on both env, connected to the same database.
> The application uses Basic Authentication, like in the example:
>
> def f1():
>
>   auth.basic()  if auth.user:
> *## do something ...*  else:
> *## raise defined auth exception*
>
>
> What is strange, the problem occures only on nginx+uwsgi: 
> 1. If I call it without basic authorization it will raise defined 
> exception correctly
> 2. The problem is when I put header with correct authorization - it raises 
> *Internal 
> error Ticked issued: uncoverable*, and there is no any traces in logs.
>
> The solution is putting *session.forget() *before *auth.basic()*, but why?
>
> Could someone explain me the impact of session.forget() for that behaviour?
>
> According documentation it is used to avoid storing session ( and it 
> is understandable)
>
> Regards,
> Tomasz
>

-- 
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/069ab380-b514-42e7-92d7-05b0c6c70dd7%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[web2py] Re: Custom validator broken in 2.18.4, working in 2.17.2

2019-04-11 Thread tim . nyborg
The web2py book's example could use replacing, since it relies on using 
__init__ and returning (value, error) rather than using def validate and 
returning value or raising ValidationError

On Sunday, 7 April 2019 05:36:13 UTC+1, Massimo Di Pierro wrote:
>
> we will fix the backward incompatibility asap. Not intentional.
>
> On Saturday, 6 April 2019 12:12:47 UTC-7, David Manns wrote:
>>
>> PS this is not backward compatible to 2.17.2
>>
>> On Thursday, April 4, 2019 at 4:52:37 PM UTC-4, David Manns wrote:
>>>
>>> The table in question has a field:
>>>
>>> Field('Paiddate', 'date', requires = [IS_EMPTY_OR(IS_DATE()), 
>>> IS_EMPTY_OR(IS_MEMBERSHIP_YEAR_END())]),
>>>
>>> The custom validator is:
>>>
>>> class IS_MEMBERSHIP_YEAR_END(object):
>>> def __init__(self, error_message='Not a membership year end'):
>>> self.error_message = error_message
>>> def __call__(self, value):
>>> yearend = datetime.date(2018,9,30)
>>> if value.month==yearend.month and value.day==yearend.day:
>>> return (value, None)
>>> return (value, self.error_message)
>>>
>>> This works in 2.17.2
>>>
>>> I updated my test environment to 2.18.4 and it fails.
>>>
>>> On the console I see:
>>>
>>> web2py Web Framework
>>> Created by Massimo Di Pierro, Copyright 2007-2019
>>> Version 2.18.4-stable+timestamp.2019.03.13.05.27.54
>>> Database drivers available: sqlite3, imaplib, pyodbc, pymysql
>>> please visit:
>>> ('\t', 'http://127.0.0.1:8000/')
>>> starting browser...
>>> Traceback (most recent call last):
>>>   File "C:\Users\David\Google Drive\Oxcamne Archive\Web 
>>> Site\OxCamNE.2.1\gluon\html.py", line 1890, in _validate
>>> (value, errors) = validator(value)
>>>   File "C:\Users\David\Google Drive\Oxcamne Archive\Web 
>>> Site\OxCamNE.2.1\gluon\packages\dal\pydal\validators.py", line 144, in 
>>> __call__
>>> return self.validate(value), None
>>>   File "C:\Users\David\Google Drive\Oxcamne Archive\Web 
>>> Site\OxCamNE.2.1\gluon\packages\dal\pydal\validators.py", line 2754, in 
>>> validate
>>> return self.other.validate(value)
>>> AttributeError: 'IS_MEMBERSHIP_YEAR_END' object has no attribute 
>>> 'validate'
>>>
>>> The ticket shows:
>>>
>>> Error ticket for "init" Ticket ID 
>>>
>>> 127.0.0.1.2019-04-04.16-41-08.0dce185d-d8d2-4d36-9e47-8c82bc1d54f5
>>>  Validation error, field:Paiddate 
>>>  Version 
>>> web2py™ Version 2.18.4-stable+timestamp.2019.03.13.05.27.54 
>>> Python Python 2.7.14: C:\Python27\python.exe (prefix: C:\Python27) 
>>> Traceback 
>>>
>>> 1.
>>> 2.
>>> 3.
>>> 4.
>>> 5.
>>> 6.
>>> 7.
>>> 8.
>>> 9.
>>> 10.
>>> 11.
>>> 12.
>>> 13.
>>> 14.
>>> 15.
>>> 16.
>>> 17.
>>> 18.
>>> 19.
>>> 20.
>>> 21.
>>> 22.
>>> 23.
>>> 24.
>>> 25.
>>> 26.
>>> 27.
>>> 28.
>>> 29.
>>> 30.
>>>
>>> Traceback (most recent call last):
>>>   File "C:\Users\David\Google Drive\Oxcamne Archive\Web 
>>> Site\OxCamNE.2.1\gluon\restricted.py", line 219, in restricted
>>> exec(ccode, environment)
>>>   File "C:\Users\David\Google Drive\Oxcamne Archive\Web 
>>> Site\OxCamNE.2.1\applications\init\controllers/default.py", line 1747, in 
>>> 
>>>   File "C:\Users\David\Google Drive\Oxcamne Archive\Web 
>>> Site\OxCamNE.2.1\gluon\globals.py", line 421, in 
>>> self._caller = lambda f: f()
>>>   File "C:\Users\David\Google Drive\Oxcamne Archive\Web 
>>> Site\OxCamNE.2.1\applications\init\models\db.py", line 109, in wrapped_f
>>> return f(*args)
>>>   File "C:\Users\David\Google Drive\Oxcamne Archive\Web 
>>> Site\OxCamNE.2.1\applications\init\controllers/default.py", line 214, in 
>>> memberform
>>> deletable = dltbl, onvalidation=setmodified, onaccept=modmember, 
>>> ondelete=delmember)
>>>   File "C:\Users\David\Google Drive\Oxcamne Archive\Web 
>>> Site\OxCamNE.2.1\gluon\tools.py", line 4322, in update
>>> detect_record_change=self.settings.detect_record_change):
>>>   File "C:\Users\David\Google Drive\Oxcamne Archive\Web 
>>> Site\OxCamNE.2.1\gluon\sqlhtml.py", line 1758, in accepts
>>> **kwargs
>>>   File "C:\Users\David\Google Drive\Oxcamne Archive\Web 
>>> Site\OxCamNE.2.1\gluon\html.py", line 2149, in accepts
>>> status = self._traverse(status, hideerror)
>>>   File "C:\Users\David\Google Drive\Oxcamne Archive\Web 
>>> Site\OxCamNE.2.1\gluon\html.py", line 910, in _traverse
>>> newstatus = c._traverse(status, hideerror) and newstatus
>>>   File "C:\Users\David\Google Drive\Oxcamne Archive\Web 
>>> Site\OxCamNE.2.1\gluon\html.py", line 910, in _traverse
>>> newstatus = c._traverse(status, hideerror) and newstatus
>>>   File "C:\Users\David\Google Drive\Oxcamne Archive\Web 
>>> Site\OxCamNE.2.1\gluon\html.py", line 910, in _traverse
>>> newstatus = c._traverse(status, hideerror) and newstatus
>>>   File "C:\Users\David\Google Drive\Oxcamne Archive\Web 
>>> Site\OxCamNE.2.1\gluon\html.py", line 910, in _traverse
>>> newstatus = c._traverse(status, hideerror) and newstatus
>>>   File "C:\Users\David\Google Drive\Oxcamne Archive\Web 
>>> 

[web2py] Re: How can I convert a SUM from a SQLite SELECT statement to web2py's DAL?

2019-04-03 Thread tim . nyborg
Apologies.  Left a lot of cruft in there which should be edited out now.

On Wednesday, 3 April 2019 17:10:49 UTC+1, tim@conted.ox.ac.uk wrote:
>
> That will be different.  SQLFORM.grid doesn't support aggregation, so 
> you'll need to use virtual fields to do the work, which is what I do to 
> show invoices along with their current calculated balance.  It's not 
> sortable, though.
>
> Something like:
>
> def is_operador(row):
> return not db(
> (row.auth_user.id == db.auth_membership.user_id)
> & (db.auth_group.id == db.auth_membership.group_id)
> & (db.auth_group.role == 'operador')
> ).isempty()
>
> db.auth_user.is_operador = Field.Virtual('is_operador', is_operador)
>
> grid = SQLFORM.grid(
> db.auth_user
> )
>
> You'll need a virtual field for each row, and it's running subqueries so 
> it's not as light on the DB, but it works without needing a hand-rolled 
> table.
>
>
> On Wednesday, 3 April 2019 16:37:16 UTC+1, João Matos wrote:
>>
>> Thanks. That worked. I just corrected the groupby you sent.
>>
>> Now I have another problem. Unfortunately a SQLFORM.grid doesn't accept a 
>> SELECT.
>> The only solution I have is to create a view in SQLite, which defies the 
>> purpose of moving from the SQLite SELECT to DAL.
>>
>> Any ideas on how I can solve this?
>>
>> Thanks,
>>
>> JM
>>
>> quarta-feira, 3 de Abril de 2019 às 16:24:24 UTC+1, 
>> tim@conted.ox.ac.uk escreveu:
>>>
>>> I think that implicit conversion of "auth_group.role = 'Operador'" to a 
>>> 1 is a Sqlite-specific thing.  What you want to use here is case:
>>>
>>> query = db().select(
>>> db.auth_user.id,
>>> db.auth_user.username,
>>> db.auth_user.canceled_on,
>>> db.auth_user.canceled_by,
>>> (db.auth_group.role == 'Operador').case(1, 0).sum().with_alias('
>>> operador'),
>>> (db.auth_group.role == 'Verificador').case(1, 0).sum().with_alias('
>>> verificador'),
>>> (db.auth_group.role == 'Supervisor').case(1, 0).sum().with_alias('
>>> Supervisor'),
>>>
>>> left=(
>>> db.auth_membership.on(db.auth_user.id == db.auth_membership.
>>> user_id),
>>> db.auth_group.on(db.auth_group.id == db.auth_membership.group_id
>>> ),
>>> ),
>>> groupby=[db.auth_user.username, db.auth_user.id, db.auth_user.
>>> canceled_on, db.auth_user.canceled_by],
>>> orderby=db.auth_user.username,
>>> )
>>>
>>> On Monday, 1 April 2019 23:41:51 UTC+1, João Matos wrote:

 Hello,

 I have this SELECT in SQLite

 result = db.executesql(
 "SELECT auth_user.id, auth_user.username, "
 "auth_user.canceled_on, "
 "auth_user.canceled_by, "
 "SUM(auth_group.role = 'Operador') operador, "
 "SUM(auth_group.role = 'Verificador') verificador, "
 "SUM(auth_group.role = 'Supervisor') supervisor "
 "FROM auth_user "
 "LEFT JOIN auth_membership ON auth_user.id = 
 auth_membership.user_id "
 "LEFT JOIN auth_group ON auth_group.id = 
 auth_membership.group_id "
 "GROUP BY username ORDER BY username"
 )

 and would like to convert it to web2py's DAL.
 I made this

 query = db().select(
 db.auth_user.id,
 db.auth_user.username,
 db.auth_user.canceled_on,
 db.auth_user.canceled_by,
 left=(
 db.auth_membership.on(db.auth_user.id == db.auth_membership.
 user_id),
 db.auth_group.on(db.auth_group.id == db.auth_membership.
 group_id),
 ),
 groupby=db.auth_user.username,
 orderby=db.auth_user.username,
 )

 but I can't find any way to integrate the sums.

 Does anyone know how to do it?

 Thanks,

 JM

>>>

-- 
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 can I convert a SUM from a SQLite SELECT statement to web2py's DAL?

2019-04-03 Thread tim . nyborg
That will be different.  SQLFORM.grid doesn't support aggregation, so 
you'll need to use virtual fields to do the work, which is what I do to 
show invoices along with their current calculated balance.  It's not 
sortable, though.

Something like:

def is_operador(row):
return not idb(
(row.auth_user.id == db.auth_membership.user_id)
& (db.auth_group.id == db.auth_membership.group_id)
& (db.auth_group.role == 'operador')
).isempty()

idb.auth_user.is_operador = Field.Virtual('is_operador', is_operador)

db = idb
grid = SQLFORM.grid(
db.auth_user,

details=False,
create=False
)

You'll need a virtual field for each row, and it's running subqueries so 
it's not as light on the DB, but it works without needing a hand-rolled 
table.


On Wednesday, 3 April 2019 16:37:16 UTC+1, João Matos wrote:
>
> Thanks. That worked. I just corrected the groupby you sent.
>
> Now I have another problem. Unfortunately a SQLFORM.grid doesn't accept a 
> SELECT.
> The only solution I have is to create a view in SQLite, which defies the 
> purpose of moving from the SQLite SELECT to DAL.
>
> Any ideas on how I can solve this?
>
> Thanks,
>
> JM
>
> quarta-feira, 3 de Abril de 2019 às 16:24:24 UTC+1, 
> tim@conted.ox.ac.uk escreveu:
>>
>> I think that implicit conversion of "auth_group.role = 'Operador'" to a 1 
>> is a Sqlite-specific thing.  What you want to use here is case:
>>
>> query = db().select(
>> db.auth_user.id,
>> db.auth_user.username,
>> db.auth_user.canceled_on,
>> db.auth_user.canceled_by,
>> (db.auth_group.role == 'Operador').case(1, 0).sum().with_alias('
>> operador'),
>> (db.auth_group.role == 'Verificador').case(1, 0).sum().with_alias('
>> verificador'),
>> (db.auth_group.role == 'Supervisor').case(1, 0).sum().with_alias('
>> Supervisor'),
>>
>> left=(
>> db.auth_membership.on(db.auth_user.id == db.auth_membership.
>> user_id),
>> db.auth_group.on(db.auth_group.id == db.auth_membership.group_id
>> ),
>> ),
>> groupby=[db.auth_user.username, db.auth_user.id, db.auth_user.
>> canceled_on, db.auth_user.canceled_by],
>> orderby=db.auth_user.username,
>> )
>>
>> On Monday, 1 April 2019 23:41:51 UTC+1, João Matos wrote:
>>>
>>> Hello,
>>>
>>> I have this SELECT in SQLite
>>>
>>> result = db.executesql(
>>> "SELECT auth_user.id, auth_user.username, "
>>> "auth_user.canceled_on, "
>>> "auth_user.canceled_by, "
>>> "SUM(auth_group.role = 'Operador') operador, "
>>> "SUM(auth_group.role = 'Verificador') verificador, "
>>> "SUM(auth_group.role = 'Supervisor') supervisor "
>>> "FROM auth_user "
>>> "LEFT JOIN auth_membership ON auth_user.id = 
>>> auth_membership.user_id "
>>> "LEFT JOIN auth_group ON auth_group.id = 
>>> auth_membership.group_id "
>>> "GROUP BY username ORDER BY username"
>>> )
>>>
>>> and would like to convert it to web2py's DAL.
>>> I made this
>>>
>>> query = db().select(
>>> db.auth_user.id,
>>> db.auth_user.username,
>>> db.auth_user.canceled_on,
>>> db.auth_user.canceled_by,
>>> left=(
>>> db.auth_membership.on(db.auth_user.id == db.auth_membership.
>>> user_id),
>>> db.auth_group.on(db.auth_group.id == db.auth_membership.group_id
>>> ),
>>> ),
>>> groupby=db.auth_user.username,
>>> orderby=db.auth_user.username,
>>> )
>>>
>>> but I can't find any way to integrate the sums.
>>>
>>> Does anyone know how to do it?
>>>
>>> Thanks,
>>>
>>> JM
>>>
>>

-- 
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 can I convert a SUM from a SQLite SELECT statement to web2py's DAL?

2019-04-03 Thread tim . nyborg
I think that implicit conversion of "auth_group.role = 'Operador'" to a 1 
is a Sqlite-specific thing.  What you want to use here is case:

query = db().select(
db.auth_user.id,
db.auth_user.username,
db.auth_user.canceled_on,
db.auth_user.canceled_by,
(db.auth_group.role == 'Operador').case(1, 0).sum().with_alias('operador
'),
(db.auth_group.role == 'Verificador').case(1, 0).sum().with_alias('
verificador'),
(db.auth_group.role == 'Supervisor').case(1, 0).sum().with_alias('
Supervisor'),

left=(
db.auth_membership.on(db.auth_user.id == db.auth_membership.user_id
),
db.auth_group.on(db.auth_group.id == db.auth_membership.group_id),
),
groupby=[db.auth_user.username, db.auth_user.id],
orderby=db.auth_user.username,
)

On Monday, 1 April 2019 23:41:51 UTC+1, João Matos wrote:
>
> Hello,
>
> I have this SELECT in SQLite
>
> result = db.executesql(
> "SELECT auth_user.id, auth_user.username, "
> "auth_user.canceled_on, "
> "auth_user.canceled_by, "
> "SUM(auth_group.role = 'Operador') operador, "
> "SUM(auth_group.role = 'Verificador') verificador, "
> "SUM(auth_group.role = 'Supervisor') supervisor "
> "FROM auth_user "
> "LEFT JOIN auth_membership ON auth_user.id = 
> auth_membership.user_id "
> "LEFT JOIN auth_group ON auth_group.id = 
> auth_membership.group_id "
> "GROUP BY username ORDER BY username"
> )
>
> and would like to convert it to web2py's DAL.
> I made this
>
> query = db().select(
> db.auth_user.id,
> db.auth_user.username,
> db.auth_user.canceled_on,
> db.auth_user.canceled_by,
> left=(
> db.auth_membership.on(db.auth_user.id == db.auth_membership.
> user_id),
> db.auth_group.on(db.auth_group.id == db.auth_membership.group_id),
> ),
> groupby=db.auth_user.username,
> orderby=db.auth_user.username,
> )
>
> but I can't find any way to integrate the sums.
>
> Does anyone know how to do it?
>
> Thanks,
>
> JM
>

-- 
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 SET A DEFAULT VALUE FOR A TABLE REFERENCED IN ANOTHER TABLE

2018-11-09 Thread tim . nyborg
You set the default in client:

db.define_table(
'client',
Field('city', db.city, default='Value here'),
)


On Friday, 9 November 2018 04:59:23 UTC, mostwanted wrote:
>
> if i have 2 table client and city and have city referenced in client, how 
> do i set a default value for city that will appear in client?
> I tried setting default in city hoping it will show as a default value in 
> client but its not showing!
> I hope this explanation of the problem is clear enough it doesn't need a 
> code example.
>
> Thank You
>
> 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.
For more options, visit https://groups.google.com/d/optout.


[web2py] cache.ram with nginx/uwsgi

2018-09-13 Thread tim . nyborg
Is it possible for cache.ram to work if running on nginx/uwsgi, 
particularly with multiple processes?

I don't really care if each of my processes (4) winds up with its own cache 
in memory, but they seem to expire very quickly.  

Moving to cache.disk or Redis may be the way to go, but if simple ram 
caching can work, I'd sooner go that route.

-- 
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: Setting filename to a streamed file

2018-09-13 Thread tim . nyborg
Are you setting the PDF's title before streaming it?

pdf.set_title('Whatever you want to appear in the tab')
pdf_stream = pdf.output(dest='S')



On Thursday, 6 September 2018 13:16:32 UTC+1, Simona Chovancová wrote:
>
> Hello.
> I have a backend function that is supposed to stream a pdf file, but not 
> instantly download it. It's being called like this 
> .../function_to_create_pdf/323, where the number is some ID. I create a 
> FPDF stream and make function return this
> response.headers['Content-Type'] = None
> return response.stream(pdf_stream, 4096, filename="iwanthisname.pdf")
>
> Soo the problem is, this works well if I set attachment=True, but since I 
> only want to display this pdf file, the filename is not applied in any way. 
> I get the right document and all that, but the browser tab title is 
> basically just the argument (ID) I passed to the function and if I press 
> the download button it is saved as 323.pdf. I want to edit its name, how 
> can I do this? I tried changing tab name with reponse.title, but it didn't 
> work. 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.


Re: [web2py] SQLFORM IS_NOT_EMPTY validator dependent on the value of another request vara

2018-01-25 Thread tim . nyborg
You need to use the onvalidation option in SQLFORM to do validation 
spanning several columns:

def _validate_other(form):
if form.vars.select_field == 'Other' and not form.vars.other:
form.errors.other = 'Please provide a value'

form = SQLFORM(table, onvalidation=_validate_other)

form.process()...



On Monday, 15 January 2018 15:20:28 UTC, Anthony wrote:
>
> On Monday, January 15, 2018 at 8:15:12 AM UTC-5, Javier Pepe wrote:
>>
>> Hi
>>
>> You can use de conditional show_if
>>
>>
>> http://web2py.com/books/default/chapter/29/07/forms-and-validators#Conditional-fields
>>
>> db,table.text_field.show_if = (db.table.select_field == Other)
>>
>
> This is useful for improving the UI, but it will not force the user to 
> enter a value in the text field.
>
> 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: DB model reference field conditions eg. auth_user belonging to a certain group only

2018-01-12 Thread tim . nyborg
You can put conditions into the field validator:

Field('writer_user', 'string', 
requires=IS_IN_DB(
db(
(db.auth_user.id == db.auth_membership.user_id)
& (db.auth_membership.group_id == db.auth_group.id)
& (db.auth_group.role == 'your group here')
),
db.auth_user.id
)



On Friday, 12 January 2018 09:13:07 UTC, Oasis Agano wrote:
>
> Greetings,
>
>
> I have defined a table referencing auth_user, but i want on the web form 
> select box to only bring users belonging to one group,
> not showing all the system users.
>
> i am wondering if i should use a lambda function or if there is a way of 
> adding a condition on a reference field.
>
> E,g returning only users belonging in a writer group on the writer_user 
>
> db.define_table('post',
> Field('post_name','string', label="Name", 
> requires=IS_NOT_EMPTY()),
> Field('description','text', label="Desc"),
> Field('writer_user','reference auth_user', label="User"),
> auth.signature,
> format='%(post_name)s')
>
> 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.


[web2py] Re: auto increment field that reset evry year

2018-01-12 Thread tim . nyborg
I've done this with a table with a year as its id:

idb.define_table(
'next_id',
Field('year', 'id'),
Field('next', 'integer'),
)


def get_next_id(year): 
record = idb.next_id(year)
if not record:
# Auto add new years
idb.next_id.insert(year=year, next=1)
record = idb.next_id(year)
   
# Return the id while incrementing the seed for the next call
id = record.next
record.update_record(next=id + 1)
return id

Probably not bullet-proof against collisions if traffic is extremely high, 
but it works for the 1s of uses per year I use.

On Saturday, 6 January 2018 17:16:31 UTC, Andrea Santini wrote:
>
>  need to create an auto increamet Field that reset to 1 every Year.
>
> db.define_table('protocol',Field('n_protocol'),Field('year_protocol',type='datetime',
>  writable = False, readable = False, default=request.now, 
> requires=(IS_DATETIME(timezone=pytz.timezone("Europe/Gibraltar"),format=('%Y'
>
> The field 'n_protocol' must start to 1 auto increment and return to 1 next 
> year.
>
> Why the date is correct when i insert data but is not correct when i see 
> the data stored in db the date is wrong?
>
> I also tried this:
>
>
>
> ultimo_protocollo= db(db.protocollo.data_protocollo).select().last()
> ieri = ultimo_protocollo.year
> data = datetime.datetime
> oggi = data.year
> db.protocollo.n_protocollo = Field.Virtual('n_protocollo', lambda 
> n_protocollo: (n_protocollo ++ 1) if (ieri == oggi)  else 
> (db.protocollo.n_protocollo =="1"))
>
>
> but i recive error.
>
> Can you please help me?
>
> Thank you guys
>
>

-- 
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: Is there a way to put icon or image picker in form?

2018-01-11 Thread tim . nyborg
If you want to avoid javascript magic, you'll want to create a custom 
widget, probably something extending a dropdown.  However, there are nice 
lightweight js libraries for adding images to dropdown options.

On Tuesday, 9 January 2018 12:33:07 UTC, Dragan Matic wrote:
>
> I would like to have an icon or image picker in form where user could 
> choose from a set of predefined icons. 
> Form would contain a few other fields like a title, text and an icon that 
> would visually mark the topic of the text. Icons could be either pictures 
> in 'static' folder or in 'uploads' (site admin would preload a few icons in 
> a table, something like 'text_topic_symbols' or something similar). 
>
> I've tried doing something like this:
>
> db.define_table('topic_icon', 
> Field('topic_icon_image', 'upload'))
>
> db.define_table('content', 
> Field('title', 'string', length=256, required=True),
> Field('body', 'text', required=True),
> Field('topic_type', 'reference topic_icon'))
>
>
>
> But then I don'k know how to build a FORM that would show image picker. 
>
> Would it be possible to do with web2py or I have to use some javascript 
> magic?
>

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

2018-01-04 Thread tim . nyborg
My interim solution for computed fields is to set writable=False.  It's 
fixed problems with form submission.

On Tuesday, 2 January 2018 19:02:30 UTC, José Leite wrote:
>
> It seems that compute fields are not working anymore with web2py 2.16.1.
> Can not generate thumbnails anymore.
>
> Is there a fix for that?
>
> terça-feira, 14 de Novembro de 2017 às 05:59:52 UTC, Massimo Di Pierro 
> escreveu:
>>
>> web2py 2.16.1 is OUT
>>
>> Lots of bugs fixes contributed by the community. Thanks Leonel, Paolo, 
>> Giovanni, and all those who contributed.
>>
>> the most visible changes are:
>>
>> - welcome now defaults to bootstrap 4
>> - lots of cleanup in the welcome app and new examples in default.py
>> - simplified layout.html
>>
>> Massimo 
>>
>>
>>
>>

-- 
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: Help with icons

2017-12-04 Thread tim . nyborg
Answered my own question: SQLFORM.grid(ui={...})
So either solution is fine.

On Monday, 4 December 2017 16:45:38 UTC, tim.n...@conted.ox.ac.uk wrote:
>
> Since I use fa icons all over the place, and do a fair bit of styling on 
> top of the w2p css, I'd sooner see 'fa fa-{name}' rules.  Not as clean as 
> .icon, I admit, but it makes it easier for global rules to affect the grid.
> Is it possible to pass a dict of custom icon class strings to the grid, so 
> 'icon icon-plus' is the default, but can be replaced by 'fa fa-plus'?
>
> On Sunday, 3 December 2017 17:41:34 UTC, Massimo Di Pierro wrote:
>>
>> In the old days of BS2 we used "icon icon-{name}" for icons. then to 
>> support BS3 we also added "glyphicon glyphicon-{name}". now we use BS4 and 
>> there are no more icons we have to use Font Awesome so we should add "fa 
>> fa-{name}". I can easily add this to sqlhtml.py and we will all be fine but 
>> we will have a proliferation of classes. Another option is to use define 
>> .icon and .icon-{name} for those classes that we use in the grid in terms 
>> of font awesome icons and add them to web2py-bootstrap4.css.
>>
>> Preferences?
>>
>>

-- 
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: Help with icons

2017-12-04 Thread tim . nyborg
Since I use fa icons all over the place, and do a fair bit of styling on 
top of the w2p css, I'd sooner see 'fa fa-{name}' rules.  Not as clean as 
.icon, I admit, but it makes it easier for global rules to affect the grid.
Is it possible to pass a dict of custom icon class strings to the grid, so 
'icon icon-plus' is the default, but can be replaced by 'fa fa-plus'?

On Sunday, 3 December 2017 17:41:34 UTC, Massimo Di Pierro wrote:
>
> In the old days of BS2 we used "icon icon-{name}" for icons. then to 
> support BS3 we also added "glyphicon glyphicon-{name}". now we use BS4 and 
> there are no more icons we have to use Font Awesome so we should add "fa 
> fa-{name}". I can easily add this to sqlhtml.py and we will all be fine but 
> we will have a proliferation of classes. Another option is to use define 
> .icon and .icon-{name} for those classes that we use in the grid in terms 
> of font awesome icons and add them to web2py-bootstrap4.css.
>
> Preferences?
>
>

-- 
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] show_if and radio buttons

2017-12-01 Thread tim . nyborg
Has anyone gotten field.show_if to work with the built-in radio button 
widget?

We've a typical show_if:
idb.amendment.transfer_module.show_if = idb.amendment.transfer_type == 1

And it functions just find if transfer_type uses 
SQLFORM.widgets.integer.widget
or ...options.widget, but not ...radio.widget



-- 
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 position students based on their total averages

2017-11-30 Thread tim . nyborg
I'm not sure I understand the link between student and student_class.  Does 
student.class_name reference class_name.id?

Anyway, I think you need to be joining things up properly, and grouping by 
student:

def generate_report():

marks=db(
  (db.student_class.class_name=='5A')
  & (db.student.class_name == db.student_class.id)
  & (db.marks.student == db.student.id)
).select(
  db.marks.avg().with_alias('average_marks'),
  groupby=db.marks.student,
  orderby=~db.marks.avg()
)

return locals()

Then you can find the position in the rowset.


On Thursday, 30 November 2017 10:27:09 UTC, mostwanted wrote:
>
>
>
> On Thursday, November 30, 2017 at 12:03:06 PM UTC+2, 
> tim.n...@conted.ox.ac.uk wrote:
>>
>> I think you need to give a bit more context.  What are your model 
>> definitions for db.student_class and db.marks?  Does each student have 
>> multiple rows in the marks table?
>>
>
>
>
> *THESE ARE MY MODEL DEFINITIONS:*I put up the only the ones i thought mat 
> be necessary here but if u need anything else please let me know 
>
>> db.define_table('student_class',
>> Field('class_name', requires=IS_NOT_EMPTY()),
>> Field('teacher', 'reference teacher'),
>> format='%(class_name)s')
>>
>> db.define_table('student',
>> Field('surname', requires=IS_NOT_EMPTY()),
>> Field('name', requires=IS_NOT_EMPTY()),
>> Field('photo', 'upload', requires=IS_NOT_EMPTY()),
>> Field('gender', requires=IS_NOT_EMPTY()),
>> Field('residence', requires=IS_NOT_EMPTY()),
>> Field('guardian', 'reference parent'),
>> Field('class_name', 'reference student_class'),
>> Field('dob', 'date', requires=IS_NOT_EMPTY()),
>> format='%(surname)s', migrate=False, false_migrate=True)
>>
>> db.define_table('marks',
>> Field('student', 'reference student'),
>> Field('subject', 'reference subject'),
>> Field('term', 'reference term'),
>> Field('marks', 'float', requires=IS_NOT_EMPTY()),
>> Field('total', 'float', requires=IS_NOT_EMPTY()),
>> Field('percentage','float', readable=False, writable=
>> False),
>> Field('average', 'float', readable=False, writable=False
>> ),
>> Field('grade', readable=False, writable=False),
>> Field('totalAverage', readable=False, writable=False),
>> Field('averageGrade', readable=False, writable=False),
>> Field('comments',type='text',requires=IS_NOT_EMPTY()))
>>
>

-- 
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 position students based on their total averages

2017-11-30 Thread tim . nyborg
I'm not sure I understand the link between student and student_class.  Does 
student.class_name reference class_name.id?

Anyway, I'd do something like this:

def generate_report():

marks=db(
  (db.student_class.class_name=='5A')
  & (db.student.class_name == db.student_class.id)
  & (db.marks.student == db.student.id)
).select(
  db.marks.avg().with_alias('average_marks'),

)

return locals()


On Thursday, 30 November 2017 10:27:09 UTC, mostwanted wrote:
>
>
>
> On Thursday, November 30, 2017 at 12:03:06 PM UTC+2, 
> tim.n...@conted.ox.ac.uk wrote:
>>
>> I think you need to give a bit more context.  What are your model 
>> definitions for db.student_class and db.marks?  Does each student have 
>> multiple rows in the marks table?
>>
>
>
>
> *THESE ARE MY MODEL DEFINITIONS:*I put up the only the ones i thought mat 
> be necessary here but if u need anything else please let me know 
>
>> db.define_table('student_class',
>> Field('class_name', requires=IS_NOT_EMPTY()),
>> Field('teacher', 'reference teacher'),
>> format='%(class_name)s')
>>
>> db.define_table('student',
>> Field('surname', requires=IS_NOT_EMPTY()),
>> Field('name', requires=IS_NOT_EMPTY()),
>> Field('photo', 'upload', requires=IS_NOT_EMPTY()),
>> Field('gender', requires=IS_NOT_EMPTY()),
>> Field('residence', requires=IS_NOT_EMPTY()),
>> Field('guardian', 'reference parent'),
>> Field('class_name', 'reference student_class'),
>> Field('dob', 'date', requires=IS_NOT_EMPTY()),
>> format='%(surname)s', migrate=False, false_migrate=True)
>>
>> db.define_table('marks',
>> Field('student', 'reference student'),
>> Field('subject', 'reference subject'),
>> Field('term', 'reference term'),
>> Field('marks', 'float', requires=IS_NOT_EMPTY()),
>> Field('total', 'float', requires=IS_NOT_EMPTY()),
>> Field('percentage','float', readable=False, writable=
>> False),
>> Field('average', 'float', readable=False, writable=False
>> ),
>> Field('grade', readable=False, writable=False),
>> Field('totalAverage', readable=False, writable=False),
>> Field('averageGrade', readable=False, writable=False),
>> Field('comments',type='text',requires=IS_NOT_EMPTY()))
>>
>>

-- 
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 position students based on their total averages

2017-11-30 Thread tim . nyborg
I think you need to give a bit more context.  What are your model 
definitions for db.student_class and db.marks?  Does each student have 
multiple rows in the marks table?

On Thursday, 30 November 2017 09:12:14 UTC, mostwanted wrote:
>
> I'm at the brink of pulling my hairs out!!!
> Can please please someone out there help me, in my results management 
> system i want to add up the students averages and give the their class 
> positions and level positions according to how their averages add up. 
> Number 1 being the one with position 1 and so on but i dont know how to 
> achieve this!
>
> The paln i came up with was to select the students of the class, add up 
> their averages individually, store them in a list. Then in the view sort 
> them up starting with the highest, select the average that a specific 
> selected student got and its index+1 the use that index as the student's 
> position. This was my perfect plan but its falling apart in code!!
>
> *CONTROLLER*: 
> select the averages of students of a particular specified class and store 
> them in the averages list
> def genrate_report():
> averages=[]
> marks=db(db.student_class.class_name=='5A').select(db.marks.ALL)
> summed=0
> for fo in marks:
> summed +=fo.average
> averages.append(summed)
> return locals()
>
> *VIEW:* the averages are sorted in the list they are in, in a reverse 
> order and the index of the student's total average is selected and used as 
> the student position
> {{
> {{
> percent=sorted(averages, key=int, reverse=True)
> position=percent.index(totalav)+1
> }}
> {{pass}}
>
> {{=percent}}
> {{=grade}}
>
> 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: 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.


[web2py] Re: web2py 2.15.2 is OUT

2017-07-21 Thread tim . nyborg
Actually, this should be simple enough that I can post a fix.

On Friday, 21 July 2017 09:35:34 UTC+1, tim.n...@conted.ox.ac.uk wrote:
>
> Creating a SQLFORM.factory() from tables, or a combination of tables and 
> fields, now breaks, because the underlying logic assumes the tables are 
> fields:
>
> form = SQLFORM.factory(idb.catering, idb.catering_diet)
>
> File "/home/www-data/internal-apps/gluon/sqlhtml.py", line 1922, in factory
> return SQLFORM(DAL(None).define_table(table_name, *[field.clone() for 
> field in fields]),
> AttributeError: 'Table' object has no attribute 'clone'
>
>
> On Wednesday, 19 July 2017 13:25:52 UTC+1, Massimo Di Pierro wrote:
>>
>> web2py 2.15.2 is OUT is includes a few major bug fixes to version 2.15.1. 
>> Thanks Leonel for the quick fixes.
>> There a few other outstanding problems and they will be resolved in the 
>> next week.
>>
>> For new users 2.15.2 is still better than previous versions. For current 
>> users, please check it out and continue to report any problem. We want to 
>> make sure it is backward compatible as promised.
>>
>> Massimo
>>
>>

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

2017-07-21 Thread tim . nyborg
Creating a SQLFORM.factory() from multiple tables, or a combination of 
tables and fields, now breaks, because the underlying logic assumes the 
tables are fields:

form = SQLFORM.factory(idb.catering, idb.catering_diet)

File "/home/www-data/internal-apps/gluon/sqlhtml.py", line 1922, in factory
return SQLFORM(DAL(None).define_table(table_name, *[field.clone() for field 
in fields]),
AttributeError: 'Table' object has no attribute 'clone'


On Wednesday, 19 July 2017 13:25:52 UTC+1, Massimo Di Pierro wrote:
>
> web2py 2.15.2 is OUT is includes a few major bug fixes to version 2.15.1. 
> Thanks Leonel for the quick fixes.
> There a few other outstanding problems and they will be resolved in the 
> next week.
>
> For new users 2.15.2 is still better than previous versions. For current 
> users, please check it out and continue to report any problem. We want to 
> make sure it is backward compatible as promised.
>
> Massimo
>
>

-- 
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: Advice needed on complex SQL operation

2017-06-29 Thread tim . nyborg
Below is something similar I've been playing with.  The interface is utter 
garbage, but it shows the general idea.  A form that allows you to select 
fields and aggregation per field:
Manage a list of queries fields, adding in the field or its .sum() or 
.count() method as necessary.  Where you're not using an aggregate, append 
the field to the groupby list.

def test():
table = idb.student

options = []
for field in table.fields:
options.append(Field(field, 'boolean'))
options.append(Field('%s_group' % field, 'string', 
requires=IS_EMPTY_OR(IS_IN_SET(['group', 'count', 'sum']


form = SQLFORM.factory(
*options,
keepvalues=True
)

if form.process().accepted:
fields = []
groupby = []
for field in form.vars:
if '_group' not in field and form.vars[field]:
if form.vars['%s_group' % field] == 'sum':
fields.append(table[field].sum())
if form.vars['%s_group' % field] == 'count':
fields.append(table[field].count())
if form.vars['%s_group' % field] == 'group':
fields.append(table[field])
groupby.append(table[field])

results = idb().select(*fields, groupby=groupby, limitby=(0, 10))

return dict(form=form, results=results)


-- 
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: New site on web2py

2017-06-16 Thread tim . nyborg
Very impressive.  Especially impressed by the 'Save for later' process, 
which I bet I'll end up copying.

On Wednesday, 14 June 2017 14:36:18 UTC+1, Ian Ryder wrote:
>
> Hi all, not sure if it's OK to do this - slap me down if not!
>
> We're just about to launch a new tool / site based on web2py - 
> https://www.wherecani.live
>
> Any feedback appreciated and if it's useful to anyone looking to live in 
> different parts of the world, great stuff.
>
> Thanks Massimo et al for the great framework :)
>
> Cheers
> Ian
>

-- 
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: web2py 2.15.1

2017-06-06 Thread tim . nyborg
Re #3: I highly recommend swapping in Eonasdan's bootstrap-datetimepicker: 
https://github.com/Eonasdan/bootstrap-datetimepicker

I just altered my web2py_ajax.html to swap dependencies and initialize 
datepickers:

# response.files.insert(1,'/inc/css/calendar.css')
# response.files.insert(2,'/inc/js/web2py/calendar.js')

# Replacing web2py calendar with bootstrap datetimepicker
response.files.insert(1, 
"/inc/js/eonasdan-bootstrap-datetimepicker/build/css/bootstrap-datetimepicker.min.css")
response.files.insert(2, "/inc/js/moment/moment.js")
response.files.insert(3, 
"/inc/js/eonasdan-bootstrap-datetimepicker/build/js/bootstrap-datetimepicker.min.js")


// Initialize bootstrap datetimepicker
$(function (){
$('.date').datetimepicker({
format: '-MM-DD',
keyBinds: null, // Stop keypresses from navigating the widget, 
allowing users to edit date/times normally
}); 
$('.datetime').datetimepicker({
format: '-MM-DD HH:mm',
useCurrent: 'day',  // This pulls out the current day, without 
the current time (00:00 default)
keyBinds: null, // Stop keypresses from navigating the widget, 
allowing users to edit date/times normally
});
});

Enter code here...





On Monday, 5 June 2017 09:39:11 UTC+1, Karoly Kantor wrote:
>
> Dear Massimo,
>
> I saw your question in the developers group where I cannot post, therefore 
> i do it here.
>
> I am currently aware of the following issues to be fixed:
>
> 1. Google 2nd generation SQL is definitely a problem. Please note I made a 
> temporary hack to fix it, described here: 
> https://groups.google.com/forum/?fromgroups=#!topic/web2py/vs39zZpaH7g
>
> 2. We have a long overdue issue with the password reset emails not sending 
> on GAE. I am using a temporary dirty workaround that sends a plain text new 
> password, search for the issue about "lazyT object being passed to GAE".
>
> 3. I am having trouble making the date picker work nicely across all 
> browsers, especially where there is a native solution. Microsoft Edge is 
> the worst case. In general, would be good to have a nicer date picker
>
> 4. General comment: We have "batteries included", however, some of those 
> batteries now have newer versions than included, e.g. bootstrap
>
>
>
>
>

-- 
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: Strange behaviour of SQL query on accented characters

2017-05-30 Thread tim . nyborg
Looks like the issue is: str(query)
The query is a unicode object by default, and á can't be converted to a 
string, since it's outside the ascii character set.

Try this instead:
print u"DEBUG: query = " + query



On Tuesday, 30 May 2017 11:07:30 UTC+1, Karoly Kantor wrote:
>
> Please help:
>
> I have this:
>
> print "DEBUG: query = " + str(query)
> result = mydb(query).select(*column_names)
> print db._lastsql
>
> This will print this into the log:
>
> DEBUG: query = record.application = 3) AND (record.entity = 24)) AND 
> (record.is_deleted = 'F')) AND ((record.is_deleted = 'F') AND 
> (record.string_1 = 'Puskás Ferenc')))
>
> Please observe the accented 'a' character: "á". Also, mydb equals to db in 
> this case. 
>
> This will raise this error (from the GAE logs):
>
> print db._lastsql File 
> "/base/data/home/runtimes/python27_experiment/python27_lib/versions/1/google/appengine/runtime/request_environment.py",
>  
> line 92, in write self._request.errors.write(data) File 
> "/base/data/home/runtimes/python27_experiment/python27_lib/versions/1/google/appengine/api/logservice/logservice.py",
>  
> line 286, in write for line in cStringIO.StringIO(lines): 
> UnicodeEncodeError: 'ascii' codec can't encode character u'\xe1' in 
> position 212: ordinal not in range(128)
>
> However:
>
> 1. If I comment out the print db._lastsql part, my app suddenly works as 
> expected,
>
> 2. Except, querying on "Puskas Ferenc" and "Puskás Ferenc" both retrieves 
> the same item from the table (which has an "á").
>
> Maybe, can someone give me a hint on what's going on here?
>
> My server connection collation is set to utf8mb4_unicode_ci and the table 
> collation to utf8_general_ci (this was all default in Google Cloud SQL, I 
> have not changed them)
>
> 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: Codec MS-SQL, unicode Latin1 UTF8

2017-05-25 Thread tim . nyborg
I use this same stack, and ran into encoding issues when updating the 
database, because of FreeTDS v.91.

But upgrading to FreeTDS v1.00.40 fixed all unicode issues:
https://github.com/mkleehammer/pyodbc/issues/244

Connect with mssql4n, TDS_Version 7.1+, no need to set db_codec

On Friday, 19 May 2017 02:07:27 UTC+1, Jose wrote:
>
> Hi J-Michel Angers
>
> Given:
> pydal <-> pyodbc  <-> UnixODBC  <-> FreeTDS  <-> MSSQL
>
> In freetds.conf I have:
>
> client charset = UTF-8
>
> and in pydal I use mssql2 adapter, db_codec is not necessary
>
> Jose
>

-- 
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 formstyle for auth

2016-10-31 Thread tim . nyborg
You'll also want to set auth.settings.formstyle

I've built a form style, placed it in a model (style.py), and then set 
response.formstyle and auth.settings.formstyle

On Tuesday, 25 October 2016 15:52:12 UTC+1, Marko Seppälä wrote:
>
> Hi,
>
> I'm trying to set custom form styles for auth, like register or login 
> form. I would like to set completely new formstyle function for that, so 
> that it's easy to use over and over again just setting formstyle = 
> my_formstyle in appconfig.ini.
>
> How I could do that? I can use formstyle_bootstrap3_inline_factory 
> from sqlhtml.py as a starting point for my own function. But where should I 
> put that function? And how to tell web2py where to look for that function? 
> Obviously I don't want to touch original source code.
>
> 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: How to code efficiently for multiple database engines with Exceptions

2016-09-13 Thread tim . nyborg
It may be a bad move, but I defined IntegrityError in a model, so it can be 
nice and terse everywhere else:
IntegrityError = idb._adapter.driver.IntegrityError

Where I have two different databases, I just added it to the database 
objects:
db.IntegrityError = db._adapter.driver.IntegrityError
idb.IntegrityError = idb._adapter.driver.IntegrityError

Allows for nice readable except statements


On Wednesday, 7 September 2016 20:47:48 UTC+1, Anthony wrote:
>
> According to the Python DB API specification, there should be a common 
> set of exceptions , 
> and they should be exposed as attributes on the connection object 
> . Therefore, 
> you should be able to do something like:
>
> try:
> db.mytable.insert(**fields)
> except (db._adapter.driver.IntegrityError, db._adapter.driver.
> OperationalError) as e:
> pass
>
> The above should catch the IntegrityError and OperationalError of any DB 
> API compliant driver.
>
> Also, when making inserts or updates, if you don't care about the specific 
> exception but just want to catch any database errors, the DAL API includes 
> the following:
>
> db.mytable._on_insert_error = my_insert_error_handler
> db.mytable._on_update_error = my_update_error_handler
>
>
> Anthony
>
> On Wednesday, September 7, 2016 at 1:14:54 PM UTC-4, Joe Barnhart wrote:
>>
>> So my website runs under PostgresSQL today but will likely be switched to 
>> MySql at some point in the future.  My problem isn't with the DAL -- it 
>> performs fine for what it does, insulating me very well from the nuances of 
>> the SQL syntax for each engine.
>>
>> No, my problem comes from Exceptions.  Each database engine defines its 
>> own Exceptions within its driver.  Even different drivers for the same 
>> database engine (psycopg2 vs pg8000) come with different Exception trees. 
>>  If I want to be able to handle database exceptions (and who doesn't?) how 
>> do I load and use the RIGHT set of Exceptions for each driver?
>>
>> When using the pg8000 driver for example, the Exceptions raised are all 
>> of the form:  "gluon.contrib.pg8000.ProgrammingError" or some such.  Errors 
>> from psycopg2 and the mysql drivers are similarly formed.  I can't even use 
>> this in a try-except block unless I first import gluon.contrib.pg8000.  The 
>> same is true for exceptions from all other database engines.
>>
>> Should we "alias" these database errors into a consistent tree inside 
>> web2py?  If we created a database exception tree inside web2py, and then 
>> added to the database driver module a section that raised the corresponding 
>> web2py Exception whenever a database exception was triggered, then we could 
>> just catch ProgrammingError (from web2py) instead of 
>> gluon.contrib.pg8000.ProgrammingError.
>>
>> Or, should I just put somewhere in the db definition of the models a line 
>> like "import gluon.contrib.pg8000 as mydb" and then use 
>> "mydb.ProgrammingError" throughout my code?  I suppose I'd need to repeat 
>> this in every module I create, and I create a LOT of modules
>>
>> Anyway, is this a real problem or am I missing something obvious??
>>
>> -- Joe
>>
>>

-- 
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: SELECT without duplicates for a specific field

2016-06-09 Thread tim . nyborg
Looks like you want a subquery.  You'll need to decide which of the items 
to choose when you have a given category_code.
Say you want the first item with a given category code:

sub_query = db()._select(db.products.id.min(), 
groupby=db.products.category_code)
results = db(db.products.id.belongs(sub_query).select()

On Wednesday, 8 June 2016 15:10:33 UTC+1, Gael Princivalle wrote:

> Hello.
>
> Is there a way to select some rows without duplicates for a specific field 
> ?
>
> MODEL:
> db.define_table('products'):
> Field('code', type='string'),
> Field('category_code', type='integer'))
>
> ROWS:
> code / category_code
> A1125 / 3
> C2214 / 2
> D235 / 3
> Z886 / 1
>
> I would like to make a select that give this result:
> code / category_code
> A1125 / 3
> C2214 / 2
> Z886 / 1
>
> Someone have an idea ?
>
> 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: alternative autocomplete widget

2016-02-12 Thread tim . nyborg
I've been thinking about doing this exact thing for a while, so I'll be 
eagerly watching your plugin

On Thursday, 11 February 2016 16:18:28 UTC, Carlos Cesar Caballero wrote:
>
> Hi, right now I am working in a plugin with an autocomplete widget using 
> typeahead.js: 
>
> https://github.com/daxslab/web2py-typeahead 
>
> Any clues, suggestions, recomendations etc... will be very welcomed. 
>
> Greetings. 
>
> -- 
> Este mensaje le ha llegado mediante el servicio de correo electronico que 
> ofrece Infomed para respaldar el cumplimiento de las misiones del Sistema 
> Nacional de Salud. La persona que envia este correo asume el compromiso de 
> usar el servicio a tales fines y cumplir con las regulaciones establecidas 
>
> Infomed: http://www.sld.cu/ 
>
>

-- 
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: Virtual fields disapeared from select() results (v2.11.2)

2015-06-09 Thread tim . nyborg
Lovely!  I was just about to post this problem.

On Tuesday, 9 June 2015 07:56:35 UTC+1, Paolo Valleri wrote:

 I see the problem now, thanks for pointing it out.
 I'll post a fix later today.

  Paolo

 2015-06-08 22:11 GMT+02:00 Donatas Burba d.b...@gmail.com javascript::

 This is failing example:

 db=DAL('sqlite:memory')

 db.define_table('tt', 
 Field('vv', 'integer'), 
 Field.Virtual('x', lambda row: row.tt.vv * 10))
 
 db.define_table('tt2', 
 Field('ttref', 'reference tt'),
 Field('vv2', 'integer'))

 tt1 = db.tt.insert(vv='1')
 tt2 = db.tt.insert(vv='3')
 db.tt2.insert(ttref=tt1, vv2='3')
 db.tt2.insert(ttref=tt2, vv2='4')
 
 records = db(db.tt).select(
 db.tt.ALL, db.tt2.ALL,
 join=[db.tt2.on(db.tt2.ttref == db.tt.id)]
 )
 for r in records:
 print r

 Result:

 Row {'tt2': {'ttref': 1L, 'id': 1L, 'vv2': 3L}, 'tt': {'id': 1L, 'vv': 
 1L}}
 Row {'tt2': {'ttref': 2L, 'id': 2L, 'vv2': 4L}, 'tt': {'id': 2L, 'vv': 
 3L}}

 As you can see virtual field 'x' (in table 'tt') is missing. As I 
 understand this occurs when selecting records from more than one table. In 
 my case (with PostgreSQL) every time I use db(...).select(db.table.ALL, 
 TOTAL_ROWS, ...) where TOTAL_ROWS = 'COUNT(*) OVER()'.

 -- 
 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 a topic in the 
 Google Groups web2py-users group.
 To unsubscribe from this topic, visit 
 https://groups.google.com/d/topic/web2py/l8V3nAzE4Hs/unsubscribe.
 To unsubscribe from this group and all its topics, send an email to 
 web2py+un...@googlegroups.com javascript:.
 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] MSSQL and Unicode problems

2015-04-07 Thread tim . nyborg
Here's a question for those of you experienced integrating MSSQL and web2py.

My web2py apps connect to a legacy SQL Server 2005 database, but I'm 
running into a problem where any attempts to *insert *unicode data into my 
nvarchar fields breaks the encoding (Renée - Renée)
It seems the Unicode query strings get to SQL Server, but are then assumed 
to be ASCII (there's no leading N before the string literals), and get 
encoded.

Switching the DAL to use MSSQL2 fixes the problem, as it converts *all* queries 
to ASCII:
def execute(self,a):
return self.log_execute(a.decode('utf8'))

But I understand MSSQL2 is experimental, possibly deprecated, and many of 
you must be managing to work with Unicode data just fine using the 
MSSQL/3/4 adapters.  
This issue occurs in both a linux stack (Web2py  pypyodbc  freetds 8.0  
MSSQL2005) and web2py running on a local windows machine (web2py  pyodbc  
Windows ODBC?  MSSQL2005)

Any thoughts?  Has anyone else run into this?

-- 
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] Bug: SQLFORM.accepts() breaks formstyle when widgets are defined

2015-02-19 Thread tim . nyborg
I'm using a custom formstyle to apply bootstrap3 to my forms (a modified 
copy of the built-in bootstrap3_inline).  Importantly, it adds the 
form-control class to each input.

This works fine, until you define a widget for a field, and have it fail 
validation.

db.define_table('test',
Field('one', 'string', requires=IS_MATCH('STUFF')),
Field('two', 'string', requires=IS_MATCH('STUFF'), 
widget=SQLFORM.widgets.string.widget),
)

def index():
# Set variables for the default view

form = SQLFORM(db.test, formstyle='bootstrap3_inline')  
form.process()

return dict(form=form)

Despite being identical fields, with identical widgets, field two loses its 
formatting.  Why?  Because of the following code at the bottom of 
SQLFORM.accepts()

elif (not ret) and (not auch):
# auch is true when user tries to delete a record
# that does not pass validation, yet it should be deleted
for fieldname in self.fields:

field = (self.table[fieldname]
 if fieldname in self.table.fields
 else self.extra_fields[fieldname])
### this is a workaround! widgets should always have default not 
None!
if not field.widget and field.type.startswith('list:') and \
not OptionsWidget.has_options(field):
field.widget = self.widgets.list.widget
if field.widget and fieldname in request_vars:
if fieldname in self.request_vars:
value = self.request_vars[fieldname]
elif self.record:
value = self.record[fieldname]
else:
value = field.default
row_id = '%s_%s%s' % (
self.table, fieldname, SQLFORM.ID_ROW_SUFFIX)
widget = field.widget(field, value)
parent = self.field_parent[row_id]
if parent:
parent.components = [widget]
if self.errors.get(fieldname):
parent._traverse(False, hideerror)
self.custom.widget[fieldname] = widget


If a field's widget is defined, it overwrites it, for reasons mysterious to 
me.  This occurs *after* the formstyle is applied.

If I remove that source code, or remove the widget between form setup and 
validation:


def index():
# Set variables for the default view

form = SQLFORM(db.test, formstyle='bootstrap3_inline')  
db.test.two.widget=None  
form.process()

return dict(form=form)


Then everything works fine.  

What is the point of that code at the end of accepts(), and is this working 
as designed?

-- 
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: ckeditor : how to make read only, how to remove the toolbar in a dynamic way

2015-02-02 Thread Tim Nyborg
Depends on how you're implementing the widget.

I've got a CKEditor widget as follows (pretty much a glorified copy of 
text.widget with the ckeditor class):

class CKEditor(FormWidget):
_class = 'ckeditor' 
   
@classmethod
def widget(cls, field, value, **attributes):
 
generates a TEXTAREA tag. 

see also: :meth:`FormWidget.widget`
 
default = dict(value=value) 
attr = cls._attributes(field, default, **attributes) 
return TEXTAREA(**attr) 

Used in the model, it's:

idb.define_table(
'module',
Field('id', 'id', readable=False),
...
Field('description', 'text', widget=CKEditor.widget)
)  

So to do what you're suggesting, I change it to:

def hideable_ckeditor_widget():
return SQLFORM.widgets.text.widget if 'new' in request.args or 'edit' 
in request.args else CKEditor.widget

idb.define_table(
'module',
Field('id', 'id', readable=False),
...
Field('description', 'text', widget=hideable_ckeditor_widget())
)  



On Sunday, February 1, 2015 at 9:25:35 AM UTC, Serge Bourgeois wrote:

 I just implemented the ckeditor plugin. It looks great, but I need help 
 (example if possible) showing how to hide the ckeditor toolbar for some 
 text fields, for instance in a controller with a smartgrid, where 
 request.args does not contain 'now' nor 'edit'.
 Thanks in advance !
 Serge


-- 
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: Override update defaults?

2015-01-28 Thread tim . nyborg
Your first suggestion's clever, and not too hard to extend.  Have a list of 
admin functions, check if request.function is in it.

At the moment, I've got a disabling routine, and pass all the table names:
def suppress_timestamp(*tables):
#Stop updating of modified_on and _by, given a list of tables 
(strings)
for table in tables:
try:
idb[table_name].modified_on.update = None
idb[table_name].modified_by.update = None
except:
pass



On Tuesday, 27 January 2015 19:31:00 UTC, Anthony wrote:

 I think you can take two approaches. One option would be to conditionally 
 set the update attribute depending on the request:

 Field('modified_on', 'datetime',
   update=request.now if request.function != 'admin_routine' else 
 None, ...)

 The other approach is to pass in the current value when doing the update 
 in the admin routine:

 def admin_routine:
 ...
 idb.student(source.id).address.update(student=target.id, 
 modified_on=idb.student.address)

 Anthony

 On Tuesday, January 27, 2015 at 9:48:54 AM UTC-5, tim.n...@conted.ox.ac.uk 
 wrote:

 I'm really liking the ability to automatically timestamp when records are 
 updated, but I'm wondering if there's a simple way of suppressing this 
 behaviour when needed:

 I have these signature fields appended to a number of tables, 
 automatically recording when users update records:
 signature_fields = idb.Table(
 idb, 'signature_fields', #Dummy table, not actually in the db
 Field('created_on', 'datetime',
   default=request.now,
   writable=False, readable=False,
   label='Created on'),
 Field('created_by', 'string',
   default=auth.user.username
   writable=False, readable=False,
   label='Created by'),
 Field('modified_on', 'datetime',
   update=request.now, default=request.now,
   writable=False, readable=False,
   label='Modified on'),
 Field('modified_by', 'string',
   default=auth.user.username, update=signature_username,
   writable=False, readable=False,
   label='Modified by'),
 )

 For example:

 idb.define_table(
 'address',
 Field('id', 'id', readable=False),
 Field('student', idb.student, readable=False, writable=False),
 Field('line1', 'string'),
 Field('line2', 'string'),
 Field('line3', 'string'),
 Field('town', 'string'),
 Field('countystate', 'string'),
 Field('country', 'string'),
 Field('postcode', 'string'),
 signature_fields
 )   

 But I have an admin routine that allows me to move addreses to another 
 student, and I don't want the timestamping to occur when I run:
 idb.student(source.id).address.update(student=target.id)

 Is there a simple way to suppress automatic update values? e.g.:
 idb.student(source.id).address.update(student=target.id, 
 _defaults=False)

 I know I can disable them one by one before running the queries, but 
 it'll add lots of boilerplate a la:
 idb.address.modified_on.update = idb.address.modified_by.update = None





-- 
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] Override update defaults?

2015-01-27 Thread tim . nyborg
I'm really liking the ability to automatically timestamp when records are 
updated, but I'm wondering if there's a simple way of suppressing this 
behaviour when needed:

I have these signature fields appended to a number of tables, automatically 
recording when users update records:
signature_fields = idb.Table(
idb, 'signature_fields', #Dummy table, not actually in the db
Field('created_on', 'datetime',
  default=request.now,
  writable=False, readable=False,
  label='Created on'),
Field('created_by', 'string',
  default=auth.user.username
  writable=False, readable=False,
  label='Created by'),
Field('modified_on', 'datetime',
  update=request.now, default=request.now,
  writable=False, readable=False,
  label='Modified on'),
Field('modified_by', 'string',
  default=auth.user.username, update=signature_username,
  writable=False, readable=False,
  label='Modified by'),
)

For example:

idb.define_table(
'address',
Field('id', 'id', readable=False),
Field('student', idb.student, readable=False, writable=False),
Field('line1', 'string'),
Field('line2', 'string'),
Field('line3', 'string'),
Field('town', 'string'),
Field('countystate', 'string'),
Field('country', 'string'),
Field('postcode', 'string'),
signature_fields
)   

But I have an admin routine that allows me to move addreses to another 
student, and I don't want the timestamping to occur when I run:
idb.student(source.id).address.update(student=target.id)

Is there a simple way to suppress automatic update values? e.g.:
idb.student(source.id).address.update(student=target.id, _update=False) 
   

I know I can disable them one by one before running the queries, but it'll 
add lots of boilerplate a la:
idb.address.modified_on.update = idb.address.modified_by.update = None



-- 
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: About validators

2015-01-27 Thread tim . nyborg
'but I get abcDEF'

How did you get that?

form=FORM(INPUT(_type=text, _name=n, requires=IS_LOWER()))

if form.process().accepted:
response.flash = form.vars.n

The above spits out 'uppercase' when I entered 'UPPERCASE'



On Tuesday, 27 January 2015 15:15:34 UTC, mweissen wrote:

 In the book I find:IS_LOWER

 This validator never returns an error. It just converts the value to lower 
 case.

 requires = IS_LOWER()

 Now I try a piece of code:

 form=FORM(INPUT(_type=text, _name=n, requires=IS_LOWER()))

 On input abcDEF I expected n==abcdef, but I get abcDEF (not 
 converted to lower characters). 

 ​What is wrong?
 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.


[web2py] Re: Record format and SQLFORM.factory

2015-01-27 Thread tim . nyborg
form = SQLFORM.factory(
Field('Presupuesto', requires=IS_IN_DB(db, db.presupuesto, 
*db.presupuesto._format*)),
submit_button='Continuar',
table_name='presupuesto',
)

On Monday, 26 January 2015 16:09:31 UTC, César Bustíos Benites wrote:

 Hello! I have a table called *presupuesto *with a custom *format*:

 db.define_table('presupuesto',
 Field('jar', db.jar, label='JAR'),
 Field('monto', 'decimal(11, 2)', label='Presupuesto inicial', requires
 =IS_NOT_EMPTY(error_message='Ingrese un monto para el presupuesto')),
 Field('monto_mensual', 'decimal(11, 2)', label='Presupuesto mensual', 
 compute=lambda r: Decimal(r.monto)/Decimal('12')),
 Field('ano', 'integer', label='Año', requires=[IS_NOT_EMPTY(
 error_message='Ingrese el año'), IS_INT_IN_RANGE(1980, 2100, error_message
 ='Año inválido')]),
 format=lambda record: '%s %s' % (record.jar.nombre, record.ano)
 )


 I'm using the following SQLFORM.factory in a view:

 @auth.requires_login()
 def control_gastos():
 form = SQLFORM.factory(
 Field('Presupuesto', requires=IS_IN_DB(db, db.presupuesto)),
 submit_button='Continuar',
 table_name='presupuesto',
 )
 form.element(_type='submit')['_class'] = 'btn btn-success'
 form.element('#presupuesto_Presupuesto')['_class'] = 'form-control'
 form.element('#presupuesto_Presupuesto')['_style'] = 'width: 100%'
 return dict(form=form)


 Somehow, I was expecting that the records shown in the form were formatted 
 as define in the table but that's not happening. It's only showing IDs:


 https://lh6.googleusercontent.com/-HVtGNOVneTI/VMZm_thtOTI/YFs/YrDCU2mdVLI/s1600/Screenshot%2Bfrom%2B2015-01-26%2B11%3A09%3A18.png

 What am I missing?


 Thanks,
 César


-- 
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: One AutoComplete overrides another

2014-12-22 Thread tim . nyborg
Found my mistake; hopefully it will save someone time in the future.

Multiple autocompletes referring to the same field need keyword arguments, 
otherwise they all end up as the 
default '_autocomplete_%(tablename)s_%(fieldname)s' 
(_autocomplete_module_code in my case).  Once I gave them distinct names, 
everything worked.

-- 
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: One AutoComplete overrides another

2014-12-22 Thread Tim Nyborg
I haven't found a solution to this, but have found more detail about the 
problem:

The first defined autocomplete widget on a particular field overrides ALL 
others defined after.

idb.define_table(
'fee',
   ...
Field('module_code', 'string', writable=False, label='Module code', 
  requires=IS_IN_DB(idb, idb.module.code, 
error_message='Required'), 
  widget=SQLFORM.widgets.autocomplete(request, idb.module.code, 
min_length=1),
  )
)

idb.define_table(
'tutor_module',
...
Field('module_code', 'string', writable=False, label='Module code', 
  requires=IS_IN_DB(idb, idb.module.code, 
error_message='Required'), 
  widget=SQLFORM.widgets.autocomplete(request, idb.module.code, 
id_field=idb.module.id,
  orderby=idb.module.code, 
min_length=2, 
  help_fields=[idb.module.code, 
idb.module.title],
  help_string='%(code)s - 
%(title)s'),   
  )
)



In this case, the second table's autocomplete widget always renders the way 
the first should (including the missing id_field).

-- 
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: Hyphen in application name

2014-12-16 Thread tim . nyborg
I've put Routes.py in the root web2py directory.  You may be right about a 
bug, though.  I've loaded up a fresh local copy of web2py, created an app 
called a_b, and set up the routing:

routers = dict(

# base router
BASE=dict(
default_application='welcome',
map_hyphen=True,
),
)

All the static files fail, and http://127.0.0.1:8000/a-b returns invalid 
function (default/a_b)



On Tuesday, 16 December 2014 00:27:03 UTC, Derek wrote:

 well, according to the documentation it should work, so perhaps you 
 encountered a bug. 

 Just a question, where did you put your routes.py? if in the application, 
 then you can only route controllers and functions.

 On Monday, December 15, 2014 3:42:53 AM UTC-7, tim.n...@conted.ox.ac.uk 
 wrote:

 Does anyone know how to get map_hyphen to work with an application name?

 I have a routes.py setup as follows:

 routers = dict(
BASE  = dict(
default_application = home,
default_controller = default,
default_function = index,
map_hyphen=True, 
 ),
 )

 In my application (tutor_events), controller and function hyphen mapping 
 work fine, so the following paths work:
 /tutor_events/default/edit-details/424
 /tutor_events/tutor-fee/add

 And all URLs are being generated with hyphens

 But if I try to go to /tutor-events/..., I get an error: invalid function 
 (default/tutor_events)
 So web2py is trying to send me on to /home/default/tutor_events



-- 
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: Hyphen in application name

2014-12-16 Thread tim . nyborg
After some further digging, I'm not sure map_hyphens can possibly work on 
application names as things sit.

In map_app() in rewrite.py, the incoming app name is never translated.  I 
added the following code near the top of the function, and everything 
started to work.

if routers.BASE.map_hyphen:
arg0 = self.harg0.replace('-', '_')
else:
arg0 = self.harg0


-- 
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] Hyphen in application name

2014-12-15 Thread tim . nyborg
Does anyone know how to get map_hyphen to work with an application name?

I have a routes.py setup as follows:

routers = dict(
   BASE  = dict(
   default_application = home,
   default_controller = default,
   default_function = index,
   map_hyphen=True, 
),
)

In my application (tutor_events), controller and function hyphen mapping 
work fine, so the following paths work:
/tutor_events/default/edit-details/424
/tutor_events/tutor-fee/add

And all URLs are being generated with hyphens

But if I try to go to /tutor-events/..., I get an error: invalid function 
(default/tutor_events)
So web2py is trying to send me on to /home/default/tutor_events

-- 
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 - best method for hide fields and set default values

2014-12-10 Thread tim . nyborg
That's the method I use, more or less, as it seems the simplest and most 
reliable to set defaults.

Would it be easier if those fields were writable = False and readable = 
False in the model, and the other form used ignore_rw=True?

You might also put
db.registrations.registered_user.default = auth.user.id
in the model, since the other form could easily type over the default.

-- 
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: Allow form re-submission / suppress disableElement?

2014-11-07 Thread tim . nyborg
Clever.

I took the route of replacing the Button with an anchor that submits the 
form via javascript:

export_form = FORM(LABEL('Export batch #'),
   DIV(
   INPUT(_type='text', _name='number', _class=span2, 
_id=appendedInputButton),
   A(icon_text('Export', 'print'), _type='submit', 
_class='btn', _onclick=$('#export').submit();),
   _class='input-append',
),
_action=URL(export, extension='csv'),  
  
_id='export'
)

But I'm switching to your neater solution.

-- 
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.grid want no initial values

2014-11-07 Thread tim . nyborg
It's easy enough if you have a separate search-form:

searchform = SQLFORM.factory(...)
form = None
if searchform.process().accepted:
form = SQLFORM.grid(...)

If you're wanting to use the built-in grid search tool, you could set the 
query to return 0 results unless keywords is in get_vars:

def search_person():
   db.person.id.readable = False
   query = (db.tenant) if request.get_vars.keywords else (db.tenant.id==0)
   ...
   form = SQLFORM.grid(query = query, headers = headers, create=False, 
deletable=False, editable=False, maxtextlength=64, paginate=4)
 
   return dict(form=form)



On Sunday, 2 November 2014 19:08:26 UTC, Wayne Tooley wrote:

 Hi Everyone;
 I'm new to web2py and love it. I have a simple question that I can't seem 
 to find a simple answer to. 
 I want to use SQLFORM.gid but not to load any values unless searched for. 
 Maybe I'm using the wrong thing but is there a simple way to do this?

 my code is this:

 def search_person():
 db.person.id.readable = False
 query = (db.tenant)
 fields = (db.person.name)
 headers = {'db.person.name': 'Name'}
 grid =False #does not work
 form = SQLFORM.grid(query = query, headers = headers, create=False, 
 deletable=False, editable=False, maxtextlength=64, paginate=4)
  return dict(form=form)

 any help or examples would be appreciated.

 Regards,

 Wayne


-- 
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: Customizing generated columns from SQLFROM.grid

2014-11-07 Thread tim . nyborg
Or, on the slightly simpler side:

before you call SQLFORM.grid():

from gluon import TAG
db.house.location_type.represent = lambda value, row: TAG.abbr(value, 
_title=row.location_type_msg)
db.house.capacity.represent = lambda value, row: TAG.abbr(value, 
_title=row.capacity_msg)


-- 
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] Allow form re-submission / suppress disableElement?

2014-11-03 Thread tim . nyborg
I have a form which allows a user to download a CSV, given a batch number, 
without having to leave the page.  However, I'd like to allow form 
re-submission, since the user might want to run the CSV export several 
times.  Web2py.js disables buttons on form submission, but is there a 
simple way to suppress this behaviour for a single form?  (I've found I can 
replace the form's .submit() in Javascript, but that seems like 
overengineering, and I'd end up putting boilerplate in any number of views)

def search():
 export_form = FORM(LABEL('Export batch #'),
DIV(
INPUT(_type='text', _name='number', _class=span2, 
_id=appendedInputButton),
BUTTON(icon_text('Export', 'print'), 
_type='submit', _class='btn'), _class='input-append',   
 
),
_action=URL(export, extension='csv')
)

return dict(export_form=export_form)

def export():
query = idb.tutor_fee.batch == request.vars.number
tutors = idb(query).select(idb.tutor_fee.ALL)
return dict(tutors=tutors)

search.html
{{extend 'layout.html'}}
...
{{=export_form}}

export.csv:
{{
import cStringIO
stream = cStringIO.StringIO()

tutors.export_to_csv_file(stream)

response.headers['Content-Type']='text/csv'
response.write(stream.getvalue(), escape=False)
}}


-- 
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] One AutoComplete overrides another

2014-10-16 Thread Tim Nyborg
I've run into an odd problem with autocomplete:

I have a factory form doing an autocomplete lookup on the field 
idb.module.code, with custom help_fields, etc., and it works well:

browseform = SQLFORM.factory(Field('code', widget=SQLFORM.widgets.
autocomplete(request, idb.module.code, id_field=idb.module.id,
  orderby=
idb.module.code, min_length=2, 
  
help_fields=[idb.module.code, idb.module.title],
  
help_string='%(code)s - %(title)s')),
...
)

Until, that is, I define an autocomplete in my model for another field, 
which does lookup on the same field:
idb.define_table(
'module',
Field('id', 'id', readable=False),
Field('code', 'string'),
Field('sourcemodulecode')
...
)

idb.module.sourcemodulecode.widget = SQLFORM.widgets.autocomplete(request, 
idb.module.code, min_length=3, 
  id_field=
idb.module.code, help_fields=[idb.module.title], 
  
help_string='This should not show up in the factory form, but does.')

Now the output of the factory form's field becomes 'This should not show up 
in the factory form, but does.'

Am I messing something up in my implementation?

An aside: is there solid documentation of help_fields and help_string 
anywhere?  They do exactly what I want, but I only stumbled upon them while 
looking through the source code.

-- 
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] Maxlength for string and text inputs in SQLFORM

2014-08-08 Thread tim . nyborg
Is it possible to have a string or text field's length parameter 
automatically populate the SQLFORM-generated input's maxlength?

Such that:
Field('personname', 'string', length=32, label='First name', 
requires=[IS_LENGTH(32), IS_NOT_EMPTY()]),

Will produce:
input class=string id=table_personname name=personname value= 
maxlength=32 type=text/input

I know I can add the parameter to the form in the controller, but this 
makes maintenance tougher if the field is used all over the place.

Many thanks,
Tim


-- 
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: Treat Datetime field as Date?

2014-02-19 Thread Tim Nyborg
Really, the overcomplication is just for aesthetics, to avoid displaying 
00:00:00 on forms and in the widget.  The field settings I have seem to 
work well, so I'll just splat them into all necessary fields.

On Saturday, February 15, 2014 1:27:30 PM UTC, Niphlod wrote:

 why the overcomplication ? as other backends that don't support date every 
 date field in DAL gets turned to a datetime (with 0 hours, minutes and 
 seconds) and it's automatically handled.

 On Wednesday, February 12, 2014 6:31:06 PM UTC+1, Tim Nyborg wrote:

 I'm connecting to an MSSQL 2005 db, which only has the Datetime format 
 (Date was added in 2008).
 Is there a standard way to treat a Datetime as a Date in web2py for forms 
 and formatting?

 I've done the following, and it works thus far, but it seems a bit 
 hackish.
 Field('BirthDte', 'datetime',
 widget=SQLFORM.widgets.date.widget,
 requires=IS_DATE(),
 represent = lambda value, row: value.strftime(%#d %b %Y))



-- 
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/groups/opt_out.


[web2py] String-keyed tables, SQLFORM, and query shortcuts?

2014-02-19 Thread Tim Nyborg


I'm connecting to a legacy MSSQL database, and have an important table which 
has an alphanumeric primary key:

db.define_table('module',
Field('modid', 'string'),
...
primarykey=['modid'])


When I generate an update SQLFORM (form = SQLFORM(db.module, index)), it 
generates an Object Not Found error unless the key happens to be an integer.
Likewise, I can't do shortcut lookups a la db.module(index), but must use 
db(db.module.modid==index).select().first()

Am I missing the correct method of using a string primary key, or is it always 
a problem in web2py?
Adding a new autoincrement key to the module solves these, but there enough 
tables and legacy processes relying on the existing key that I can't possibly 
make a full switch.

-- 
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/groups/opt_out.


[web2py] Treat Datetime field as Date?

2014-02-14 Thread Tim Nyborg
I'm connecting to an MSSQL 2005 db, which only has the Datetime format 
(Date was added in 2008).
Is there a standard way to treat a Datetime as a Date in web2py for forms 
and formatting?

I've done the following, and it works thus far, but it seems a bit hackish.
Field('BirthDte', 'datetime',
widget=SQLFORM.widgets.date.widget,
requires=IS_DATE(),
represent = lambda value, row: value.strftime(%#d %b %Y))

-- 
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/groups/opt_out.