[web2py] Re: Download link for dynamic upload folder

2018-02-02 Thread David Orme
So at the moment, what users are seeing is a controller presenting 
SQLFORM.grid of dataset records, and then in the 'view' argument to that 
controller for a particular record, the file field is shown as the output 
of the represent method of UploadWidget (so the word 'file' wrapped up with 
the download link, which is ignorant of the subfolder). It isn't obvious to 
me that there is a way to insert new_ds_id into that mechanism?

The new_ds_id (which is an integer) is stored in the record as 
datasets.dataset_id, so I've tried setting the uploadfolder in the model 
after the table definition using this:

db.datasets.file.uploadfolder = lambda id, row: os.path.join(request.folder, 
'uploads','datasets', str(row.dataset_id))

But that breaks - I get an error message:  'function' object has no attribute 'endswith'. 
I think that is field.retrieve firmly expecting a string and trying to find 
the end character of the lambda function.

So, if that isn't possible, then I need a custom view of the record, which 
represents the file with a custom download function that I can pass 
new_ds_id to? 

On Friday, 2 February 2018 22:04:26 UTC, David Orme wrote:
>
> Hi,
>
> I'm collecting dataset files from users. There can be several versions as 
> problems with the files get fixed and I want to organise the uploaded files 
> by their common dataset id. So in my controller I do this:
>
> # set the upload directory locally
> upload_dir = os.path.join(request.folder, 'uploads', 'datasets', str(
> new_ds_id))
> db.datasets.file.uploadfolder = upload_dir
> 
> # Setup the form
> form = SQLFORM(db.datasets, 
>record = record, 
>fields=['project_id', 'file'],
>showid=False,
>deletable=False,
>button='Upload')
>
> That works really nicely and I just have to remember to use that path 
> where I need to find the file within the code. 
>
> However, I can't work out how to get the download controller to work with 
> the folder structure. For example, I'm currently using SQLFORM.grid to 
> provide a table of uploaded datasets, and when users click through to view 
> a particular record then they get the nice automatically generated file 
> download link. Unfortunately, that has no idea that there is the extra 
> component in the path, so it doesn't work.
>
> I've had a look at the source for response.download, heading into 
> field.retrieve and it looks like I should be able to set a custom_retrieve, 
> but I can't find example usage.
>  Any suggestions?
>
> Many thanks,
> David
>

-- 
Resources:
- http://web2py.com
- http://web2py.com/book (Documentation)
- http://github.com/web2py/web2py (Source code)
- https://code.google.com/p/web2py/issues/list (Report Issues)
--- 
You received this message because you are subscribed to the Google Groups 
"web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [web2py] Re: auth.messages.verify_email html template

2018-02-02 Thread Yi Liu
Thanks for sharing. I really hope web2py can officially update the native 
function to allow modern html email for verification. I understand the 
contributors have priorities.

Yi

On Saturday, November 22, 2014 at 5:56:06 AM UTC-8, Lisandro wrote:
>
> Hi Jay Martin. Actually, I ended up coding my own functions instead of 
> instantiating the Auth class. That is, I coded my own login, register, 
> reset_password, etc functions.
>
> For example, for the login, this is the code in the controller:
>
> # This code should run when the users posts the form with all required 
> data, and after doing some validation to the data provided
> from gluon.tools import web2py_uuid
> registration_key = web2py_uuid()
> db.auth_user.insert(\
> first_name=form.vars.first_name, \ 
> last_name=form.vars.last_name, \
> email=form.vars.email, \
> password=db.auth_user.password.validate(form.vars.password)[0], \
> registration_key=registration_key)
> mail.send(to=form.vars.email, subject='Confirm your registration', \
>   message='Hi %s, thanks for registering in our website!\n\n' %first_name 
> + \
> 'To finish the registration, please click on the next link:\n' + \
> '%s\n\n' %URL('default', 'user/verify_email/%s' %registration_key, 
> host=request.env.http_host))
>
>
> Then, in the default/user/verify_email I use this code:
>
> registration_key = request.args(1)
> user = db(db.auth_user.registration_key==registration_key
> ).select().first()
> if not user:
> redirect(URL('default', 'index'))
> user.update_record(registration_key='')
> auth.login_user(user)
> session.flash = 'Your registration has been confirmed. Thanks!'
> redirect(URL('init', 'default', 'index'))
>
>
> I hope it helps!
>
>
>
>
>
> El sábado, 22 de noviembre de 2014 10:39:12 UTC-3, Jay Martin escribió:
>>
>> @Lisandro, would happen to have these code snippets handy to share? I'm 
>> interested in using the mailgun api too. Either way, thanks for checking!
>>
>> My best,
>> Jay
>>
>> On Tuesday, October 29, 2013 5:46:51 PM UTC-4, Lisandro wrote:
>>>
>>>  ...
>>>
>>> For those interested in doing that, is just as simple as instantiating 
>>> Auth class and overwriting wanted methods, for example, I overwrited 
>>> "register" and "email_reset_password" methods in Auth class, that is, to 
>>> send my custom emails on register and request reset password respectively.
>>>
>>> Regards, Lisandro.
>>>
>>>
>>>

