[web2py] Re: Emailing

2015-08-07 Thread Anthony Smith


I have looked at that but still cant figure out, do you have example 
cheers
tony

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

2015-08-07 Thread 黄祥
e.g. 
*private/appconfig.ini*
[smtp]
server = smtp.gmail.com:587
sender = em...@gmail.com
login  = email:password

*models/db.py*
from gluon.tools import Auth, Crud, Service, PluginManager, prettydate
auth = Auth(db)

mail = auth.settings.mailer
mail.settings.server = 'logging' if request.is_local else 
myconf.take('smtp.sender')
mail.settings.sender = myconf.take('smtp.sender')
mail.settings.login = myconf.take('smtp.login')

db.define_table('contact_us', 
Field('name'), 
Field('email'), 
Field('phone'), 
Field('address', 'text'), 
Field('messages', 'text'), 
format = '%(email)s %(name)s')

*controllers/default.py*
def contact_us():
form = SQLFORM(db.contact_us)
email = em...@gmail.com
if form.process().accepted:
mail.send(email,
 'Contacted from %s' % request.env.http_host,
 
'htmltabletrtdbName/b/tdtd%s/td/trtrtdbEmail/b/tdtd%s/td/trtrtdbPhone/b/tdtd%s/td/trtrtdbAddress/b/tdtd%s/td/trtrtdbMessages/b/tdtd%s/td/tr/table/html'
 
% (form.vars.name, form.vars.email, form.vars.phone, form.vars.address, 
form.vars.messages))
response.flash = T('messages sent')
elif form.errors:
response.flash = T('there is an error in the form')
else:
response.flash = T('please fill out the form')
return dict(form = form)

p.s.
you can modify to suit with your requirement

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] Re: 2.12.1 is out

2015-08-07 Thread JorgeH
thanks for the great job massimo and team!!

Is bootstrap 3 + as default?

On Friday, August 7, 2015 at 11:59:13 AM UTC-5, Massimo Di Pierro wrote:

 Changelog:

 - security fix: Validate for open redirect everywhere, not just in login()

 - allow to pack invidual apps and selected files as packed exe files

 - allow bulk user registration with default bulk_register_enabled=False

 - allow unsorted multiword query in grid search

 - better MongoDB support with newer pyDAL

 - enable app/appadmin/manage/auth by default for user admin

 - allow mail.settings.server='logging:filename' to log emails to a file

 - better caching logic

 - fixed order of confirm-password field

 - TLS support in ldap

 - prettydate can do UTC

 - jquery 1.11.3

 - bootstrap 3.3.5

 - moved to codecov and enabled appveyor

 - many bug fixes


 I am sure I am missing many important changes. Thanks to Niphlod, Paolo, 
 Giovanni, Leonel, Mark, Tim, Anthony, Cassio, Stephen, and all those who's 
 names I do not know or I do not remember but who are giving so much to 
 web2py.


 Thank you!


 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.


Re: [web2py] Re: Emailing

2015-08-07 Thread Anthony Smith
Are got it.

thankyou

On Sat, Aug 8, 2015 at 9:58 AM, 黄祥 steve.van.chris...@gmail.com wrote:

 e.g.
 *private/appconfig.ini*
 [smtp]
 server = smtp.gmail.com:587
 sender = em...@gmail.com
 login  = email:password

 *models/db.py*
 from gluon.tools import Auth, Crud, Service, PluginManager, prettydate
 auth = Auth(db)

 mail = auth.settings.mailer
 mail.settings.server = 'logging' if request.is_local else
 myconf.take('smtp.sender')
 mail.settings.sender = myconf.take('smtp.sender')
 mail.settings.login = myconf.take('smtp.login')

 db.define_table('contact_us',
 Field('name'),
 Field('email'),
 Field('phone'),
 Field('address', 'text'),
 Field('messages', 'text'),
 format = '%(email)s %(name)s')

 *controllers/default.py*
 def contact_us():
 form = SQLFORM(db.contact_us)
 email = em...@gmail.com
 if form.process().accepted:
 mail.send(email,
  'Contacted from %s' % request.env.http_host,
  
 'htmltabletrtdbName/b/tdtd%s/td/trtrtdbEmail/b/tdtd%s/td/trtrtdbPhone/b/tdtd%s/td/trtrtdbAddress/b/tdtd%s/td/trtrtdbMessages/b/tdtd%s/td/tr/table/html'
 % (form.vars.name, form.vars.email, form.vars.phone, form.vars.address,
 form.vars.messages))
 response.flash = T('messages sent')
 elif form.errors:
 response.flash = T('there is an error in the form')
 else:
 response.flash = T('please fill out the form')
 return dict(form = form)

 p.s.
 you can modify to suit with your requirement

 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 a topic in the
 Google Groups web2py-users group.
 To unsubscribe from this topic, visit
 https://groups.google.com/d/topic/web2py/diE-ddw8EYY/unsubscribe.
 To unsubscribe from this group and all its topics, send an email to
 web2py+unsubscr...@googlegroups.com.
 For more options, visit https://groups.google.com/d/optout.


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


[web2py] Code organization help

2015-08-07 Thread David Ripplinger
Hi all,

This is a request for ideas on good code organization for my application. 
I've been reading up on the preferred organization for web2py as well as 
typical REST HTTP conventions, and I'm trying to use some ideas of both 
where they make sense.

If I understand correctly, web2py takes more of a verb approach, where a 
URL maps to a controller and then an action, which has a corresponding 
view. Additional parameters for the action can be additions to the URL 
(e.g. /app/controller/action/arg1/arg2) or key/value pairs in a query, 
though parameters can also be passed through the HTTP request body (but I'm 
not as familiar with how to read these in using web2py. Typical REST HTTP 
conventions, however, seem to use URL structures identifying resources, 
i.e. using nouns and then letting the HTTP method map to what to do with 
that resource (e.g. GET or POST or DELETE /app/persons/5). Each HTTP method 
on the same URL would map to a different action, effectively, on that 
resource or type of resource. I see some overlap here, making me think I 
can find I nice mix, but it's not immediately clear in my mind. With that 
intro, here's my current code hierarchy:

models:
  - dbTables.py
  - object_a/object_a.py
  - create_a_type1()
  - create_a_type2()
  - update_a()
  - get_info_abt_a()
  - ...other functions the controller shouldn't touch, i.e., private 
functions
  - object_b/object_b.py
  - create_b()
  - rename_b()
controllers:
  - object_a.py
  - ...what do I put in here???
  - object_b.py
  - ...what do I put in here???

I organized the models folder that way so that any given call won't reload 
the entire models code base. If I wanted to go the route of REST design, I 
was thinking of maybe adding to controllers/object_a.py a couple of 
functions called type1() and type2(), then checking whether the request was 
a GET or POST or whatever to then call the appropriate function in the 
model. But then models/object_b/object_b.py only describes one resource, so 
it feels kinda tacky to put within controllers/object_b.py a function 
called object_b(), since then the URL to call that function would be 
/app/object_b/object_b/..., which is a redundant and doesn't make for a 
clean API.

On the other hand, I could do something like move all the public model 
functions into the corresponding controllers instead, but then the URLs 
would be verbs instead of nouns (aka resources), and I wouldn't be able to 
keep a concise API that overloads a URL with the different HTTP methods.

What are your thoughts?

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


[web2py] Re: CSV save on Server

2015-08-07 Thread Anthony
I assume that's not the actual code, as there is a syntax error (no . 
before the write). Also, you appear to be doing the same thing twice -- 
first using str() to convert the Rows to CSV, and then using the 
export_to_csv_file method. As detailed in the book, those methods are the 
same -- just pick one.

Anthony

On Friday, August 7, 2015 at 3:42:17 PM UTC-4, forumweb...@gmail.com wrote:

 Ok, i change the code but i get an error:

 @auth.requires_login()
 def create_csv():
 from gluon.contenttype import contenttype
 import os
 response.headers['Content-
 Type'] = contenttype('.csv')
 response.headers['Content-disposition'] = 'attachment; 
 filename=%s_database.csv' % (
 request.now
 )
 import csv
 s=open('mycsvfile.csv','wb')write(str(db(mydb.mytable.id).select()))
 db((db.grunddaten.id0)).select().export_to_csv_file(s, 
 delimiter=',', quotechar='', quoting=csv.QUOTE_NONNUMERIC)
 s.close()

 TicketFile: type 'exceptions.TypeError argument 1 must have a write 
 method


 Am Freitag, 7. August 2015 20:39:32 UTC+2 schrieb forum...@gmail.com:

 He group, 

 i create serial letters with web2py and pdfLatex. It works fine with a 
 static csv-file in private folder. 
 But i want to create the csv and save directly to the folder. No Download!

 I create the csv ... no Problem:

 @auth.requires_login()
 def create_csv():
 from gluon.contenttype import contenttype
 import os
 response.headers['Content-Type'] = contenttype('.csv')
 response.headers['Content-disposition'] = 'attachment; 
 filename=%s_database.csv' % (
 request.now
 )
 import csv, cStringIO
 s = cStringIO.StringIO()
 db((db.grunddaten.id0)).select().export_to_csv_file(s, 
 delimiter=',', quotechar='', quoting=csv.QUOTE_NONNUMERIC)
 return s.getvalue()

 But how can i save this file directly on my folder?



-- 
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: 2.12.1 is out

2015-08-07 Thread Massimo Di Pierro
Ne because it iI do not know for sure that is a bug in web2py.


On Friday, 7 August 2015 14:14:18 UTC-5, ermolaev.icrea...@gmail.com wrote:

 pickled.HIGHPROTOCOL - fixed?


-- 
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: type 'exceptions.AttributeError'

2015-08-07 Thread Anthony
How is request.vars.table being set? For that to work, presumably you would 
need ?table=some_table in the query string of the URL used to access the 
grid.

Anthony

On Friday, August 7, 2015 at 6:27:52 PM UTC-4, ESRA GÜÇLÜ wrote:


 Hi ,
 I'm pretty new to web2py, I'm developing a project for my internship and i 
 have a problem.

 My program gets a choice from user and according to the choice it shows db 
 table on the SQLFORM.grid.
 SQLFORM.grid is displaying but the user cannot add new record or delete or 
 update. This is my code:

 def operations():
 table_name = request.vars.table
 grid = SQLFORM.grid(db[table_name], user_signature=False)
 return locals()

 i have this error: type 'exceptions.AttributeError' 

 Version 2.11.2-stable+timestamp.2015.05.30.16.33.24

 Traceback (most recent call last):
   File C:\web2py_win\web2py\gluon\restricted.py, line 227, in restricted
 exec ccode in environment
   File C:/web2py_win/web2py/applications/Inventory/controllers/admin.py 
 http://127.0.0.1:8000/admin/default/edit/Inventory/controllers/admin.py, 
 line 22, in module
   File C:\web2py_win\web2py\gluon\globals.py, line 412, in lambda
 self._caller = lambda f: f()
   File C:/web2py_win/web2py/applications/Inventory/controllers/admin.py 
 http://127.0.0.1:8000/admin/default/edit/Inventory/controllers/admin.py, 
 line 19, in operations
 grid = SQLFORM.grid(db[table_name], user_signature=False)
   File C:\web2py_win\web2py\gluon\packages\dal\pydal\base.py, line 899, in 
 __getitem__
 return self.__getattr__(str(key))
   File C:\web2py_win\web2py\gluon\packages\dal\pydal\base.py, line 906, in 
 __getattr__
 return super(DAL, self).__getattr__(key)
   File C:\web2py_win\web2py\gluon\packages\dal\pydal\helpers\classes.py, 
 line 348, in __getattr__
 raise AttributeError
 AttributeError


 Best regards.


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