-- 
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: Download link for dynamic upload folder

2018-02-02 Thread Anthony
On Friday, February 2, 2018 at 5:04:26 PM UTC-5, David Orme wrote:
>
> Hi,
>
> I'm collecting dataset files from users. There can be several versions as 
> problems with the files get fixed and I want to organise the uploaded files 
> by their common dataset id. So in my controller I do this:
>
> # set the upload directory locally
> upload_dir = os.path.join(request.folder, 'uploads', 'datasets', str(
> new_ds_id))
> db.datasets.file.uploadfolder = upload_dir
> 
> # Setup the form
> form = SQLFORM(db.datasets, 
>record = record, 
>fields=['project_id', 'file'],
>showid=False,
>deletable=False,
>button='Upload')
>
> That works really nicely and I just have to remember to use that path 
> where I need to find the file within the code. 
>
> However, I can't work out how to get the download controller to work with 
> the folder structure. For example, I'm currently using SQLFORM.grid to 
> provide a table of uploaded datasets, and when users click through to view 
> a particular record then they get the nice automatically generated file 
> download link. Unfortunately, that has no idea that there is the extra 
> component in the path, so it doesn't work.
>
> I've had a look at the source for response.download, heading into 
> field.retrieve and it looks like I should be able to set a custom_retrieve, 
> but I can't find example usage.
>  Any suggestions?
>

The downside of custom_retrieve is that you've got to custom code a lot of 
additional logic just so you can specify a custom path. Is it feasible to 
include new_ds_id in the link (as an arg or var)? If so, either in the 
model code or in the download function, you can set the custom uploadfolder 
based on that value. Alternatively, you could do a query for the filename 
to retrieve the database record and get the new_ds_id from there, and then 
set the custom uploadfolder.

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] Download link for dynamic upload folder

2018-02-02 Thread David Orme
Hi,

I'm collecting dataset files from users. There can be several versions as 
problems with the files get fixed and I want to organise the uploaded files 
by their common dataset id. So in my controller I do this:

# set the upload directory locally
upload_dir = os.path.join(request.folder, 'uploads', 'datasets', str(
new_ds_id))
db.datasets.file.uploadfolder = upload_dir

# Setup the form
form = SQLFORM(db.datasets, 
   record = record, 
   fields=['project_id', 'file'],
   showid=False,
   deletable=False,
   button='Upload')

That works really nicely and I just have to remember to use that path where 
I need to find the file within the code. 

However, I can't work out how to get the download controller to work with 
the folder structure. For example, I'm currently using SQLFORM.grid to 
provide a table of uploaded datasets, and when users click through to view 
a particular record then they get the nice automatically generated file 
download link. Unfortunately, that has no idea that there is the extra 
component in the path, so it doesn't work.

I've had a look at the source for response.download, heading into 
field.retrieve and it looks like I should be able to set a custom_retrieve, 
but I can't find example usage.
 Any suggestions?

Many thanks,
David