[web2py] web2py - display nslookup result

2015-08-07 Thread Heinrich Piard
Hi,

I this default.py

import os
import sys

def nslookup():
form = SQLFORM.factory(Field('hostname',
 label='Please enter a valid HOSTNAME to 
resolve:',
 requires=IS_NOT_EMPTY()))
if form.process().accepted:
response.flash = Hostname accepted
session.hostname = os.system(dig +short +time=1 +   + 
request.vars.hostname)
else:
response.flash = 'Please fill the form with a valid hostname'
ipaddress = session.hostname
return dict(form=form, ipaddress=ipaddress)

and respective nslookup.html

{{extend 'layout.html'}}
h1Domain Name Lookup Tool/h1

{{=form}}

h2
Entered HOSTNAME has IP Address:
/h2
{{=BEAUTIFY(ipaddress)}}



However, the resolved IP does not work though I see the nslookup when doing 
a tcpdump.

Any help would be appreciated.

-- 
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] type 'exceptions.AttributeError'

2015-08-07 Thread ESRA GÜÇLÜ

Hi ,
I'm pretty new to web2py, I'm developing a project for my internship and i 
have a problem.

My program gets a choice from user and according to the choice it shows db 
table on the SQLFORM.grid.
SQLFORM.grid is displaying but the user cannot add new record or delete or 
update. This is my code:

def operations():
table_name = request.vars.table
grid = SQLFORM.grid(db[table_name], user_signature=False)
return locals()

i have this error: type 'exceptions.AttributeError' 

Version 2.11.2-stable+timestamp.2015.05.30.16.33.24

Traceback (most recent call last):
  File C:\web2py_win\web2py\gluon\restricted.py, line 227, in restricted
exec ccode in environment
  File C:/web2py_win/web2py/applications/Inventory/controllers/admin.py 
http://127.0.0.1:8000/admin/default/edit/Inventory/controllers/admin.py, line 
22, in module
  File C:\web2py_win\web2py\gluon\globals.py, line 412, in lambda
self._caller = lambda f: f()
  File C:/web2py_win/web2py/applications/Inventory/controllers/admin.py 
http://127.0.0.1:8000/admin/default/edit/Inventory/controllers/admin.py, line 
19, in operations
grid = SQLFORM.grid(db[table_name], user_signature=False)
  File C:\web2py_win\web2py\gluon\packages\dal\pydal\base.py, line 899, in 
__getitem__
return self.__getattr__(str(key))
  File C:\web2py_win\web2py\gluon\packages\dal\pydal\base.py, line 906, in 
__getattr__
return super(DAL, self).__getattr__(key)
  File C:\web2py_win\web2py\gluon\packages\dal\pydal\helpers\classes.py, line 
348, in __getattr__
raise AttributeError
AttributeError


Best regards.

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


[web2py] Re: How to set Content-type:application/json for all subpages

2015-08-07 Thread Alehandro Ramoz Rodrigez

Great! Now it works as expected. 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: gluon.contrib.populate didn't fill upload and password field type

2015-08-07 Thread 黄祥
IntegrityError: FOREIGN KEY constraint failed ?
perhaps you modify auth_user table, could you show some code.

no, i don't use populate, i insert it manually.
e.g.
controllers/install.py
# -*- coding: utf-8 -*-

# index
def index():
if db(db.auth_permission).isempty() and db(db.auth_membership).isempty():
# group
auth.add_group('Manager', 'Manager')
auth.add_group('Admin', 'Admin')
# user
db.auth_user.bulk_insert([{first_name : Admin, last_name : Admin, 
  email : ad...@a.com, username : admin, 
  password : db.auth_user.password.validate(a)[0] }, 
 {first_name : User, last_name : User, 
  email : u...@a.com, username : user, 
  password : db.auth_user.password.validate(a)[0] } ] )


membership (group_id, user_id)

auth.add_membership(1, 1)
auth.add_membership(2, 1)
auth.add_membership(2, 2)

# permission
auth.add_permission(1, impersonate, auth_user, 2)

session.flash = T('Installation Done')
redirect(URL('default', 'index'))

best regards,
stifan

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


Re: [web2py] To display random questions one by one

2015-08-07 Thread 黄祥
perhaps you can use random
ref:
http://web2py.com/books/default/chapter/29/06/the-database-abstraction-layer#orderby--groupby--limitby--distinct--having-orderby_on_limitby-left-cache
https://groups.google.com/forum/#!topic/web2py/-Y2JL2cIQEI

best regards,
stifan

On Thursday, August 6, 2015 at 4:10:01 AM UTC+7, Fabiano Almeida wrote:

 Hi Sai,

 Can you try this:

 import  random

 ## first option to select question
 s = number of lines of your table
 i = random.randint(0,s)

 ## second option to select question - best: no broke if delete any record 
 on table
 s = db(db.ins_ques.id  0).select(db.ins_ques.id)
 i = random.sample(s,1)

 ## how to query your question
 question=db(db.ins_ques.id == i).select(db.ins_ques.ALL).first()

 [...]


 Fabiano.

 2015-07-28 5:51 GMT-03:00 Sai Harsh Tondomker saihar...@iiits.in 
 javascript::

 I have trying to display random question for every login (Means client 
 get different questions for every login).
 Here I gave my db.py and def doing paper. Please help me to solve the 
 problem. 


 db.define_table('ins_ques',
 Field('qnum','integer',notnull=True,readable=False,writable=False,label='Question
  
 Number'),
 Field('qupload','upload',label='Upload Image'),
 Field('question','text',notnull=True,label='Question'),
 Field('op1','string',notnull=True,label='Option A'),
 Field('op2','string',notnull=True,label='Option B'),
 Field('op3','string',notnull=True,label='Option C'),
 Field('op4','string',notnull=True,label='Option D'),
 Field('cor_ans',requires=IS_IN_SET(['A','B','C','D'],multiple=True),label='Correct
  
 Answer',widget=SQLFORM.widgets.checkboxes.widget)
 )
 db.define_table('ans_ques',
 Field('qdate','date',readable=False,writable=False,label='Date of Paper'),
 Field('qnum','integer',readable=False,writable=False),
 Field('studentid','integer',readable=False,writable=False),

 Field('answer','string',requires=IS_IN_SET(['A','B','C','D'],multiple=True),widget=SQLFORM.widgets.checkboxes.widget)
 )
 db.define_table('marks',
 Field('studentid',db.auth_user,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=='students')),'auth_user.id
 ','auth_user.first_name'),readable=False,writable=False),
 Field('marks','integer'))



 def doing_paper():
 pid=auth.user_id
 q_num=int(request.vars.q_num)
 question=db((q_num==db.ins_ques.qnum)).select(db.ins_ques.ALL)
 val=db(db.ins_ques).select(db.ins_ques.ALL)
 rmax=0
 for f in val:
   rmax+=1
 if (q_num = 0):
 response.flash='This is the first question'
 q_num=1
 redirect(URL(r=request,f='doing_paper?q_num=%s') % (q_num) )
 elif (len(question)  0) :
 for i in question:
 if i:
 question=i
 break
 else:
 q_num=q_num-1
 redirect(URL(r=request,f='preprocess?q_num=%s') % (q_num))
 else:
 q_num=q_num-1
 redirect(URL(r=request,f='preprocess?q_num=%s') % (q_num))
 if question:
 form=SQLFORM.factory(db.ans_ques)
 form.vars.qnum=q_num
 form.vars.studentid=pid
 
 answered=db((db.ans_ques.answer!='||')(db.ans_ques.studentid==pid)).select(db.ans_ques.qnum)
 n=[]
 for k in answered:
 n.append(k['qnum'])
 
 ans_yet=db((db.ans_ques.studentid==pid)(db.ans_ques.qnum==q_num)).select(db.ans_ques.answer)
 if(ans_yet and ans_yet[0]['answer']!='||'):
 form.vars.answer=ans_yet[0]['answer']
 if form.accepts(request.vars,session):
 if 
 db((db.ans_ques.qnum==q_num)(db.ans_ques.studentid==pid)).select(db.ans_ques.answer):

 db((db.ans_ques.qnum==q_num)(db.ans_ques.studentid==pid)).update(answer=form.vars.answer)
 else:
 db.ans_ques.insert(answer=form.vars.answer,qnum=q_num,studentid=pid)
 q_num=q_num+1
 redirect(URL(r=request,f='doing_paper?q_num=%s') % (q_num))
 return locals()

 Regards 
 Sai Harsh

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


Re: [web2py] can web2py be used as a static website generator?

2015-08-07 Thread Mark Graves
Hello,

I realize this is a bit of an old thread, but I figured I'd post an answer 
anyway as I came up with this same problem recently.

For development, sometimes I create static sites before I get into the 
dynamic interaction.

I handled this case with a simple routes.py in the web2py folder

for the app I wanted to replace, I put in all the html in one folder at 
/APPLICATION_NAME/static/html

Then in routes.py:

routes_in = (

  ('/APPLICATION_NAME/(?Pany.*)', '/APPLICATION_NAME/static/html/\gany'
),

)

routes_out = (

  ('/APPLICATION_NAME/(?Pany.*)', '/\gany'),
)

where APPLICATION_NAME is the name of the application I wanted to run 
completely as static files.

I'm not certain of any security implications (someone else would have to 
comment), so I wouldn't deploy this method in production but it allows me 
to do rapid dev.



-- 
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 response Content-Length parameter by file size

2015-08-07 Thread 黄祥
perhaps you can use request.env.content_length
ref:
http://web2py.com/books/default/chapter/29/04/the-core#request

best regards,
stifan

On Friday, August 7, 2015 at 3:14:18 PM UTC+7, Alehandro Ramoz Rodrigez 
wrote:

 My application should respond to remote application request with data from 
 attached file.
 By default web2py has Transfer-Encoding: Chunked parameter and for some 
 reason remote app can get only
 first string from file, so I need to use Content-Length parameter that 
 set to file bytes size.
 My current Controller is:
 def file_to_process():
 try:
 files = Expose('/home/user/Desktop/TAA_Testing/Policies_for_send')
 except HTTP as http_response:
 if http_response.status == 200:
 http_response.headers['Content-Type'] = 'application/json'
 http_response.headers['Content-Length'] = '1000'
 raise http_response
 return dict(files=files)

 In this case remote app will get only 1000 bytes of data so I want to know 
 what value should I set to respond with full range of data that file 
 contain?


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

2015-08-07 Thread Anthony Smith
Hi All,

I have a app where I records sales, but I want to email different part of 
the sale to different people eg the person I brought only need to know what 
I item and how much, then another person needs to know how many and the 
item and how much.

I can get this by using a post,but I cant workout how to email the post or 
create a controller that will do this.

thanks for any help 

cheers

tony

-- 
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 1.12.1 is out