-- 
Resources:
- http://web2py.com
- http://web2py.com/book (Documentation)
- http://github.com/web2py/web2py (Source code)
- https://code.google.com/p/web2py/issues/list (Report Issues)
--- 
You received this message because you are subscribed to the Google Groups 
"web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[web2py] Re: SQLFORM - update record, save datetime to table field

2018-02-02 Thread 黄祥
think you can use grid parameter onupdate, then assign the request.now as 
the value
ref:
http://web2py.com/books/default/chapter/29/07/forms-and-validators#SQLFORM-grid

best regards,
stifan

-- 
Resources:
- http://web2py.com
- http://web2py.com/book (Documentation)
- http://github.com/web2py/web2py (Source code)
- https://code.google.com/p/web2py/issues/list (Report Issues)
--- 
You received this message because you are subscribed to the Google Groups 
"web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[web2py] How to activate google analytics

2018-02-02 Thread Manuele Pesenti

Dear all,

is it indeed sill a good and updated choice to setup the variable 
response.google_analytics_id (in menu.py) in order to activate GA[1]?
I mean reading the offical GA documentation[2] it seams that GA is 
activated with such different js code and I was thinking if would be a 
better choice follow the official reference of the service.


Thanks for any suggest

Cheers

    Manuele

[1] 
http://web2py.com/books/default/chapter/29/05/the-views?search=google_analytics_id


[2] https://support.google.com/analytics/answer/1008080?hl=it

--
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] SQLFORM - update record, save datetime to table field

2018-02-02 Thread Omicron VT
I have a db table with a datetime field to save last update/creation date.

Field('fecha_update', 'datetime', default=request.now)

My question is : How i can save the update time of a record when i do it 
through sqlform.grid ?


-- 
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: appadmin.py interpret represent differently than default.py, causing keyError or attributeError

2018-02-02 Thread Yi Liu
Thank you so much for your detailed explanation. You also solved my puzzle 
about the behavior of join tables.  Amazing that you know I have join tables in 
default.py when I didn’t say it. Lol.

Really appreciate your help.

-- 
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: IMPORTANT - WEB2PY CONSULTING

2018-02-02 Thread David Zejda
Hi, 

If you can, please list Open-IT cz, s.r.o. (Czech Republic) as well.

Main website is https://www.o-it.info made in Zope. Though it should be 
replaced with something fresher. But, IMO, it is not as ugly that it could 
not be listed..

We have a plenty of web2py-based projects, such as:

http://www.englishlife.cz/
http://www.englishspace.cz/
http://www.englishanywhere.cz/
http://gjs.englishanywhere.cz/
http://lc.o-it.info/
http://www.netlektor.cz/

And we also offer web2py hosting:

http://www.o-it.info/weby/webhosting/web2py-hosting

Thank you in advance :)
D.

On Sunday, 15 February 2015 23:21:36 UTC+1, Massimo Di Pierro wrote:
>
> We need to update the list of companies that provide web2py consulting.
> This list is obsolete:
>
> http://web2py.com/init/default/support
>
> Some links are broke. Most pages do not even mention web2py. Some of them 
> have a design that is simply not acceptable for a web development company.
>
> That list will be eliminated. IF YOU WANT TO BE LISTED please update your 
> page to have a decent design and MENTION WEB2PY on the main site. Then 
> respond to this thread by providing an updated link and the country were 
> you incorporated. If you have a self-employed individual list your country 
> of residence.
>
>

-- 
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] web2py behind Apache with virtualhosts and SSL (SNI) leads to SSL_ERROR_RX_RECORD_TOO_LONG

2018-02-02 Thread David Zejda
Hi :)

I am having troubles with web2py behind Apache with multiple SSL 
virtualhosts, each serving different web2py application and encrypted with 
a different letsencrypt SSL key. All are served from the same IP address. I 
have only one web2py instance in my setup.
If I set-up up to 3 VirtualHosts (serving 3 applications), it works. But as 
soon as I add more applications in my setup, all HTTPS end up in 
SSL_ERROR_RX_RECORD_TOO_LONG.

Versions: Web2py 2.16.1, Apache 2.4.10, libapache2-mod-wsgi 4.3.0-1 (Debian 
Jessie)