2015-08-07 Thread Massimo Di Pierro
Changelog:

- security fix: Validate for open redirect everywhere, not just in login()

- allow to pack invidual apps and selected files as packed exe files

- allow bulk user registration with default bulk_register_enabled=False

- allow unsorted multiword query in grid search

- better MongoDB support with newer pyDAL

- enable app/appadmin/manage/auth by default for user admin

- allow mail.settings.server='logging:filename' to log emails to a file

- better caching logic

- fixed order of confirm-password field

- TLS support in ldap

- prettydate can do UTC

- jquery 1.11.3

- bootstrap 3.3.5

- moved to codecov and enabled appveyor

- many bug fixes


I am sure I am missing many important changes. Thanks to Niphlod, Paolo, 
Giovanni, Leonel, Mark, Tim, Anthony, Cassio, Stephen, and all those who's 
names I do not know or I do not remember but who are giving so much to 
web2py.


Thank you!


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

2015-08-07 Thread 黄祥
please take a look at the book :
http://web2py.com/books/default/chapter/29/08/emails-and-sms

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 set response Content-Length parameter by file size

2015-08-07 Thread Alehandro Ramoz Rodrigez
My application should respond to remote application request with data from 
attached file.
By default web2py has Transfer-Encoding: Chunked parameter and for some 
reason remote app can get only
first string from file, so I need to use Content-Length parameter that 
set to file bytes size.
My current Controller is:
def file_to_process():
try:
files = Expose('/home/user/Desktop/TAA_Testing/Policies_for_send')
except HTTP as http_response:
if http_response.status == 200:
http_response.headers['Content-Type'] = 'application/json'
http_response.headers['Content-Length'] = '1000'
raise http_response
return dict(files=files)

In this case remote app will get only 1000 bytes of data so I want to know 
what value should I set to respond with full range of data that file 
contain?

-- 
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 to many relationship

2015-08-07 Thread Lisandro
Hi there.
Web2py has some cool field types called list:string, list:integer and 
list:reference table. Check them here:
http://www.web2py.com/books/default/chapter/29/06/the-database-abstraction-layer#Field-types

In your case, you could avoid the creation of the third table with 
*list:reference 
table*, for example, in your db.py:

db.define_table('skill', Field('name'))

db.define_table('worker',\
Field('name'),\
Field('skills','list:reference skill'))


Then you can do things like:

skill_1 = db.skill.insert(name='coding in python')
skill_2 = db.skill.insert(name='making a cake')
skill_3 = db.skill.insert(name='writing a song')

db.worker.insert(name='John', skills=[skill_1, skill_2])
db.worker.insert(name='Paul', skills=[skill_3])
db.worker.insert(name='Richard', skills=[skill_2, skill_3])

# search which workers have skill_2:
have_skill_3 = db(db.worker.skills.contains(skill_2)).select()


The list:reference field will be rendered as a select with multiple=True.
You can always write your own widget to use other stuff, like checkboxes.

Look for list:reference in this group, you will lots of posts about it. 
Hope it helps!



El jueves, 6 de agosto de 2015, 22:51:53 (UTC-3), Yebach escribió:

 Hello

 How to solve the problem of one to many relationship:

 Lets say I have a worker that has multiple skills. How to set up SQLFORM 
 to add as many skills to the worker as possible.

 So skills in one table workers in another.I guess a third table will be 
 needed

 Thank you

 best regards


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


[web2py] Re: web2py 1.12.1 is out

2015-08-07 Thread Jack Kuan
surely you meant 2.12.1 ?

-- 
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: avoid controller to sanitize html

2015-08-07 Thread Luis Valladares
Thanks Anthony! using the option helper and returning without the 
dictionary solved my issue, there is other errors on the javascript but i 
already solved it, now works well, one more question: There is no built-in 
function that creates a dropdown list from a DAL select?

El viernes, 7 de agosto de 2015, 11:34:31 (UTC-4:30), Anthony escribió:

 If your function returns a dictionary, web2py assumes you want to execute 
 a view. If you haven't created a view, it will use generic.html (by 
 default, this only works for local requests). If you just want to return 
 the raw HTML generated in the controller without then executing a view, 
 then just return the HTML (i.e., no dictionary).

 Additionally, you might want to consider building the HTML using the 
 web2py HTML helpers rather than building it via strings. In that case, you 
 can just return the final HTML helper, and it will automatically be 
 converted to an HTML string before returning to the browser.

 If you do actually have a view that is being executed and you want to 
 insert raw HTML, you would wrap it in XML() (though, again, you could 
 instead just use the web2py HTML helpers and not bother with XML()).

 Anthony

 On Friday, August 7, 2015 at 11:50:47 AM UTC-4, Luis Valladares wrote:

 Hello!

 I've a form where i store country, state and municipality and i need to 
 dynamcally change the value based on the select, i mean: If i select a X 
 country i need to display only the states of the country X in the states 
 dropdown, the same with municipality

 I used a basic approach that i've used many times befores in other 
 languages, a jquery function on dropdown change that ajax call a page and 
 it returns the options and put it into the dropdown, i've been researching 
 and found this really helpful: 
 http://stackoverflow.com/questions/10387672/web2py-dropdown-menu, so 
 based on this answer i build this structure:

 On the controller: 

 def ajaxMunicipio():
 if request.args(0) in db.estados.id:
 response.generic_patterns = ['load']
 data = db(db.municipios.estado == request.args(0)).select()
 html = \select\
 for fila in data:
 html += \option value=\+str(fila.id
 )+\\+fila.nombre+\/option\
 html += \/select\
 return dict(form=html)
 else:
 raise HTTP(404)





 And on the view:

   jQuery(function() {
 jQuery('#no_table_estado_id').change(function() {
   var request = $.ajax({
 url: {{=URL('hot', 'ajaxMunicipio.load')}} + / + 
 jQuery(this).val(),
 method: GET,
 dataType: html
 });
   request.done(function(html) {
 console.log(html)
 $(#no_table_municipio_id).val(html);
   });
 })
   })



 everything works well on the call side but i recieve the HTML sanitized 
 like this: \lt;select\gt;\lt;option 
 value=quot;1quot;\gt;LIBERTADOR\lt;/option\gt;\lt;/select\gt;

 So i'm looking for a way to avoid web2py to sanitize the html, or maybe a 
 cleanest way to do this because i dont really like looping the data in the 
 controller in order to create the HTML

 I appreciate any help you can give! Thanks for your atention




-- 
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] avoid controller to sanitize html

2015-08-07 Thread Luis Valladares
Hello!

I've a form where i store country, state and municipality and i need to 
dynamcally change the value based on the select, i mean: If i select a X 
country i need to display only the states of the country X in the states 
dropdown, the same with municipality

I used a basic approach that i've used many times befores in other 
languages, a jquery function on dropdown change that ajax call a page and 
it returns the options and put it into the dropdown, i've been researching 
and found this really helpful: 
http://stackoverflow.com/questions/10387672/web2py-dropdown-menu, so based 
on this answer i build this structure:

On the controller: 

def ajaxMunicipio():
if request.args(0) in db.estados.id:
response.generic_patterns = ['load']
data = db(db.municipios.estado == request.args(0)).select()
html = \select\
for fila in data:
html += \option 
value=\+str(fila.id)+\\+fila.nombre+\/option\
html += \/select\
return dict(form=html)
else:
raise HTTP(404)





And on the view:

  jQuery(function() {
jQuery('#no_table_estado_id').change(function() {
  var request = $.ajax({
url: {{=URL('hot', 'ajaxMunicipio.load')}} + / + 
jQuery(this).val(),
method: GET,
dataType: html
});
  request.done(function(html) {
console.log(html)
$(#no_table_municipio_id).val(html);
  });
})
  })



everything works well on the call side but i recieve the HTML sanitized 
like this: \lt;select\gt;\lt;option 
value=quot;1quot;\gt;LIBERTADOR\lt;/option\gt;\lt;/select\gt;

So i'm looking for a way to avoid web2py to sanitize the html, or maybe a 
cleanest way to do this because i dont really like looping the data in the 
controller in order to create the HTML

I appreciate any help you can give! Thanks for your atention


-- 
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: gluon.contrib.populate didn't fill upload and password field type

2015-08-07 Thread Ben Lawrence
Thanks Stifan,
I don't have any code, but just type this into the shell:
from gluon.contrib.populate import populate 
populate(db.auth_user,10) 

but you have shown me another way I can do it.

On Friday, August 7, 2015 at 12:48:41 AM UTC-7, 黄祥 wrote:

 IntegrityError: FOREIGN KEY constraint failed ?
 perhaps you modify auth_user table, could you show some code.

 no, i don't use populate, i insert it manually.
 e.g.
 controllers/install.py
 # -*- coding: utf-8 -*-

 # index
 def index():
 if db(db.auth_permission).isempty() and db(db.auth_membership).isempty():
 # group
 auth.add_group('Manager', 'Manager')
 auth.add_group('Admin', 'Admin')
 # user
 db.auth_user.bulk_insert([{first_name : Admin, last_name : Admin, 
   email : ad...@a.com javascript:, username : admin, 
   password : db.auth_user.password.validate(a)[0] }, 
  {first_name : User, last_name : User, 
   email : us...@a.com javascript:, username : user, 
   password : db.auth_user.password.validate(a)[0] } ] )

 
 membership (group_id, user_id)
 
 auth.add_membership(1, 1)
 auth.add_membership(2, 1)
 auth.add_membership(2, 2)

 # permission
 auth.add_permission(1, impersonate, auth_user, 2)

 session.flash = T('Installation Done')
 redirect(URL('default', 'index'))

 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] Re: Problem with calling Field Methods after upgrading to 2.11.2 from 2.9.10

2015-08-07 Thread Umpei Kurokawa
It is a Method Field, 

Field.Method('do_someting', . ) 

On Thursday, August 6, 2015 at 10:55:22 PM UTC-4, Massimo Di Pierro wrote:

 what is out.dog.do_something()?
 Is it an example of a VirtualMethod?

 On Thursday, 6 August 2015 16:36:13 UTC-5, Umpei Kurokawa wrote:

 I'm having problems after upgrading web2py to 2.11.2 from 2.9.10, that I 
 wasn't getting before. 

 The problem appears to happen when I make a select call with an inner 
 join, and than trying to make calls to a Field Method associated with that 
 table. I get this error: 

 So for example I am doing something like : 

 out = db((db.breed.id == 
 db.dog.breed)).select().first()  


 out.dog.do_something()

 This will fail  with the below error

 File 
 /home/ukurokawa/Documents/web2py_2112/gluon/packages/dal/pydal/helpers/classes.py,
  
 line 348, in __getattr__

 raise AttributeError
 AttributeError



-- 
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] 2.12.1 is out

2015-08-07 Thread Massimo Di Pierro
Changelog:

- security fix: Validate for open redirect everywhere, not just in login()

- allow to pack invidual apps and selected files as packed exe files

- allow bulk user registration with default bulk_register_enabled=False

- allow unsorted multiword query in grid search

- better MongoDB support with newer pyDAL

- enable app/appadmin/manage/auth by default for user admin

- allow mail.settings.server='logging:filename' to log emails to a file

- better caching logic

- fixed order of confirm-password field

- TLS support in ldap