My config follows; to make it concise I removed the portions dealing with 
static files, logging etc. which are not related to the problem:




  ServerName $domain
  WSGIDaemonProcess $domain user=www-data group=www-data 
display-name=%{GROUP} 
  WSGIScriptAlias / /opt/web2py/wsgihandler.py
  WSGIProcessGroup $domain

  
Require all denied
  

  
Require all denied
  

  
AllowOverride None
Require all denied

  Require all granted

  





  SSLEngine on
  SSLCertificateFile /etc/apache2/ssl/letsencrypt/$domain/fullchain.pem
  SSLCertificateKeyFile /etc/apache2/ssl/letsencrypt/$domain/privkey.pem

  ServerName $domain

  WSGIScriptAlias / /opt/web2py/wsgihandler.py
  WSGIProcessGroup $domain
  WSGIPassAuthorization On

  
AllowOverride None
Require all denied

  Require all granted

  






And one-liners in sites-enabled:

Use Web2PySSL www.domain1.com

Use Web2PySSL www.domain2.com

Use Web2PySSL www.domain3.com
...

SSL certificates are symlinked to /etc/apache2/ssl/letsencrypt.

routes.py:

routers = dict(
BASE=dict(
domains = {
  'www.domain1.com' : 'domain1',
  'www.domain3.com' : 'domain2',
  'www.domain3.com' : 'domain3',
  #...
}
),
)

I made several experiments to help to identify the cause. 

1) Instead of domain-specific letsencrypt certificates I tried one 
self-signed certificate for all domains. It increased the number of 
applications which work in my scenario from 3 to 5, but as soon as I add 
one more, it starts failing again. I think the main difference of the 
self-signed certificate in the context of the error is that it does not 
have any chain.

2) In order to find out if it is not a problem of Apache, I tried to set-up 
plain Apache virtualhosts with SSL support. It works. There are no problems 
with SSL at all, regardless to the number of virtualhosts.




  ServerName $domain
  DocumentRoot /var/www
  
Options FollowSymLinks
AllowOverride None
  
  
Options Indexes FollowSymLinks MultiViews
AllowOverride None
Order allow,deny
allow from all
  
  ErrorLog ${APACHE_LOG_DIR}/error.log
  LogLevel warn
  CustomLog ${APACHE_LOG_DIR}/access.log combined



  ServerName $domain
  SSLEngine on
  SSLCertificateFile /etc/apache2/ssl/letsencrypt/$domain/fullchain.pem
  SSLCertificateKeyFile /etc/apache2/ssl/letsencrypt/$domain/privkey.pem
  DocumentRoot /var/www
  
Options FollowSymLinks
AllowOverride None
  
  
Options Indexes FollowSymLinks MultiViews
AllowOverride None
Order allow,deny
allow from all
  
  ErrorLog ${APACHE_LOG_DIR}/error.log
  LogLevel warn
  CustomLog ${APACHE_LOG_DIR}/access.log combined




And:

Use testSSL www.domain1.com

Use testSSL www.domain2.com

Use testSSL www.domain3.com

...

3) In order to find out if it is not a problem of mod-wsgi, I tried the 
following. Again, no problems. Both HTTP and HTTPS is working well.

Simple WSGI handler in /var/www/wsgi/test.wsgi:

def application(environ, start_response):
status = '200 OK'
output = 'Just testing...'
response_headers = [('Content-type', 'text/plain'),('Content-Length', 
str(len(output)))]
start_response(status, response_headers)
return [output]



And related config:




  ServerName $domain

  WSGIDaemonProcess $domain user=www-data group=www-data 
display-name=%{GROUP} 
  WSGIScriptAlias / /var/www/wsgi/test.wsgi
  WSGIProcessGroup $domain

  DocumentRoot /var/www
  