- prettydate can do UTC

- jquery 1.11.3

- bootstrap 3.3.5

- moved to codecov and enabled appveyor

- many bug fixes


I am sure I am missing many important changes. Thanks to Niphlod, Paolo, 
Giovanni, Leonel, Mark, Tim, Anthony, Cassio, Stephen, and all those who's 
names I do not know or I do not remember but who are giving so much to 
web2py.


Thank you!


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 1.12.1 is out

2015-08-07 Thread Massimo Di Pierro
yes. re-posting.

On Friday, 7 August 2015 09:17:05 UTC-5, Jack Kuan wrote:

 surely you meant 2.12.1 ?


-- 
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 response Content-Length parameter by file size

2015-08-07 Thread Anthony
See answer here: http://stackoverflow.com/a/31882961/440323

Unless you need the file-listing functionality of Expose, don't bother with 
it -- instead just use response.stream (even if you do need Expose for 
listing the files, you can still use response.stream to do the individual 
file serving).

Anthony

On Friday, August 7, 2015 at 4:14:18 AM UTC-4, Alehandro Ramoz Rodrigez 
wrote:

 My application should respond to remote application request with data from 
 attached file.
 By default web2py has Transfer-Encoding: Chunked parameter and for some 
 reason remote app can get only
 first string from file, so I need to use Content-Length parameter that 
 set to file bytes size.
 My current Controller is:
 def file_to_process():
 try:
 files = Expose('/home/user/Desktop/TAA_Testing/Policies_for_send')
 except HTTP as http_response:
 if http_response.status == 200:
 http_response.headers['Content-Type'] = 'application/json'
 http_response.headers['Content-Length'] = '1000'
 raise http_response
 return dict(files=files)

 In this case remote app will get only 1000 bytes of data so I want to know 
 what value should I set to respond with full range of data that file 
 contain?


-- 
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: 127.0.0.1 and ip address are not interchangeable, and Port 80 Error

2015-08-07 Thread Massimo Di Pierro
python web2py.py -i 0.0.0.0 -p 80

will use any IP address you have and port 80. Your OS may block port 80 so 
be careful.

On Thursday, 6 August 2015 21:57:27 UTC-5, Zhihong Zeng wrote:

 Hello,

 I just start using web2py, and get the following questions: 

 1) Based on my experience on apache, localhost, 127.0.0..1 and local ip 
 address obtained by ifconfig in linux are interchangeable. So I can use ip 
 address to visit my web page running in a remote computer in the same 
 network. 
 But when I run web2py, visiting localhost and 127.0.0.1 are successful but 
 not local ip address.

 2) if I use 80 port on web2py server, I get error: Rocket.Error.Port80

 I would appreciate any answers to my questions.

 Zhihong


-- 
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] CSV save on Server

2015-08-07 Thread forumweb2py
He group, 

i create serial letters with web2py and pdfLatex. It works fine with a 
static csv-file in private folder. 
But i want to create the csv and save directly to the folder. No Download!

I create the csv ... no Problem:

@auth.requires_login()
def create_csv():
from gluon.contenttype import contenttype
import os
response.headers['Content-Type'] = contenttype('.csv')
response.headers['Content-disposition'] = 'attachment; 
filename=%s_database.csv' % (
request.now
)
import csv, cStringIO
s = cStringIO.StringIO()
db((db.grunddaten.id0)).select().export_to_csv_file(s, delimiter=',', 
quotechar='', quoting=csv.QUOTE_NONNUMERIC)
return s.getvalue()

But how can i save this file directly on my folder?

-- 
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: avoid controller to sanitize html

2015-08-07 Thread Anthony
On Friday, August 7, 2015 at 12:18:12 PM UTC-4, Luis Valladares wrote:

 Thanks Anthony! using the option helper and returning without the 
 dictionary solved my issue, there is other errors on the javascript but i 
 already solved it, now works well, one more question: There is no built-in 
 function that creates a dropdown list from a DAL select?


No, but you can do:

SELECT([OPTION('', _value='')] +
   [OPTION(r.nombre, _value=r.id) for r in
db(db.municipios.estado == request.args(0)).select()]) 

Wouldn't be hard to write a function to encapsulate that (pass in a DAL Set 
and the names of the fields to use in each OPTION).

Note, the first OPTION is just there in case you want an empty slot at the 
top of the dropdown.

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] sessions in cookies

2015-08-07 Thread ermolaev . icreator


 To *store sessions in cookies* instead you can do:

 session.connect(request,response,cookie_key='yoursecret',compression_level=None)


I do that - but folders continue to created in app/sessions 

-- 
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: avoid controller to sanitize html

2015-08-07 Thread Anthony
If your function returns a dictionary, web2py assumes you want to execute a 
view. If you haven't created a view, it will use generic.html (by default, 
this only works for local requests). If you just want to return the raw 
HTML generated in the controller without then executing a view, then just 
return the HTML (i.e., no dictionary).

Additionally, you might want to consider building the HTML using the web2py 
HTML helpers rather than building it via strings. In that case, you can 
just return the final HTML helper, and it will automatically be converted 
to an HTML string before returning to the browser.

If you do actually have a view that is being executed and you want to 
insert raw HTML, you would wrap it in XML() (though, again, you could 
instead just use the web2py HTML helpers and not bother with XML()).

Anthony