Options FollowSymLinks
AllowOverride None
  
  
Options Indexes FollowSymLinks MultiViews
AllowOverride None
Order allow,deny
allow from all
  
  ErrorLog ${APACHE_LOG_DIR}/error.log
  LogLevel warn
  CustomLog ${APACHE_LOG_DIR}/access.log combined




  ServerName $domain

  SSLEngine on
  SSLCertificateFile /etc/apache2/ssl/letsencrypt/$domain/fullchain.pem
  SSLCertificateKeyFile /etc/apache2/ssl/letsencrypt/$domain/privkey.pem

  WSGIScriptAlias / /var/www/wsgi/test.wsgi
  WSGIProcessGroup $domain

  DocumentRoot /var/www
  
Options FollowSymLinks
AllowOverride None
  
  
Options Indexes FollowSymLinks MultiViews
AllowOverride None
Order allow,deny
allow from all
  
  ErrorLog ${APACHE_LOG_DIR}/error.log
  LogLevel warn
  CustomLog ${APACHE_LOG_DIR}/access.log combined





And:

Use testSSLWSGI www.domain1.com

Use testSSLWSGI www.domain2.com

Use testSSLWSGI www.domain3.com
...

So, my conclusion is 

[web2py] Switching database backend from sqlite to mysql

2018-02-02 Thread jburker

I currently have a mysql database that is defined using pydal and used by 
several other applications. I am trying to use Web2py to create an 
interface with the existing database. 

For testing I mirrored the schema of the database using sqlite and now that 
the project is ready I want to connect it to the mysql database, but I'm 
receiving the following error when trying to query the database from the 
controller:


1.
2.
3.
4.
5.
6.
7.
8.
9.
10.
11.
12.
13.
14.
15.
16.
17.
18.
19.
20.
21.
22.
23.
24.

Traceback (most recent call last):
  File "/Users/jon/github/build/web/gluon/restricted.py", line 219, in 
restricted
exec(ccode, environment)
  File 
"/Users/jon/github/build/web/applications/project/controllers/scenarios.py" 
, line 349, 
in 
  File "/Users/jon/github/build/web/gluon/globals.py", line 414, in 
self._caller = lambda f: f()
  File "/Users/jon/github/build/web/gluon/tools.py", line 3981, in f
return action(*a, **b)
  File "/Users/jon/github/build/web/applications/ 
project 
/controllers/scenarios.py"
 , line 207, 
in show
use_case_set = list({row.use_case_name for row in 
mysql_db(mysql_db.build_scenarios).select()})
  File "/Users/jon/.env/build/lib/python2.7/site-packages/pydal/objects.py", 
line 2250, in select
return adapter.select(self.query, fields, attributes)
  File 
"/Users/jon/.env/build/lib/python2.7/site-packages/pydal/adapters/base.py", 
line 762, in select
return self._select_aux(sql, fields, attributes, colnames)
  File 
"/Users/jon/.env/build/lib/python2.7/site-packages/pydal/adapters/base.py", 
line 718, in _select_aux
rows = self._select_aux_execute(sql)
  File 
"/Users/jon/.env/build/lib/python2.7/site-packages/pydal/adapters/base.py", 
line 712, in _select_aux_execute
self.execute(sql)
  File 
"/Users/jon/.env/build/lib/python2.7/site-packages/pydal/adapters/__init__.py", 
line 63, in wrap
if not args[0].connection:
  File "/Users/jon/.env/build/lib/python2.7/site-packages/pydal/connection.py", 
line 36, in connection
return getattr(THREAD_LOCAL, self._connection_uname_)
AttributeError: 'thread._local' object has no attribute 
'_pydal_connection_4382647568_28651'


To make things stranger, the query is sometimes successful on the first 
attempt after restarting the server, but a refresh always results in the 
error. Also using the web2py shell and loading the modules from the 
project, I am able to connect to the mysql database without error, and run 
the same query repeatedly without any issues.

-- 
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: appadmin.py interpret represent differently than default.py, causing keyError or attributeError

2018-02-02 Thread Anthony
On Thursday, February 1, 2018 at 11:23:41 PM UTC-5, Yi Liu wrote:
>
> I figured a work around:
>
> ```
> if request.controller == 'default':
> ctID = ctID.t_trial.f_ctid
> else:
> ctID = ctID.f_ctid
> ```
>
> It would be nice to fix from the source.
>

There is nothing to be done in appadmin.py -- it simply passes data to 
appadmin.html, which ultimately calls SQLTABLE. SQLTABLE itself simply 
passes the field's value and the record containing the value to the 
represent function -- it does not and cannot "interpret" the represent 
function -- it is up to you to write a represent function that works with 
the values that will be passed in.

In this case, the difference in behavior between appadmin and your 
controller is likely due to the fact that you are doing a join in the 
controller (the selects in appadmin do not involve joins). Without a join, 
values are referenced as row.fieldname, but with a join, you must use 
row.tablename.fieldname. If you need your "represent" function to 
accommodate both cases, then you must code it appropriately:

represent=lambda value, row: lastUpdateDateFormat(value, row.get('f_ctid', 
row.t_trial.f_ctid))

The above first attempts to get row.f_ctid, and if the "f_ctid" key does 
not exist on the row object (which would be the case when doing a join, 
unless the join also happens to include a table named "f_ctid"), it then 
uses the value row.t_trial.f_ctid.

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] xml namespaces

2018-02-02 Thread Yebach
Hello

Although not so much web2py question and more Python. I am struggling with 
creating some xmls - more specific namespaces. I would really appreciate it 
if smbd could help me with this

I am trying to get all the namespaces together., but somehow they are not 
named or declared properly, even more so if I have more data the numbers 
are increasing

This is what I have to get

http://xxx.yyy/sheme/pdr/skupno/v1; 
xmlns:ns2="http://xxx.yyy/sheme/pdr/v1; 
xmlns:ns3="http://xxx.yyy/sheme/kis/skupno/v2; 
xmlns:ns4="http://xxx.yyy/sheme/kis/v2; 
xmlns:ns5="http://xxx.yyy/sheme/pdr/sporocila/v1;>


80


4


D


12
2017

0
P_738


1
D4




738


10357




and this is what I am getting from my code


   http://rccirc.si/sheme/pdr/skupno/v1; 
xmlns:ns2="http://rccirc.si/sheme/pdr/v1; 
xmlns:ns3="http://rccirc.si/sheme/kis/skupno/v2; 
xmlns:ns4="http://rccirc.si/sheme/kis/v2; 
xmlns:ns5="http://rccirc.si/sheme/pdr/sporocila/v1; 
xmlns:ns0="ns5">
  
647
  
  
D
  
  
1
2018
  
  0
  0
  
250
  
  
80
  
  

  29
  1930-0730

  
  
Z1
  

...

  
647
  
  
D
  
  
1
2018
  
  0
  0
  
250
  
  
80
  
  

  3
  0730-1530

.
  
  
Z1
  


 

And since this is send trough REST my XML is always rejected
You can see the ns are incremented on lower levels and the xmlns:ns13="ns4" is 
rejected by server and also I cannot get behind the whole ns start number 
thing

Here is my code

root = etree.Element('{ns2}prenosPodatkovRazporedaZahtevaSporocilo', nsmap = 
{'ns': "http://xxx.yyy/sheme/pdr/skupno/v1;,
#'ns2': 
"http://rccirc.si/sheme/pdr/sporocila/v1;,
  
'ns2':"http://xxx.yyy/sheme/pdr/v1; ,

'ns3':"http://xxx.yyy/sheme/kis/skupno/v2;,
'ns4': 
"http://xxx.yyy/sheme/kis/v2;,
'ns5': 
"http://xxx.yyy/sheme/pdr/sporocila/v1"})
podatkiRazporedaMain = etree.SubElement(root, '{ns2}podatkiRazporeda')
# Add the subelements
#I. nivo
#tole gre na nivo delavca
for rec in grouped_workers:
podatkiRazporeda = etree.SubElement(podatkiRazporedaMain, 
'{ns3}podatkiRazporeda')
vrstaRazporeda= etree.SubElement(podatkiRazporeda, '{ns3}vrstaRazporeda')
vrstaRazporedaSifra = etree.SubElement(vrstaRazporeda, 'sifra').text = "647"
#vrstaRazporedaSifra.text = "647"
tipRazporeda= etree.SubElement(podatkiRazporeda, '{ns3}tipRazporeda')
tipRazporedaSifra = etree.SubElement(tipRazporeda, 'sifra').text = 'D'
#tipRazporedaSifra.text = 'D'