On Friday, August 7, 2015 at 11:50:47 AM UTC-4, Luis Valladares wrote:

 Hello!

 I've a form where i store country, state and municipality and i need to 
 dynamcally change the value based on the select, i mean: If i select a X 
 country i need to display only the states of the country X in the states 
 dropdown, the same with municipality

 I used a basic approach that i've used many times befores in other 
 languages, a jquery function on dropdown change that ajax call a page and 
 it returns the options and put it into the dropdown, i've been researching 
 and found this really helpful: 
 http://stackoverflow.com/questions/10387672/web2py-dropdown-menu, so 
 based on this answer i build this structure:

 On the controller: 

 def ajaxMunicipio():
 if request.args(0) in db.estados.id:
 response.generic_patterns = ['load']
 data = db(db.municipios.estado == request.args(0)).select()
 html = \select\
 for fila in data:
 html += \option value=\+str(fila.id
 )+\\+fila.nombre+\/option\
 html += \/select\
 return dict(form=html)
 else:
 raise HTTP(404)





 And on the view:

   jQuery(function() {
 jQuery('#no_table_estado_id').change(function() {
   var request = $.ajax({
 url: {{=URL('hot', 'ajaxMunicipio.load')}} + / + 
 jQuery(this).val(),
 method: GET,
 dataType: html
 });
   request.done(function(html) {
 console.log(html)
 $(#no_table_municipio_id).val(html);
   });
 })
   })



 everything works well on the call side but i recieve the HTML sanitized 
 like this: \lt;select\gt;\lt;option 
 value=quot;1quot;\gt;LIBERTADOR\lt;/option\gt;\lt;/select\gt;

 So i'm looking for a way to avoid web2py to sanitize the html, or maybe a 
 cleanest way to do this because i dont really like looping the data in the 
 controller in order to create the HTML

 I appreciate any help you can give! Thanks for your atention




-- 
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: CSV save on Server

2015-08-07 Thread forumweb2py
Ok, i change the code but i get an error:

@auth.requires_login()
def create_csv():
from gluon.contenttype import contenttype
import os
response.headers['Content-
Type'] = contenttype('.csv')
response.headers['Content-disposition'] = 'attachment; 
filename=%s_database.csv' % (
request.now
)
import csv
s=open('mycsvfile.csv','wb')write(str(db(mydb.mytable.id).select()))
db((db.grunddaten.id0)).select().export_to_csv_file(s, delimiter=',', 
quotechar='', quoting=csv.QUOTE_NONNUMERIC)
s.close()

TicketFile: type 'exceptions.TypeError argument 1 must have a write method


Am Freitag, 7. August 2015 20:39:32 UTC+2 schrieb forum...@gmail.com:

 He group, 

 i create serial letters with web2py and pdfLatex. It works fine with a 
 static csv-file in private folder. 
 But i want to create the csv and save directly to the folder. No Download!

 I create the csv ... no Problem:

 @auth.requires_login()
 def create_csv():
 from gluon.contenttype import contenttype
 import os
 response.headers['Content-Type'] = contenttype('.csv')
 response.headers['Content-disposition'] = 'attachment; 
 filename=%s_database.csv' % (
 request.now
 )
 import csv, cStringIO
 s = cStringIO.StringIO()
 db((db.grunddaten.id0)).select().export_to_csv_file(s, 
 delimiter=',', quotechar='', quoting=csv.QUOTE_NONNUMERIC)
 return s.getvalue()

 But how can i save this file directly on my folder?



-- 
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: CSV save on Server

2015-08-07 Thread Anthony
See 
http://web2py.com/books/default/chapter/29/06/the-database-abstraction-layer#CSV--one-Table-at-a-time-.
 
No need for StringIO -- just create an open file and pass it to the export 
method (then close the file).

Anthony

On Friday, August 7, 2015 at 2:39:32 PM UTC-4, forumweb...@gmail.com wrote:

 He group, 

 i create serial letters with web2py and pdfLatex. It works fine with a 
 static csv-file in private folder. 
 But i want to create the csv and save directly to the folder. No Download!

 I create the csv ... no Problem:

 @auth.requires_login()
 def create_csv():
 from gluon.contenttype import contenttype
 import os
 response.headers['Content-Type'] = contenttype('.csv')
 response.headers['Content-disposition'] = 'attachment; 
 filename=%s_database.csv' % (
 request.now
 )
 import csv, cStringIO
 s = cStringIO.StringIO()
 db((db.grunddaten.id0)).select().export_to_csv_file(s, 
 delimiter=',', quotechar='', quoting=csv.QUOTE_NONNUMERIC)
 return s.getvalue()

 But how can i save this file directly on my folder?



-- 
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: CSV save on Server

2015-08-07 Thread forumweb2py
Oh right, the point was the point ...
now it works fine with: 

open('test.csv', 'wb').write(str(db(db.person.id).select()))

thanks a lot


Am Freitag, 7. August 2015 20:39:32 UTC+2 schrieb forum...@gmail.com:

 He group, 

 i create serial letters with web2py and pdfLatex. It works fine with a 
 static csv-file in private folder. 
 But i want to create the csv and save directly to the folder. No Download!

 I create the csv ... no Problem:

 @auth.requires_login()
 def create_csv():
 from gluon.contenttype import contenttype
 import os
 response.headers['Content-Type'] = contenttype('.csv')
 response.headers['Content-disposition'] = 'attachment; 
 filename=%s_database.csv' % (
 request.now
 )
 import csv, cStringIO
 s = cStringIO.StringIO()
 db((db.grunddaten.id0)).select().export_to_csv_file(s, 
 delimiter=',', quotechar='', quoting=csv.QUOTE_NONNUMERIC)
 return s.getvalue()

 But how can i save this file directly on my folder?



-- 
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: 2.12.1 is out

2015-08-07 Thread ermolaev . icreator
pickled.HIGHPROTOCOL - fixed?

-- 
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 response Content-Length parameter by file size

2015-08-07 Thread Alehandro Ramoz Rodrigez
Should it looks like 

http_response.headers['Content-Length'] = int(request.env.content_length)

?

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