obdobje= etree.SubElement(podatkiRazporeda, '{ns3}obdobje')
obdobjeMesec= etree.SubElement(obdobje, '{ns3}mesec').text = 
str(results_woshi[0]["rw_date"].month)
#obdobjeMesec.text = str(results_woshi[0]["rw_date"].month)

obdobjeLeto= etree.SubElement(obdobje, '{ns3}leto').text = 
str(results_woshi[0]["rw_date"].year)
#obdobjeLeto.text = str(results_woshi[0]["rw_date"].year)

skupina= etree.SubElement(podatkiRazporeda, '{ns3}skupina')
skupina.text = "0"
izvor = etree.SubElement(podatkiRazporeda, '{ns3}izvor').text = "P_738"
#izvor.text = "P_738"
#vrstaRazporedaSifra.text = str(rec["data"][0]["rw_script"])

organizacijskaEnota= etree.SubElement(podatkiRazporeda, 
'{ns3}organizacijskaEnota')
organizacijskaEnotaSifra= etree.SubElement(organizacijskaEnota, 
'sifra').text = str(results_woshi[0]["rw_organization"])
#organizacijskaEnotaSifra.text = str(results_woshi[0]["rw_organization"])

delitvenaenota = etree.SubElement(podatkiRazporeda, '{ns3}delitvenaEnota')
delitvenaenotaSifra = etree.SubElement(delitvenaenota, 'sifra').text = '80'
#delitvenaenotaSifra.text ='80'

oznakeDelaZaDneve= etree.SubElement(podatkiRazporeda, 
'{ns3}oznakeDelaZaDneve')
zaposlenec = etree.SubElement(podatkiRazporeda, '{ns3}zaposlenec')
zaposlenecSifra= etree.SubElement(zaposlenec, '{ns5}osebnaStevilka').text = 
str(results_woshi[0]["rw_worker_nick"])
#zaposlenecSifra.text = str(results_woshi[0]["rw_worker_nick"])

# sporocilo= etree.SubElement(podatkiRazporeda, '{ns2}sporocilo')
# sporocilo.text = "Vpis zaposlenca"



#za vsakega delavca znotrej za vsak dan 

[web2py] Re: how to pass user input into url

2018-02-02 Thread Ntogg
thanks 

On Friday, January 19, 2018 at 4:34:57 PM UTC+8, Dave S wrote:
>
>
>
> On Tuesday, January 2, 2018 at 8:43:54 AM UTC-8, Ntogg wrote:
>>
>> I want to show the user their home address on the google map api that i 
>> am using. When the user inputs their address and clicks "submit", I want 
>> the google map api to pinpoint their address which I am trying to do by 
>> passing the user input into the iframe url of the google maps api. Any idea 
>> how I can do that with web2py? (I am very new to Python and web2py)
>>
>
> Sorry this got overlooked.  In case you're still wondering, I can mention 
> that the user input can be obtained in various ways, SQLFORM() being one of 
> the easiest. and your controller function would look at request.post_vars.  
> Assuming the Google Maps API uses values passed in the URL, you would just 
> append the values to the base url.  Something like
>
>
> # assume the address 123 xyz street,Hollywood,California comes from a form 
> with 4 inputsaddr_sgtr
> addr_str = request.post_vars.housenum + " " + request.post_vars.street + "," 
> + request.post_vars.city + "," + request.post_vars.state
> IFRAME(_src='http://www.google.com/maps/api?address=' + addr_str)
>
>
> (not tested ... I haven't worked with Google APIs, although I saw a demo 
> where GM was used to get the 10 closest Starbucks locations)
>
> /dps
>
>
>
>

-- 
Resources:
- http://web2py.com
- http://web2py.com/book (Documentation)
- http://github.com/web2py/web2py (Source code)
- https://code.google.com/p/web2py/issues/list (Report Issues)
--- 
You received this message because you are subscribed to the Google Groups 
"web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.