[web2py] auth_ tables problem
I have one application (called base) in which I define all the tables for three other applications. In the three applications I use the same db.py file. In these db.py files I set migrate=False on all tables. One of these applications is a CMS, in which I enabled Authorization and Authentication. This creates the .table files for auth_event, auth- group, auth_membership, auth_permission and auth_user in the databases folder of the cms application, all the .table files for the other tables are in the databases folder of the base application. When I extend the model in the base application's db.py file, i.e. define new tables, and set migrate=False on these tables and copy and paste them into the db.py file of the CMS application, after saving the db.py file, I keep getting the following error when I go to the database administration: ProgrammingError: relation "auth_user" already exists Am I right to conclude that I cannot make changes to the db.py file in which Authorization and Authentication are enabled? i.e. I can only save the db.py file once? Did anyone face the same problem? How did you solve it? Is there a best practice to dealing with db.py when it comes to defining and altering tables and using web2py's authentication and authorization features? Kind regards, Annet.
[web2py] Re: auth_ tables problem
Thanks for your reply, > have you tried: > # defines all needed tables without migration/table files > auth.define_tables(migrate=False) > > where you configure auth for your app? I didn't now I could set migrate=False on the auth_ tables, this isn't documented anywhere, is it? I did indeed solve my problem. Kind regards, Annet.
[web2py] confirmation dialog on delete
The jQuery code for confirmation on delete connects the onclick event of the checkbox with a confirmation dialog. I would like this confirmation dialog to be triggered by the submit button. Is it possible to re-write the code in web2py_ajax.html: jQuery("input[type='checkbox'].delete").click(function() { if (this.checked) if(!confirm("{{=T('Sure you want to delete this object?')}}")) this.checked=false; }); ... so that the code connects to the onclick event of the submit and not the onclick event of the checkbox? Kind regards, Annet.
[web2py] Re: auth_ tables problem
Hi, > I don´t know if understood your problem right but looks like you are > using sqlite. I am using PostgreSQL 8.4. > If that´s the case I guess it would be better and safer for you to use > another relational database such as mysql. > I think the problem could be you don´t have a db server. Kind regards, Annet.
[web2py] Re: verify email limitations
Maybe this post: http://groups.google.com/group/web2py/browse_thread/thread/420e0001e3c8949c/32a262d1c39cdb02?lnk=gst&q=Mar+24#32a262d1c39cdb02 Annet.
[web2py] email form into database table.
In an application I have forms which on submit are mailed to my mail box. After verification I manually insert the form data into their respective tables, e.g. for an application form into the tables: company, address, nfa, and contact. Since this is a rather time consuming task I thought of inserting the form data into a form_table and retrieving them into a four part form (one for every table), and after verification submitting each form and on form acceptance insert the data into the individual tables. I wonder whether there is the right way to proceed or whether there is a better way to execute this task. Kind regards, Annet.
[web2py] Re: email form into database table.
Massimo, > You can insert them and have a flag (Field) called appreoved which > default to false. Than you can send yourself an email with a link to a > page so that by just clicking on the link you approve it. I implemented this and gave it a try, just what I was looking for. Thanks. Kind regards, Annet.
[web2py] Re: Data table
Hi Sverre, I am using Allan Jardine's DataTables: http://www.datatables.net/ Regards, Annet.
[web2py] Multiple apps based on one model.
I read this post in the group: http://groups.google.com/group/web2py/browse_thread/thread/6201f9f56bdb16d6, and I am facing a similar problem. I have one web2py installation in which I have a base application which contains all shared files i.e .js and .css files. Within this application I also defined all database tables, so all .table files are in the databases folder of this application. Furthermore this web2py installation contains an init application and b2c, b2b, crm applications. The db.py files of these applications are copies of the db.py of the base application with all migrates set to False. From the post mentioned above I understand I can make a function of the base app's db.py, name it db_stuff.py and put it in the base application's modules file: /web2py/applications/base/modules/db_stuff.py My first question is: how do I make a function of a db.py file, and which parts of the db.py file should the function contain? Then, I should write an import statement in each of the applications db.py files: local_import('db_stuff',app='base') My second question is: what code do these db.py files contain apart from the import statement? Kind regards, Annet.
[web2py] Re: question about webfactional
Pai, The solution to your problem is described in this thread: http://groups.google.com/group/web2py/browse_thread/thread/504dd2deff41f8f4/156e920088c11b85#156e920088c11b85 Basically you have to log on to webfaction via terminal/ssh and manually create a directory in your remote web2py/applications directory. You can then upload and install a packed web2py app via the web interface. Kind regards, Annet.
[web2py] Re: Data table
Hi Sverre, Here's an example of how you would make the id a link: company id company name {{for company in rows:}} {{=A(company.id,_onmouseover="this.style.cursor='pointer';", \ _onclick="javascript:clublocatordetails('%s')"%URL(r=request,f='details',args=[company.id]))}} {{=company.name}} {{pass}} Here the link opens a details view in a new window, but that's optional. Regards, Annet.
[web2py] _onclick to close window
In custom_ajax.html I defined the following function: function closeWin() { window.close(); return false; } I a function I added a cancel button to a form: This one works: form[0][-1] [1].append(INPUT(_type='button',_value='Cancel',_onclick='javascript:history.go(-1)')) This one doesn't: form[0][-1] [1].append(INPUT(_type='button',_value='Cancel',_onclick='javascript:closeWin()')) Does one of you know why not? Kind regards, Annet.
[web2py] design issue
I have multiple applications connecting to the same database, some of them query the database for data on multiple companies others query the database for data on one company, apart from a company table containing the company id there is no overlap. I know web2py can connect to multiple databases, and I wonder whether it would be possible to have two db.py files: db1.py and db2.py, where db1.py connects to the database containing the first type of data and db2.py connects to the company's database. db2.py would also contain the auth_ tables. I hope some of you are willing to comment on this idea. Kind regards, Annet.
[web2py] Re: design issue
Hi, Thank you very much for your extensive reply, it's very helpful, at least I now have an idea of how to approach this problem. Kind regards, Annet
[web2py] expire_sessions.py and cron
To clean up sessions I ran the following command: me:~ i$ cd /Library/Python/2.5/site-packages/web2py me:web2py i$ cp applications/admin/cron/crontab applications/init/cron me:web2py i$ The crontab file in the init app now reads like: 10 * * * * root **applications/admin/cron/expire_sessions.py I wonder whether this is correct and whether this a local setting or works on the server as well. Kind regards, Annet.
[web2py] Re: expire_sessions.py and cron
Massimo, At webfaction I can do: [myser...@webxxx ~]$ crontab -l 11,31,51 * * * * /home/fitwise/webapps/customweb2py/apache2/bin/start > /dev/null 2>&1 12,32,52 * * * * /home/fitwise/webapps/customweb2py/apache2/bin/start > /dev/null 2>&1 46 * * * * cd ~/webapps/loganalyzer;./update_awstats.sh [myser...@webxxx ~]$ ... and I can edit this file: crontab -e I posted a ticket: Will running the crontab -e command and adding this line: 10 * * * * root **applications/admin/cron/ expire_sessions.py , solve my problem? What's with the 10, and the 'root ** applications' bit, are they specific to my local system, or will they work remotely as well. ... to which I got the following reply: Yes, I bee that the "root **" part is specific to your local cron setup. I would suggest that you try to figure out which command exactly do you need to run through the command line, in order to clear the sessions. If the script is directly executable via the command line, then you should add the command that you are executing it with to your crontab. If it is accessible via web, you could add something like 'wget http://yourdomain.com/url/of/script' to your crontab, in order to trigger a web request to the script. I hope this helps you help me solve the problem, Annet.
[web2py] Re: Need help with datatable
Hi Sverre, I have a cms application in which I use dataTables. In the view I have something like: {{=A('update/delete',_onmouseover="this.style.cursor='pointer';", _href=URL(r=request,f='update_nfa',args=[record.nfa.id]))}} ... and in the corresponding function: auth.requires_membership('site_manager') def update_nfa(): response.view='default/update_form.html' record=db.nfa[request.args[0]] if not record or not record.company==auth.user.company: redirect(URL(r=request,f='crud_nfa')) form=update_form(db.nfa,record,'crud_nfa',message='Nfa updated',deletable=True) return dict(form=form) ... where update_form(...) is a function that performs the actual update: def update_form(table,record,next,message,deletable): form=crud.update(table,record,next=(URL(r=request,f=next)),message=message,deletable=deletable) form[0][-1] [1].append(INPUT(_type="button",_value="Cancel",_onclick="javascript:history.go(-1)")) return form I hope you get the idea. Kind regards, Annet.
[web2py] Re: expire_sessions.py and cron
Massimo, Emil just tried running the following command on my account: python2.5 /home/fitwise/webapps/customweb2py/web2py/web2py.py -S admin -R applications/admin/cron/expire_sessions.py This was successfully executed, and the output was: web2py Enterprise Web Framework Created by Massimo Di Pierro, Copyright 2007-2010 Version 1.76.5 (2010-03-11 15:19:08) Database drivers available: SQLite3, MySQL, PostgreSQL I verified that this actually cleaned up my sessions. It did in admin, not in init, b2b etc. Would it be possible to copy the expire_sessions.py to every single application's cron directory and set this command as a cron by editing my crontab (crontab -e): 10 * * * * /usr/local/bin/python2.5 /home/fitwise/webapps/customweb2py/ web2py/web2py.py -S init -R applications/init/cron/expire_sessions.py According to Emil: Applications do not really have crontabs. They may have some built-in feature which makes them work similar to crontab, but it is a completely separate system than your "real" crontab (the one you see when you runt 'crontab -l'). By the way, the Web2py installation that I have is running behind Apache + mod_wsgi. Kind regards, Annet.
[web2py] Re: CRUD read or OneToOne
> I want the user to click on the link and if there is already > a project _location for a project then just display it (crud.read), > if the project has no location associated, then it will give me > crud.write. I know it must be simple but I cant figure it out. I am not sure I do understand your problem correctly, but I'll give it a try. You list projects, when the user clicks on one of the projects, depending on the project's location being set or not you either display the project's details or display an update form @auth.requires_login() def update_project_location(): projects=db(..).select(..) form=[] if request.args: project_id=request.args(0) project=db.project[project_id] if project[0].location: form=crud.read(db.project,project_id) else: form=crud.update(db.project,project_id) return(projects=projects,form=form) I hope this helps to point you in right direction. Annet.
[web2py] Re: How to send an URL() from a view to a controller?
> I want to implement a function to back to previous page. Simply back to the previous page would be something like: {{=A('back',_onmouseover="this.style.cursor='pointer';",_onclick="javascript:history.go(-1);")}} I am not sure but doesn't this: from documents back to device and from documents back to workorder contradict this: from device or workorder view back to documents controller? Kind regards, Annet
[web2py] Re: expire_sessions.py and cron
Massimo, Thank you very much for providing me with this code, problem solved. Kind regards, Annet.
[web2py] Re: Drop Down alternative
Massimo, I gave this a try: from gluon.sqlhtml import AutocompleteWidget db.define_table('address', Field('city',length=42,default='',notnull=True)), ...) db.address.city.widget=AutocompleteWidget(request,db.city.name,db.city.name,orderby=db.city.name) but that doesn't work, why not? Kind regards, Annet.
[web2py] Authentication
I read chapter 8 of the web2py manual and some post on authentication to get started (again) implementing a cms. I read about MD5 and SHA-512, and understand I have to provide a secret key for this setting: auth.settings.hmac_key='' Does this key have a specific format, e.g. 448a98e0-00fd-46b2- ac4f-a14d2315b189? Or can I use any key? At the moment I am working in web2py 1.76.5 does this version already use hmac + sha-512? Furthermore I would like to customize the auth_user table. In the manual the proper way to define a user table is: auth_table = db.define_table(auth.settings.table_user_name, Field('first_name', length=128, default=''), Field('last_name', length=128, default=''), Field('email', length=128, default='', unique=True), Field('password', 'password', length=256, readable=False, label='Password'), Field('registration_key', length=128, default= '', writable=False, readable=False)) auth_table.first_name.requires = IS_NOT_EMPTY(error_message=auth.messages.is_empty) auth_table.last_name.requires = IS_NOT_EMPTY(error_message=auth.messages.is_empty) auth_table.password.requires = [IS_STRONG(), CRYPT()] auth_table.email.requires = [IS_EMAIL(error_message=auth.messages.invalid_email), IS_NOT_IN_DB(db, auth_table.email)] auth.settings.table_user = auth_table In a workgroup post of 8 February I read this definition: auth.settings.table_user = db.define_table('auth_user', Field('first_name', length=512,default=''), Field('last_name', length=512,default=''), Field('email', length=512,default='', requires = [IS_EMAIL(),IS_NOT_IN_DB(db,'auth_user.email')]), Field('password', 'password', readable=False, label='Password', requires=CRYPT(auth.settings.hmac_key)), Field('registration_key', length=512, writable=False, readable=False,default=''), Field('reset_password_key', length=512, writable=False, readable=False, default='')) What is the reset_password_key for? I guess I'd better use the latter table definition, don't I need any validators? Kind regards, Annet.
[web2py] Re: Drop Down alternative
Massimo, > Do you have a table db.city with a field db.city.name? Yes I do. > If so, because db.address.city is not a reference, it should just be > db.address.city.widget=AutocompleteWidget(request,db.city.name) Yes, now it works. This saves me a lot of work, implementing the pengoworks autocomplete every time I need an autocomplete field isn't this simple. However, the drop box displaying the options doesn't disappear after selecting a city name or typing the full name. Could that be fixed, it covers some other form fields. Kind regards, Annet.
[web2py] Re: Drop Down alternative
I had a quick look at the slice, am I right to conclude that contrary to the pengoworks autocomplete this one is more generic. When I use the Pengoworks autocomplete in my model I have to define: db.address.city.widget=lambda self,value:INPUT(_type='text',_id='city',_class='ac_input',_name='city',requires=self.requires) ... in web2py_ajax.html: jQuery('#city').autocomplete('/init/handlers/cityAC',{maxItemsToShow: 12}); ... in a controller called handlers: def cityAC(): q='' if request.vars: q=request.vars.q if not q: return q rows=db(db.city.name.like('%s% %'%q.capitalize())).select(db.city.name,orderby=db.city.name) r='' for row in rows: r='%s%s\n'%(r,row.name) return r ... and I have to repeat this for every field I need autocomplete functionality for. When I use the one described in the slice, I would put this in db.py: def autocomplete_widget(f,v): import uuid d_id = "autocomplete-" + str(uuid.uuid4())[:8] wrapper = DIV(_id=d_id) inp = SQLFORM.widgets.string.widget(f,v) rows = f._db(f._table['id']>0).select(f,distinct=True) itms = [str(t[f.name]) for t in rows] scr = SCRIPT('var data= "%s".split("|");jQuery("#%s input").autocomplete(data);' % \ ("|".join(itms),d_id)) wrapper.append(inp) wrapper.append(scr) return wrapper ... which would work both on my laptop and on the webfaction servers!? ... put this in the handlers controller: def get_items(): itms = [] if request.vars.q and \ request.vars.table and \ request.vars.field: q = request.vars.q f = request.vars.field t = request.vars.table fld = db[t][f] rows = db(fld.upper().like(q.upper() +"%")).select(fld,distinct=True) itms = [str(t[f]) for t in rows] return '\n'.join(itms) ... and put this in the table definition: db.address.city.widget=autocomplete_widget Is that right? Kind regards, Annet.
[web2py] auth problem
I enabled authentication and have the following entries in the auth_user, auth_group and auth_membership tables: user.iduser.first_name ... 1 Ann 2 Jan group.idgroup.role 1 user_1 2 user_2 membership.idmembership.user_idmembership.group.id 1 1 user_1(1) 2 2 user_2(2) Now, I would like to add permissions, the problem is that auth.add_persmission() takes the following arguments: group_id, 'name', 'object', record_id whereas I need to set permissions related to a tables company_id field. I have tables that have the following structure: db.define_table('tagline', Field('company_id',db.bedrijf,default='',notnull=True,ondelete='CASCADE'), Field('line',length=84,default='',notnull=True), migrate=’tagline.table’) Now user with user_id 1 and group_id user_1(1) should get the permission to create, update and delete all records in the tagline table that have company_id 443. Is that possible in web2py's, or do I have to customize one of the auth tables to make this possible? Kind regards, Annet.
[web2py] Re: expire_sessions.py and cron
Hi, > @Annet: > Sorry, but what do you mean "emil"? Emil works at WebFaction, where I host my application in a Shared 1 plan. Using web2py's crontab doesn't work at WebFaction, I have to use my 'real' crontab to clean up sessions in my web2py applications. Hence Massimo's re-write of the expire_session.py file, and this line in my 'real' crontab: 10 * * * * /usr/local/bin/python2.5 /home/fitwise/webapps/ customweb2py/ web2py/web2py.py -S init -R applications/init/cron/ expire_sessions.py Kind regards, Annet.
[web2py] Re: auth problem
Massimo, I have a table company, which contains 2000+ company's. Visitors can search for a company and in the query result click the company name, which directs to a details function displaying the company's address and nfa's. Some company managers would like to add a tagline to this details view. So, I added the tagline table to the model: db.define_table('tagline', Field('company_id',db.company,default='',notnull=True,ondelete='CASCADE'), Field('line',length=84,default='',notnull=True), migrate=’tagline.table’) Now, when a manager registers, he should get permission to create,update and delete a tagline for his company. One solution would be to customize the auth_user table and add a field company: auth.settings.table_user=db.define_table('auth_user', Field('company', db.company, default='', notnull=True,ondelete='CASCADE', writable=False, readable=False), ...)) In this case I could define a function update_tagline: def update_tagline(): record=db(db.tagline.company_id==auth.user.company_id).select(db.tagline.id) record_id=record[0].id form=crud.update(db.tagline,record_id,next=(URL(r=request,f='index')),message='',deletable=True) return dict(form=form) This works, however, in my opinion, it interferes too much with web2py's authentication and authorization workflow. Therefore, I had hoped there would be another solution. Like linking user and company in the permissions table, instead of the user table. Kind regards, Annet.
[web2py] Re: Drop Down alternative
I gave this a try, but what about standardization tables, where I need the name instead of the id in the referencing table. In web2py's autocomplete I just do: db.address.city.widget=AutocompleteWidget(request,db.city.name) How would I go about to get this to work in this jquery autocomplete plugin? Kind regards, Annet.
[web2py] Re: Maybe Off-Topic: I am very happy thanks to web2py :)
To give you an idea, I am reading a bachelor in computer science at OUNL, a view years ago my friend had this idea for a web application, and I decided to set out to develop it. For a long time I felt I had ended up in a quest, where every one knew how to acquire secret weapons and knew where the secret doors were, except me. Almost two years ago I discovered my secret door: web2py. So yes, +1 and thanks to all developers and the group and their support to get me started with web2py, and make web development a joy instead of an annoyance. Annet.
[web2py] Re: A mistake and crashed T3 appadmin from default/configure/models - No solution by now
Hi, I have had these moments to. Luckily I work on a Mac, which comes with Time Machine. Time Machine enables me to recover web2py applications easily. Furthermore, I save myself a lot of hassle by packing apps that are more or less working versions of an application and saving them outside web2py in a packedApps folder. Within web2py it did help me to have multiple db.py files: db.py, db_00_auth.py, db_01_tables.py etc. I also try to keep my applications small, e.g. I have a b2c, b2b, cms, crm and demo application, instead of an init application containing a b2c, b2b etc controller. I have been searching for these kind of best practices myself, in order to make developing and maintaining applications easier, up til now it's been a matter of trial and error. Kind regards, Annet.
[web2py] Re: Drop Down alternative
> Sorry, I don't understand. In get_items, request.vars.field and > request.vars.table contain the field and table names of the requesting > autocompleter. Is that what you mean? Yes, thank you, now I understand. Annet
[web2py] crud problem
I defined the following function: @auth.requires_login() def index(): response.functionname='Basic account' record=db(db.tagline.company_id==auth.user.company_id).select().first() if record: response.init_flash='Update tagline' form=crud.update(db.tagline,record,message='Tagline updated') else: response.init_flash='Insert tagline' db.tagline.company_id.default=auth.user.company_id form=crud.create(db.tagline,message='Tagline inserted') return dict(form=form) When there is no tagline I get the create form and when I submit the form the Tagline inserted flash is displayed, however, the tagline field is empty, 1) whereas I expected it to contain the inserted tagline. When I refresh the page I get the update form and the flash says: Update tagline. When I update the tagline and submit the change the Tagline updated flash displays. Which is correct. When I check the 'check to delete' box, the alert displays, after clicking OK and clicking submit, 2) the Tagline updated flash displays and the tagline field still contains the tagline and the check box is still checked. When I click submit again the tagline is being deleted and the Insert tagline flash displays, 3) whereas I would like a flash telling the user that the tagline has been deleted. How do I solve these three problems? Kind regards, Annet.
[web2py] Re: crud problem
Massimo, Thanks for pointing me in the right direction, I had to add the next argument to the crud.update() function to get the check to delete work properly. There's one small problem to solve, when the user logs in the flash reads: Logged in. Whereas, I would like it to read 'Insert tagline' or 'Update tagline'. The function: @auth.requires_login() def index(): response.functionname='Basic account' record=db(db.tagline.bedrijf_id==auth.user.bedrijf_id).select().first() if record: if not response.init_flash: response.init_flash='Update tagline' message='Tagline updated' else: if not response.init_flash: response.init_flash='Insert tagline' message='Tagline inserted' db.tagline.bedrijf_id.default=auth.user.bedrijf_id form=crud.update(db.tagline,record,next=(URL(r=request,f='index')),message=message) return dict(form=form) The view: {{if response.functionname:}} {{=response.functionname}} {{pass}} {{if response.flash:}} {{=response.flash}} {{else:}} {{=response.init_flash}} {{pass}} {{if form:}} {{=form}} {{pass}} Kind regards, Annet.
[web2py] Re: auth.login problem - redirect on error
Hi Arnaud, Why don't you use default/user/login and set auth.settings.login_next=URL(a='helloworld',c='admin',f='index'), in that case, when login fails there is no need to redirect. When you need a custom Invalid login message just set: auth.messages.invalid_login='your customized message' Kind regards, Annet.
[web2py] crud question on multiple form layout
I have the following layout: .header. .1. .2. .3. .footer. I my database header, .1, .2 , .3 and footer are fields of type text and in web2py_ajax.html I enabled tinyMCE on textareas. I would like to make an administrative view in which all five divs are links to forms in which a user can perform crud actions on the textareas and in return see the result of their actions. The problem is I have no idea of how to implement this in web2py. I hope someone could point me in the right direction. Kind regards, Annet.
[web2py] uploads problem
In web2py I have a cms application and an init application. In the cms application I have a function in which users can upload images for a view which contains four images, the problem is that this view is in the init application not in the cms application, whereas the images end up in the uploads folder of the cms application. Is there a way to upload the in the cms application into the uploads folder of the init application. Furthermore I would like to let every user have his own subfolder in the uploads folder, is that possible? If so, how would I implement that? Kind regards, Annet.
[web2py] Re: uploads problem
Massimo, > if field is the upload field you can set > > db.table.field.uploadfolder = This is my image table: db.define_table('image', Field('company_id',db.company,default='',notnull=True,ondelete='CASCADE',writable=False,readable=False), Field('image_filename',writable=False,readable=False), Field('file',type='upload',default='',notnull=True,autodelete=True), Field('positie',default='',notnull=True), Field('posted_on',type='datetime',writable=False,readable=False), Field('modified_on',type='datetime',writable=False,readable=False), migrate=False) >From your reply I understand that in the function in which the user can update images I could do: def update_image(): record=db((db.image.company_id==auth.user.company_id)&(db.image.positie==request.args[0])).select().first() db.image.file.uploadfolder=os.path.join(request.folder,"uploads/%i" % auth.user.company_id) form=crud.update(db.image,record,next=(URL(r=request,f='index')),message=message) return dict(form=form) Does the folder have to exist already or will it be made when a folder named company_company_id doesn't exist? > User A uploads and image into pathA. If user B wants to > download the image posted by user A, web2py will search for it in > pathB. This won't be a problem, since user A cannot download user B's images and vice versa. Kind regards, Annet.
[web2py] Re: uploads problem
The update_image(): function resides here: .../cms/homepage/update_image where cms is the application. Whereas I would like the image to be uploaded to this folder: .../init/uploads/company_xxx where init is the application How do I have to adjust this line of code to get it to work. db.image.file.uploadfolder=os.path.join(request.folder,"uploads/%i" % auth.user.company_id) To append the company_id to company_ what is the best way: "uploads/ company_%i" % auth.user.company_id or "uploads/%i" % "company_" + auth.user.company_id I realize I could also upload the images to the .../cms/uploads/ company_xxx folder and then change the downloads function in the .../ init/homepage/ controller to download the images from the cms/uploads/ company_xxx folder, is this a better way to proceed? Kind regards, Annet.
[web2py] resize window after redirect.
I have the following code in a view: {{=A(club.companyname,_onmouseover="this.style.cursor='pointer';",\ _onclick="javascript:clublocatordetails('%s')"%URL(r=request,f='details',args=[club.id]))}} The javascript clublocatordetails function (in web2py_ajax.html) resizes the window. I extended the details function: def details(): if not club: redirect(URL(r=request,c='default',f='error')) elif club[0].status=='2': redirect(URL(r=request,f='homepage',args=id)) return dict(...) When a club has status 2 there is a redirect to a different function, since this function's view is larger I would like to resize the browser window. The problem is I don't know how to code this and where the code should go, I hope one of you knows how to solve this problem. Kind regards, Annet.
[web2py] combining requirements
I have a custom auth table which contains a field 'account'. Once a user is logged in, would it be possible to decorate a function the following way: @auth.requires(auth.user.account=='3') def update_xxx(): return(form=form) In the web2py manual I read that it is possible combine requirements. If the above decorator works, would it be possible to combine a requirement the following way: @auth.requires(auth.user.account=='3' or auth.user.account=='2') def update_xxx(): return(form=form) Kind regards, Annet.
[web2py] Re: combining requirements
Massimo, > Yes but Great, this makes it possible to code my cms more generic. Kind regards, Annet.
[web2py] Re: combining requirements
In default.py I adjusted the def user() function: def user(): form=auth() form[0][-1] [1].append(INPUT(_type="button",_value="Cancel",_onclick="window.location='%s';"%URL(r=request,f='index'))) return dict(form=form) Now, when an unauthorized user tries to access a function decorated as described above, there is a redirection to this function: http://127.0.0.1:8000/cms/default/user/not_authorized However, due to rewriting the user function, this results in the following error: Traceback (most recent call last): File "/Library/Python/2.5/site-packages/web2py/gluon/restricted.py", line 173, in restricted exec ccode in environment File "/Library/Python/2.5/site-packages/web2py/applications/cms/ controllers/default.py", line 73, in File "/Library/Python/2.5/site-packages/web2py/gluon/globals.py", line 96, in self._caller = lambda f: f() File "/Library/Python/2.5/site-packages/web2py/applications/cms/ controllers/default.py", line 30, in user form[0][-1] [1].append(INPUT(_type="button",_value="Cancel",_onclick="window.location='%s';"%URL(r=request,f='index'))) IndexError: string index out of range is there a way to prevent this from happening? Kind regards, Annet.
[web2py] empty field crud.update(db.table)
I am using the Pengoworks auto complete plugin. In my model file I have: db.address.city.widget=lambda self,value:INPUT(_type='text',_id='city',_class='ac_input',_name='city_name',requires=self.requires) In web2py_ajax.html: jQuery('#city').autocomplete('/cms/handlers/cityAC',{maxItemsToShow: 12}); In a handlers controller: def cityAC(): q='' if request.vars: q=request.vars.q if not q: return q rows=db(db.city.name.like('%s% %'%q.capitalize())).select(db.city.name,orderby=db.city.name) r='' for row in rows: r='%s%s\n'%(r,row.name) return r The auto complete works in empty forms, however, when I use crud.update(db.address,...) the city field is empty, whereas the database record contains a value for city. I guess I have to adjust the cityAC() function, but I don't know how... Kind regards, Annet.
[web2py] cancel button in update and create work differently
I have a function to update opening hours: @auth.requires_membership('homepage_manager') def update_openinghours(): openinghours=db(db.openinghours.company_id==auth.user.company_id)\ .select(db.openinghours.ALL) form=[] if not openinghours or request.vars.x: if not response.init_flash: response.init_flash='Insert opening hour' message='Opening hour inserted' form=create_form(db.openinghours,'update_openingshours',message=message) else: if not request.args: if not response.init_flash: response.init_flash='Opening hours in database' else: if not response.init_flash: response.init_flash='Update opening hour' message='Opening hour updated' form=update_form(db.openinghours,request.args[0],'update_openinghours', \ message=message,deletable=True) return dict(openinghours=openinghours,form=form) In the create_form and update_form functions I add a cancel button to the form which redirects to the current page: def create_form(table,next,message): form=crud.create(table=table,next=(URL(r=request,f=next)),message=message) form[0][-1][1].append(INPUT(_type="button",_value="Cancel",\ _onclick="window.location='%s';"%URL(r=request,f=next))) return form def update_form(table,record,next,message,deletable): form=crud.update(table=table,record=record,next=(URL(r=request,f=next)),message=message,deletable=deletable) form[0][-1][1].append(INPUT(_type="button",_value="Cancel",\ _onclick="window.location='%s';"%URL(r=request,f=next))) return form In the view I have a link "insert record": {{=A('Insert record',_onmouseover="this.style.cursor='pointer';",\ _href=URL(r=request,f='update_openinghours',vars={'x':1}))}} and the days are links: {{=A(record.dag,_onmouseover="this.style.cursor='pointer';",\ _href=URL(r=request,f='update_openinghours',args=[record.id]))}} The problem is everything works accept for the cancel button in the create_form, which results in an invalid function error when clicked. This I don't understand, while the url's of the cancel buttons in both the create_form and the update_form read the same, the cancel button in the update_form works, the form above the table containing the opening hours disappears and just the table is displayed. I hope one of you knows why this happens and how I can fix this problem. Kind regards, Annet.
[web2py] Re: uploads problem
In the cms application uploads folder I made this directory: company_443 In the function that contains the upload field I set: db.outerimage.image.uploadfolder=os.path.join(request.folder,"uploads/ company_%i" %auth.user.bedrijf_id) When I expose the function and upload an image it ends up in the ../ upload/company_443 directory. Which is the intended behaviour. In the init application's view in which I want to display the uploaded images, I set the image's src attribute to: {{=IMG(_src=URL(r=request,a='cms',c='default',f='download/company_' + str(club[0].id), args=image_1[0].image))}} When I expose the related function the scr attribute reads like: http:///[app]/default/download/[filename] """ return response.download(request,db) Kind regards, Annet.
[web2py] Re: crud question on multiple form layout [closed]
After a lot of trial and error I figured out how to implement this, so subject closed. On May 24, 6:45 pm, annet wrote: > I have the following layout: > > > > .header. > > > > .1. > > > .2. > > > .3. > > > .footer. > > > I my database header, .1, .2 , .3 and footer are fields of type text > and in web2py_ajax.html I enabled tinyMCE on textareas. > > I would like to make an administrative view in which all five divs are > links to forms in which a user can perform crud actions on the > textareas and in return see the result of their actions. The problem > is I have no idea of how to implement this in web2py. I hope someone > could point me in the right direction. > > Kind regards, > > Annet.
[web2py] Re: crud problem [closed]
> You can try replace > > if not response.init_flash: response.init_flash='Insert tagline' > > with > > response.init_flash='Insert tagline' That solved the problem, thanks. Annet.
[web2py] Re: cancel button in update and create work differently [closed]
Setting the cancel button to: form[0][-1] [1].append(INPUT(_type="button",_value="Cancel",_onclick='javascript:history.go(-1);')) at least gives the user a way to cancel the function, not the way I wanted it, but it's better than getting an error. Annet
[web2py] Re: cancel button in update and create work differently [closed]
Yes, you're right, I hadn't thought of that. Thanks for providing me with a better solution. Kind regards, Annet.
[web2py] placeholder instead of image preview
I have the following function: db.define_table('image', Field('company_id',db.company), Field('filename',writable=False,readable=False), Field('file',type='upload',default='',notnull=True,autodelete=True), migrate=False) The problem is that crud.update shows a placeholder for the image instead of a preview of the image. Safari's inspect element shows the following src attribute: scr="/cms/default/download/image.file.b4d69...jpg" Why isn't the image being displayed? Kind regards, Annet. System: Mac OS X 10.5.8 Python 2.5 Web2py 1.76.5
[web2py] Re: Frivolous request for login/logout
It's probably not the most elegant of solutions, but in db.py I simply set: if auth.is_logged_in(): auth.messages.logged_in='Logged in successfully, welcome ' + auth.user.first_name + ' ' + auth.user.last_name auth.messages.logged_out='Logged out successfully, until next time ' + auth.user.first_name + ' ' + auth.user.last_name Kind regards, Annet.
[web2py] Re: Frivolous request for login/logout
> This's not working !! you need to set the message before actually logged in !! Why is that? I welcome a user who logs in so setting auth.messages.logged_in works. When does auth.user provide you with values for first_name and last_name in your solution? Before logging in? > your solution just set the message after user is actually logged in so > it's useless Cheers! > moreover, setting the logout message will not work, unless the index > page itself has no flash message set or else the flash message in > index age will override yours In my case (with login_next and logout_url set) both the login message and the logout message works, so who are you to tell me that it doesn't work. As I said: > It's probably not the most elegant of solutions, but in db.py I simply > set: Kind regards, Annet.
[web2py] call javascript function from within controller
I have the following code in a view: {{=A(club.companyname,_onmouseover="this.style.cursor='pointer';",\ _onclick="javascript:clublocatordetails('%s')"%URL(r=request,f='details',args=[club.id]))}} The javascript clublocatordetails function (in web2py_ajax.html) re sizes the window. I extended the details function: def details(): if not club: redirect(URL(r=request,c='default',f='error')) elif club[0].status=='2': redirect(URL(r=request,f='homepage',args=id)) return dict(...) When a club has status 2 there is a redirect to a different function, since this function's view is larger I would like to resize the browser window. Would it be possible to define a second javascript function that re- sizes the window to the desired height and width and call that function in the redirect somehow? Kind regards, Annet.
[web2py] Re: html5 test
Safari 4.0.5 : 115 0ut of 160 Failing on: Geolocation, Forms and User interaction. Annet.
[web2py] form[0] insert
I am using this: form[0].insert(21,TR(H4('Text'))) to insert headers between rows. The header is being inserted in the first column of the form. I would like to insert an explanatory text into the second column of a particular row, is that possible using this syntax, if so, what is the correct syntax. Kind regards, Annet.
[web2py] Re: tables name in result
In your table definitions (in db.py) you could set a label on the fields: db.person.id.label='Person's ID' db.person.name.label='Person's Name' Kind regards, Annet.
[web2py] disable label
I have a form: form=SQLFORM(db.signup_auth) in which I don't want some of the labels to show, I tried: db.signup_auth.akkoord_incasso.label=None but that doesn't work, is there a way to disable labels on fields? Kind regards, Annet
[web2py] Re: form[0] insert
Massimo, Indeed it was easier to use form.element(...), thanks for providing me with this solution. Annet. On Jun 7, 8:13 pm, mdipierro wrote: > form[0] #table > form[0][21] # 22nd row > form[0][21][1] # second column of above row > form[0][21][1].insert(0,H4('Text')) > > but it should be easier to do > > form.element('input[name=xxx]').parent.insert(0,H4('Text')) > > where 'xxx' is the name of the field variable. > > On Jun 7, 4:24 am, annet wrote: > > > I am using this: > > > form[0].insert(21,TR(H4('Text'))) > > > to insert headers between rows. The header is being inserted in the > > first column of the form. I would like to insert an explanatory text > > into the second column of a particular row, is that possible using > > this syntax, if so, what is the correct syntax. > > > Kind regards, > > > Annet.
[web2py] tos download
In a view I have a link which should enable users to download the terms of service: {{=A('terms of service',_href=URL(r=request,c='static',f='cms/files/ tos_fitwise.pdf'))}} This opens the tos in the browser window, whereas I would like them to be downloaded into the downloads folder on the users computer. Is that possible from within web2py? Kind regards, Annet.
[web2py] Re: tos download
Massimo, I used: > {{=A('terms of service',_href=URL(r=request,c='static',f='cms/files/ > tos_fitwise.pdf',vars=dict(attachment=True)))}} and it works, so problem solved thanks. Annet.
[web2py] Re: disable label
Thanks for providing me with this solution, problem solved. I have another problem with this form. In the first column some of the field names are split up, like: Sub-dossiernumber * : Is there a way to solve this? Kind regards, Annet.
[web2py] Re: disable label [closed]
Setting: label { white-space: nowrap; } solved the problem, thanks for providing me with this solution. Annet.
[web2py] Re: tos download [closed]
Massimo, At the moment this is the only static file I serve, so web2py does all the work. Annet.
[web2py] Multiple domains one web2py installation.
I posted the following question at WebFaction: One of my customers asked me whether it would be possible to have his domain centralfit.nl reference a page within my web2py app. Is this simply a matter of adding the domain centralfit.nl to the Control Panel, and creating a website that references this single page, by entering a website name 'centralfit', selecting the subdomain www.centralfit.nl which corresponds to the website record and adding a site app where 'customweb2py' is the app and /init/homepage/index/443 is the URL in which 'init' is the application, 'homepage' is the controller, 'index' is the function and '443' is the argument. Or isn't it this simple? There reply reads as follows: If you do what you described, you would end up with your "customweb2py" app available through http://www.centralfit.nl/init/homepage/index/443; no page will be displayed at http://www.centralfit.nl though. You will definitely need a second application if you want http://www.centralfit.nl to show different pages than http://www.fitwise.nl I wonder whether this is a limitation of WebFaction or a limitation in general. I built an application that, based on a company_id, exposes a fully functional web application. If the customers domain cannot reference this application, this idea is useless. Is there a way to solve this problem? Kind regards, Annet.
[web2py] Multiple domains one web2py installation.
I posted the following question at WebFaction: One of my customers asked me whether it would be possible to have his domain centralfit.nl reference a page within my web2py app. Is this simply a matter of adding the domain centralfit.nl to the Control Panel, and creating a website that references this single page, by entering a website name 'centralfit', selecting the subdomain www.centralfit.nl which corresponds to the website record and adding a site app where 'customweb2py' is the app and /init/homepage/index/443 is the URL in which 'init' is the application, 'homepage' is the controller, 'index' is the function and '443' is the argument. Or isn't it this simple? There reply reads as follows: If you do what you described, you would end up with your "customweb2py" app available through http://www.centralfit.nl/init/homepage/index/443; no page will be displayed at http://www.centralfit.nl though. You will definitely need a second application if you want http://www.centralfit.nl to show different pages than http://www.fitwise.nl I wonder whether this is a limitation of WebFaction or a limitation in general. I built an application that, based on a company_id, exposes a fully functional web application. If the customers domain cannot reference this application, this idea is useless. Is there a way to solve this problem? Kind regards, Annet.
[web2py] Re: Multiple domains one web2py installation.
To add to the confusion: On my follow up question: So, I would need an installation of web2py for every customer who would like to have his domain reference a function within my application? And this also holds true, if I'd install an application for that customer within web2py? I received this reply: You would need a separate application for each separate domain name that you want to display a different page on, unless the same web2py application can serve different pages, based on the domain name that is used - and I am not aware of such a feature. You might want to check with the web2py developers whether it is possible to serve different pages based on the domain name that is used in the HTTP request. The separate application can be a full fledged web2py installation, or a redirect to the main URL (e.g.to http://www.centralfit.nl/init/homepage/index/443) , or an iframe page used to mask to actual URL, or a simple HTML copy of the page(s) your web2py installation generates, or anything that displays the content you want to see actually. I guess the feature mentioned is routes.py? The second part of the reply doesn't ring a bell at all, I hope one of you can tell me what is being explained here. Kind regards, Annet.
[web2py] Re: Multiple domains one web2py installation.
Hi Vasile, > please take a look if that is what you > needhttp://groups.google.com/group/web2py/browse_thread/thread/fac136d7e1... Thanks for pointing me in the right direction. I'll give it a try and let you know if it works. > - webfaction application is a different thing than a web2py application I know, I installed web2py using their custom install script and named the application customweb2py. The web2py applications are located in customweb2py/web2py/applications/ Do you know whether there is a limit to the number of applications you can have within web2py and routes.py. According to webfaction's support people you cannot install only one web2py application in an account, when I install a second web2py called secondweb2py, how do customweb2py and secondweb2py know about each others existence? Kind regards, Annet.
[web2py] error auth_user already exists
I altered something in the db.py file, the file contains the following custom auth_user table: auth.settings.table_user = db.define_table('auth_user', Field('first_name',length=24,default=''), Field('last_name',length=42,default=''), Field('bedrijf_id',db.bedrijf,default='',notnull=True,ondelete='CASCADE',writable=False, readable=False), Field('email',length=72,default='',notnull=True), Field('username',length=72,default='',notnull=True,writable=False,readable=False), Field('password',type='password',default='',notnull=True,readable=False), Field('account',length=2,default='99',notnull=True,writable=False,readable=False), Field('registration_key',length=512,default='',writable=False, readable=False), Field('reset_password_key',length=512,default='',writable=False, readable=False)) auth.define_tables(fake_migrate=True) # creates all needed tables When I save the file and open the database administration I get the following ticket. Traceback (most recent call last): File "/Library/Python/2.5/site-packages/web2py/gluon/restricted.py", line 173, in restricted exec ccode in environment File "/Library/Python/2.5/site-packages/web2py/applications/cms/ models/db_01.py", line 16, in Field('reset_password_key',length=512,default='',writable=False, readable=False)) File "/Library/Python/2.5/site-packages/web2py/gluon/sql.py", line 1275, in define_table t._create(migrate=migrate, fake_migrate=fake_migrate) File "/Library/Python/2.5/site-packages/web2py/gluon/sql.py", line 1694, in _create self._db._execute(query) File "/Library/Python/2.5/site-packages/web2py/gluon/sql.py", line 958, in self._execute = lambda *a, **b: self._cursor.execute(*a, **b) ProgrammingError: relation "auth_user" already exists I thought setting fake_migrate=True would prevent me from having this problem? Kind regards, Annet.
[web2py] Re: error auth_user already exists
Hi Jonhy, Thanks for your reply. I am using PostgreSQL, and the auth_ tables contain data, so I cannot simply drop them, empty the databases folder and redefine them. I hope there is a solution which allows me to keep the tables in the PostgreSQL database. Kind regards, Annet.
[web2py] Re: where are the auth table model?
Hi Johny, I am facing the same problem, since there seems to be no proper solution I use the following workaround: I move everything that has to do with auth to its own db_01 file and define all my tables in a separate db_00.py file. Now every time a table definition changes, and I save db_00.py auth doesn't complain about the already existing tables. Now when I move the app containing auth to the deployment environment I delete the auth_ tables from both the app and PostgreSQL in the development environment. Once on the server, I open and save db_01.py, which creates the auth_ tables on the server. Every time I upgrade the app on the server I remove the auth_ .table and sql.log from the databases folder, pack all, upload and install the app on the server, and put the auth_ .table and sql.log files back into the databases folder. I know this is awkward, but I tried everything else, setting fake_migrate=False etc. but none of this solved the problem, whereas this procedure works for me. I posted a similar question on 6th January, to which Massimo posted the following reply: ""Tables have to be redefined (at the web2py level) every time you need them. Therefore you must call auth.define_tables() or, as far as web2py is concerned, they do not exist. When you define them at the web2py level, if migrate=False, web2py assumes thay also exist in the DB, if migrate=True it does not assumes that and looks into the .table files."" Kind regards, Annet.
[web2py] Re: where are the auth table model?
Hi Richard, > I don't know whether the problems you're having might stem from not > following this structure. I am pretty sure I got the structure right, Massimo helped me sort that out. auth.settings.table_user = db.define_table('auth_user', Field('first_name',length=24,default=''), Field('last_name',length=42,default=''), Field('bedrijf_id',db.bedrijf,default='',notnull=True,ondelete='CASCADE',writable=False, readable=False), Field(...), Field('reset_password_key',length=512,default='',writable=False, readable=False)) db.auth_user.first_name.requires=... auth.define_tables() When I moved my PostgreSQL database from development to production, I did not have authentication and authorization enabled. After developing a CSM app on the database, I had to run auth.define_tables in the production environment to add the auth_ tables to the production database. This could only be done with an empty databases folder in the CMS app. Now every time I update/upgrade the cms application I empty the databases folder, to prevent the .table files from being overwritten. The auth_... already exists problem also occurred when I extended my database with a new table, to prevent this from happening I put all my table definition in a separate db_xx.py file. I am very much aware that these are layman solutions, and I am very much looking forward to the day I come up with am more professional solution. Kind regards, Annet.
[web2py] Open menu item in new window.
In a view I have the following link which opens in a new window: {{=A('Contact form',_href=URL(r=request,a='utilities',c='forms',f='contact_form',args='init'),_target='_blank')}} In a menu I have a menu item which references the same function: ['Contact form',request.function=='contact_form',URL(r=request,a='utilities',c='forms',f='contact_form',args='init')]] To keep their behaviour consistent I would like to open the menu item in a new window also, is that possible? Kind regards, Annet.
[web2py] html e-mail newsletter
>From this article I learned how to code an html e-mail newsletter: http://articles.sitepoint.com/article/code-html-email-newsletters Now I would like to send this newsletter from within a Web2py CRM application. I searched the group for how to instructions but I didn't find anything useful. I tried the link in this post: http://groups.google.com/group/web2py/browse_thread/thread/83ee213ce5d3db0c/2ba13207adf09e57?lnk=gst&q=html+email#2ba13207adf09e57 but that resulted in an unable to connect warning. I tried the link to the wiki from Web2py's homepage but that resulted in an internal error. I hope one of you could provide me with detailed instructions of how to send an html e-mail newsletter from a Web2py application. Kind regards, Annet. -- You received this message because you are subscribed to the Google Groups "web2py-users" group. To post to this group, send email to web...@googlegroups.com. To unsubscribe from this group, send email to web2py+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/web2py?hl=en.
[web2py] Using the Template System to Generate Emails
I am trying to work out a working version of this: Using the Template System to Generate Emails, page 146 -147 of the web2py. 1. The database table in db.py: db.define_table('nfa', Field('bedrijf',db.bedrijf,default='',notnull=True,ondelete='CASCADE',writable=False,readable=False), Field('nfatype',db.nfatype,default='',notnull=True,ondelete='RESTRICT'), Field('adres',length=72,default='',notnull=True), migrate=False) 2. The mail settings in db.py: from gluon.tools import * mail=Mail() mail.settings.server='smtp.web...ion.com:587' mail.settings.sender='adm...ise.eu' mail.settings.login='xx' Where I would like to send every comapny in a message , stored in a view file "html_mail.html": 3. The function in default.py def send_mail(): nfas=db(db.nfa.nfatype==3).select(db.nfa.ALL,orderby=db.nfa.bedrijf) for nfa in nfas: context = dict(nfa=nfa) message = response.render('html_mail.html', context) mail.send(to=['.'], subject='None', message=message) . My questions are: what goes here: to= [''] the mail address to which I would like to send the mail is in nfas.adres and how does this function end, I mean what goes at the ... Kind regards, Annet. -- You received this message because you are subscribed to the Google Groups "web2py-users" group. To post to this group, send email to web...@googlegroups.com. To unsubscribe from this group, send email to web2py+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/web2py?hl=en.
[web2py] Re: Using the Template System to Generate Emails
Hi Denes, This send_mail function works: def send_mail(): nfas=db(db.nfa.nfatype==4).select(db.nfa.ALL,orderby=db.nfa.bedrijf) for nfa in nfas: context=dict(nfa=nfa) message=response.render('clublocatormail/ send_mail.html',context) recipient=nfa.adres mail.send(to=[recipient],subject='Controleer uw adresgegevens in Fitwise',message=message) return True I do have a question though: why recipient=nfa.adres and not recipient=nfa[0].adres Furthermore, I don't think this function is very robust. It returns True on success, but that's all. What happens when the send function returns a False? Shouldn't I keep track of the Trues and Falses the send function returns for every mail sent? Kind regards, Annet -- You received this message because you are subscribed to the Google Groups "web2py-users" group. To post to this group, send email to web...@googlegroups.com. To unsubscribe from this group, send email to web2py+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/web2py?hl=en.
[web2py] Re: Using the Template System to Generate Emails
Hi Denes, > because you have for nfa in nfas: so each nfa is a record > (from the group of records or 'Rows' object called nfas) This is what caused my confusion, in my cms app I had the following lines of code: record=db(db.betalingsgegevens.bedrijf==auth.user.bedrijf).select() record_id=record[0].id I thought that was similar to: for nfa in nfas: recipient=nfa.adres I do see the difference now, thanks. Kind regards, Annet -- You received this message because you are subscribed to the Google Groups "web2py-users" group. To post to this group, send email to web...@googlegroups.com. To unsubscribe from this group, send email to web2py+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/web2py?hl=en.
[web2py] Re: Using the Template System to Generate Emails
In my application all functions related to sending mail from it work. The main function reads like: def send_mail(): nfas=db(db.nfa.nfatype==4).select(db.nfa.ALL,orderby=db.nfa.bedrijf) for nfa in nfas: context=dict(nfa=nfa) message=response.render('clublocatormail/ send_mail.html',context) recipient=nfa.adres mail.send(to=[recipient],subject='Controleer uw adresgegevens in Fitwise',message=message) return True The send_mail.html view reads like (I removed the irrelevant parts): Template - Single Column body { background-color: #ee; } {{if not request.function=='browser_version':}} Having trouble viewing this email? {{=A('View it in your browser', _href="{{=URL(r=request,a='mock_crm',c='clublocatormail',f='browser_version',args=[nfa.bedrijf])")}}. {{pass}} {{=nfa.bedrijf}} {{=nfa.adres}} I based this code on this article: http://articles.sitepoint.com/article/code-html-email-newsletters and the templates referred to. I had hoped the view would display without trouble, but it doesn't. In all mail clients and web based apps, it displays as plain text, so the html is not rendered. I have been trying to find out why for two days now, and hope one of you can come to my rescue. Kind regards, Annet. -- You received this message because you are subscribed to the Google Groups "web2py-users" group. To post to this group, send email to web...@googlegroups.com. To unsubscribe from this group, send email to web2py+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/web2py?hl=en.
[web2py] Re: Using the Template System to Generate Emails
Denes and Alexandre, Your replies were very helpful and helped me understand and solve the problem, thanks. Thadeus, > Use the following class lined out in the wiki, works like a charm. I will, in one of the next iterations. At the moment I am not yet proficient enough in Python to completely understand the class outlined in the wiki, and consequently unable to use it properly. Kind regards, Annet. -- You received this message because you are subscribed to the Google Groups "web2py-users" group. To post to this group, send email to web...@googlegroups.com. To unsubscribe from this group, send email to web2py+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/web2py?hl=en.
[web2py] Re: Using the Template System to Generate Emails
I have another question: In case the user would like to view the html mail in his browser, I have got the following line of code: {{if not request.function=='browser_version':}} Having trouble viewing this email? View it in your browser {{pass}} I would like to use the same view, however, that view contains the variable nfa.bedrijf, which, in case of the mail, is available from the context. The link to the browser_version function contains args=[nfa.bedrijf], so nfa.bedrijf is available as request.args[0] in the browser_version function, but I don't now to pass it on to the view in a suitable way. I could do: def browser_version(): response.view='send_mail.html' nfa=db((db.nfa.nfatype==4)&(db.nfa.bedrijf==request.args[0])).select(db.nfa.ALL) return dict(nfa=nfa) ..., but that would unnecessarily query the database. Is there another way to solve this problem? Kind regards, Annet. -- You received this message because you are subscribed to the Google Groups "web2py-users" group. To post to this group, send email to web...@googlegroups.com. To unsubscribe from this group, send email to web2py+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/web2py?hl=en.
[web2py] Mailing list.
In my application I have a table npa which contains non-physical addresses, i.e. telephone numbers, fax numbers, e-mail addresses etc. that are displayed on business cards. This table has a field company which references a table company. Initially I inserted addresses into these tables which I got from the Chamber of Commerce. Now I would like to send a first e-mail to these companies, based on the e-mail addresses in the npa table. In this first mail the recipient gets the opportunity to register himself as contact person for a company. The table contact_person contains a field e-mail_address, which I would like to use for future promotional e-mails, instead of the e-mail address in the npa table. However, if the recipient doesn't register as a contact person, I have to be able to use the e-mail address from the npa table. Furthermore, I need a table which keeps track of the unsubscribe request. Did one of you face a similar problem? How did you solve it? Kind regards, Annet. -- You received this message because you are subscribed to the Google Groups "web2py-users" group. To post to this group, send email to web...@googlegroups.com. To unsubscribe from this group, send email to web2py+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/web2py?hl=en.
[web2py] Re: Using the Template System to Generate Emails
In the send_mail.html view I have a link which reads like: Having trouble viewing this email? View it in your browser When I send the mail and open it this link reads like: Having trouble viewing this email? View it in your browser Does one of you know why the href isn't being rendered? Kind regards, Annet. -- You received this message because you are subscribed to the Google Groups "web2py-users" group. To post to this group, send email to web...@googlegroups.com. To unsubscribe from this group, send email to web2py+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/web2py?hl=en.
[web2py] Re: Mailing list.
Yarko, > Hope this helps a little. Yes, actually it helped me a lot. Kind regards, Annet. -- You received this message because you are subscribed to the Google Groups "web2py-users" group. To post to this group, send email to web...@googlegroups.com. To unsubscribe from this group, send email to web2py+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/web2py?hl=en.
[web2py] Drop boxes in 1.76.5
Today, I upgraded my web2py installation to version 1.76.5. In this web2py version the drop boxes display an empty key value pair first, and then the key value pairs from the tables I based them on. What causes this change in behaviour? How do I correct it? Kind regards, Annet. -- You received this message because you are subscribed to the Google Groups "web2py-users" group. To post to this group, send email to web...@googlegroups.com. To unsubscribe from this group, send email to web2py+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/web2py?hl=en.
[web2py] href not being rendered
In a send_mail.html view I have a link which reads like: Having trouble viewing this email? View it in your browser When I send the mail and open it this link reads like: Having trouble viewing this email? View it in your browser Does one of you know why the href isn't being rendered? Kind regards, Annet. -- You received this message because you are subscribed to the Google Groups "web2py-users" group. To post to this group, send email to web...@googlegroups.com. To unsubscribe from this group, send email to web2py+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/web2py?hl=en.
[web2py] Cleanup sessions
I have just moved my application from the development environment to a production environment. I read the web2py manual and some posts in the group on the subject of cleaning up sessions, but I am not sure which is the best way to proceed. I am running version 1.76.5 of web2py. Kind regards, Annet -- You received this message because you are subscribed to the Google Groups "web2py-users" group. To post to this group, send email to web...@googlegroups.com. To unsubscribe from this group, send email to web2py+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/web2py?hl=en.
[web2py] Web2py mounted to sub-url
When I use the custom install script at WebFaction to install web2py the docs point me to the following caveat: Web2py won't work properly if it is mounted to a sub-URL like http://domain.com/web2py/. it must be mounted to the domain root. What exactly does this mean? Kind regards, Annet. -- You received this message because you are subscribed to the Google Groups "web2py-users" group. To post to this group, send email to web...@googlegroups.com. To unsubscribe from this group, send email to web2py+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/web2py?hl=en.
[web2py] args problem in 1.76.5
After upgrading to web2py version 1.76.5 one of the functions I defined no longer works. I defined a table newsmonth: db.define_table('newsmonth', db.Field('number',type='integer',length=2,default='',notnull=True), db.Field('month',length=14,default='',notnull=True,unique=True), db.Field('publish',type='boolean'), migrate=False) ... which I use to display archived news items per month. Number is the number of the month e.g April 4. Month is a string, for April it reads like: April 2010. Publish defaults to false and is set to true on the 1st of the next month. In the view I have a list with links: March 2010 february 2010 january 2010 When the visitor clicks March 2010, the news table is queried: def archive(): months=db(db.newsmonth.publish==True).select(db.newsmonth.ALL,orderby=~db.newsmonth.id) news=[] month=[] if request.args: news=db(db.news.publishing_date.month()==request.args[0])\ .select(db.news.ALL,orderby=~db.news.publishing_date) month=request.args[1] if not news: response.flash='Select an archived month' else: response.flash='Select an archived month' return dict(months=months,news=news,month=month) month is set to request.args[1], i.e March 2010, and returned to the view: Nieuws {{=month.replace('_',' ')}} {{for item in news:}} {{=db.news.publishing_date.formatter(item.publishing_date)}} {{=A(item.title,_onmouseover="this.style.cursor='pointer';",\ _onclick="javascript:newsdetails('%s')"%URL(r=request,f='details',args=[item.id]))}} {{pass}} Archived months: {{for month in months:}} {{=A(month.month,_href=URL(r=request,args=[month.number,month.month]))}} {{pass}} When I expose the archive function, the view displays well. The URL reads like: http://127.0.0.1:8000/init/news/archive However, when I click one of the archived months links I get an invalid request error. The link in the view reads like: March 2010 ... the URL in the browser reads like: http://127.0.0.1:8000/init/news/archive/3/maart%202010 Since the function works without args, I suppose the error has something to do with the args, the porblem is I can't figure out what. Kind regards, Annet. -- You received this message because you are subscribed to the Google Groups "web2py-users" group. To post to this group, send email to web...@googlegroups.com. To unsubscribe from this group, send email to web2py+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/web2py?hl=en.
[web2py] args problem in 1.76.5
After upgrading to web2py version 1.76.5 one of the functions I defined no longer works. I defined a table newsmonth: db.define_table('newsmonth', db.Field('number',type='integer',length=2,default='',notnull=True), db.Field('month',length=14,default='',notnull=True,unique=True), db.Field('publish',type='boolean'), migrate=False) ... which I use to display archived news items per month. Number is the number of the month e.g April 4. Month is a string, for April it reads like: April 2010. Publish defaults to false and is set to true on the 1st of the next month. In the view I have a list with links: March 2010 february 2010 january 2010 When the visitor clicks March 2010, the news table is queried: def archive(): months=db(db.newsmonth.publish==True).select(db.newsmonth.ALL,orderby=~db.newsmonth.id) news=[] month=[] if request.args: news=db(db.news.publishing_date.month()==request.args[0])\ .select(db.news.ALL,orderby=~db.news.publishing_date) month=request.args[1] if not news: response.flash='Select an archived month' else: response.flash='Select an archived month' return dict(months=months,news=news,month=month) month is set to request.args[1], i.e March 2010, and returned to the view: Nieuws {{=month.replace('_',' ')}} {{for item in news:}} {{=db.news.publishing_date.formatter(item.publishing_date)}} {{=A(item.title,_onmouseover="this.style.cursor='pointer';",\ _onclick="javascript:newsdetails('%s')"%URL(r=request,f='details',args=[item.id]))}} {{pass}} Archived months: {{for month in months:}} {{=A(month.month,_href=URL(r=request,args=[month.number,month.month]))}} {{pass}} When I expose the archive function, the view displays well. The URL reads like: http://127.0.0.1:8000/init/news/archive However, when I click one of the archived months links I get an invalid request error. The link in the view reads like: March 2010 ... the URL in the browser reads like: http://127.0.0.1:8000/init/news/archive/3/March%202010 Since the function works without args, I suppose the error has something to do with the args, the porblem is I can't figure out what. Kind regards, Annet. -- You received this message because you are subscribed to the Google Groups "web2py-users" group. To post to this group, send email to web...@googlegroups.com. To unsubscribe from this group, send email to web2py+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/web2py?hl=en.
[web2py] Re: args problem in 1.76.5
In the view, when I replace: {{=A(month.month,_href=URL(r=request,args=[month.number,month.month]))}} with: {{=A(month.maand,_href=URL(r=request,args=[3,'maart_2010']))}} The function works. When I replace the underscore with a space: {{=A(month.maand,_href=URL(r=request,args=[3,'maart 2010']))}} The space is being replaced with %20 and the function no longer works. Hopes this helps you help me solve the problem. Annet. -- You received this message because you are subscribed to the Google Groups "web2py-users" group. To post to this group, send email to web...@googlegroups.com. To unsubscribe from this group, send email to web2py+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/web2py?hl=en.
[web2py] Re: args problem in 1.76.5
In the view, when I replace: {{=A(month.month,_href=URL(r=request,args=[month.number,month.month]))}} with: {{=A(month.month,_href=URL(r=request,args=[3,'maart_2010']))}} The function works. When I replace the underscore with a space: {{=A(month.month,_href=URL(r=request,args=[3,'maart 2010']))}} The space is being replaced with %20 and the function no longer works. Hopes this helps you help me solve the problem. Annet. -- You received this message because you are subscribed to the Google Groups "web2py-users" group. To post to this group, send email to web...@googlegroups.com. To unsubscribe from this group, send email to web2py+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/web2py?hl=en.
[web2py] Re: args problem in 1.76.5
Massimo, The problem is that web2py did replace spaces with underscores, but in version 1.76.x it no longer does. The function described above worked, until I upgraded to version 1.76.5. That's why I have this line of code in my view: Nieuws {{=month.replace('_',' ')}} to have the month display like without the underscore: April 2009 instead of April_2009 Kind regards, Annet. -- You received this message because you are subscribed to the Google Groups "web2py-users" group. To post to this group, send email to web...@googlegroups.com. To unsubscribe from this group, send email to web2py+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/web2py?hl=en.
[web2py] ProgrammingError: relation "auth_user" already exists
I have one application (called base) in which I define all the tables for three other applications. In the three applications I use the same db.py file. In these db.py files I set migrate=False on all tables. One of these applications is a CMS, in which I enabled Authorization and Authentication. This creates the .table files for auth_event, auth- group, auth_membership, auth_permission and auth_user in the databases folder of the cms application, all the .table files for the other tables are in the databases folder of the base application. Today I defined four more tables in the base application's db.py file, and copied and paste them to the db.py files of the other applications, and set migrate=False on these tables. After saving the db.py file of the CMS application I got the following error when I go to the database administration: ProgrammingError: relation "auth_user" already exists Does this mean I cannot make changes to the db.py file in which Authorization and Authentication are enabled? i.e. I can only save the db.py file once. Kind regards, Annet. -- To unsubscribe, reply using "remove me" as the subject.
[web2py] Re: ProgrammingError: relation "auth_user" already exists
Could it have anything to do with defining a custom auth_user tabel? auth.settings.table_user=db.define_table('auth_user', Field('bedrijf', db.bedrijf, default='', notnull=True,ondelete='CASCADE', writable=False, readable=False), Field('first_name', length=128, default='', notnull=True), Field('last_name', length=128, default='', notnull=True), Field('email', length=128, default='', notnull=True), Field('site', type='boolean', writable=False, readable=False), Field('username', length=128, default='', notnull=True, unique=True), Field('password', type='password', length=256, readable=False, default='', notnull=True), Field('created_on',type='datetime', writable=False, readable=False), Field('modified_on',type='datetime', writable=False, readable=False), Field('most_recent_login',type='datetime', writable=False, readable=False), Field('registration_key', length=128, writable=False, readable=False, default='')) db.auth_user.bedrijf.requires=[IS_IN_DB(db, db.bedrijf.id, '% (bedrijfsnaam)s')] db.auth_user.bedrijf.label='Bedrijf * ' db.auth_user.first_name.requires=[IS_LENGTH(128,error_message='lengte overschreidt 128 tekens'), IS_NOT_EMPTY()] db.auth_user.first_name.label='Voornaam * ' db.auth_user.last_name.requires=[IS_LENGTH(128,error_message='lengte overschreidt 128 tekens'), IS_NOT_EMPTY()] db.auth_user.last_name.label='Achternaam * ' db.auth_user.email.requires=[IS_LENGTH(128,error_message='lengte overschreidt 128 tekens'), IS_EMAIL(), IS_NOT_EMPTY()] db.auth_user.email.label='E-mail * ' db.auth_user.site.default=False db.auth_user.username.requires=[IS_LENGTH(128,error_message='lengte overschreidt 128 tekens'), IS_NOT_EMPTY(), IS_NOT_IN_DB(db, 'auth_user.username')] db.auth_user.username.label='Gebruikersnaam * ' db.auth_user.password.requires=[IS_NOT_EMPTY(), CRYPT()] db.auth_user.password.label='Wachtwoord * ' db.auth_user.created_on.default=request.now db.auth_user.modified_on.default=request.now db.auth_user.modified_on.update=request.now db.auth_user.most_recent_login.default=request.now Kind regards, Annet. -- To unsubscribe, reply using "remove me" as the subject.
[web2py] Unable to install application
I installed web2py 1.76.5 at webfaction using their latest custom installer script. I am able to login to the admin application, however, when I Upload and Install a packed application I get the error: unable to install application "init". I hope one of you can help me solve this problem. Kind regards, Annet. -- To unsubscribe, reply using "remove me" as the subject.
[web2py] Re: ProgrammingError: relation "auth_user" already exists
Massimo, Yes, that would solve the problem, but I do have data in the auth_xxx tables. I had hoped there would be a more robust solution. Isn't it possible to define the auth_event, auth- group, auth_membership, auth_permission and auth_user in db.py just like I define all the other tables, and after the tables have been created set their migrates to migrate=False. I mean to not use auth.define_tables() to create the tables. In that case the auth_xxx tables are created once, and longer touched when I edit the db.py file. Kind regards, Annet. -- To unsubscribe, reply using "remove me" as the subject.
[web2py] Re: Unable to install application
Chris, Thank you very much for your extensive reply to my post. I apologize for not replying earlier (bedtime ;-) ) The script you reference above is indeed the one I used to install web2py: http://wiki.webfaction.com/wiki/Web2py-LatestSource I first tried to install web2py manually based on these instructions: http://forum.webfaction.com/viewtopic.php?id=2373 I did get web2py installed this way in December, however, in March I didn't. At WebFaction they advised me to use their installer script to install web2py, and emphasized that I should not start/stop web2py myself. I'll get in touch with them, and reference the links you posted. I'll let you know when the problem is solved. Kind regards, Annet. -- To unsubscribe, reply using "remove me" as the subject.
[web2py] Re: Unable to install application
Chris, Thank you very much for your extensive reply to my post. I apologize for not replying earlier (bedtime ;-) ) The script you reference above is not the one I used to install web2py. I read my log and found out that WebFaction no longer provides the scrip I used: web2py:http://wiki.webfaction.com/wiki/Web2py-TrunkInstall?format=txt I first tried to install web2py manually based on these instructions: http://forum.webfaction.com/viewtopic.php?id=2373 I did get web2py installed this way in December, however, in March I didn't. At WebFaction they advised me to use their installer script to install web2py, and emphasized that I should not start/stop web2py myself. I'll get in touch with them, and reference our findings. I'll let you know when the problem is solved. Kind regards, Annet. -- To unsubscribe, reply using "remove me" as the subject.
[web2py] _href and src url not rendered
In the view of a html mail function I have got the following A-helper and img tag: Having trouble viewing this email? {{=A('View it in your browser', _href=URL(r=request,c='clublocatormail',f='browser_version',args=[item.bedrijfcontactpersoon.bedrijf,item.contactpersoon.id]), _target="_blank")}} When I expose the function both locally and on the server the _href and src attributes aren't rendered, i.e. when I open the mail in a mail client or for example roundcube web mail the attributes just aren't there: Having trouble viewing this email? View it in your browser Does one of you know why, and how to solve this problem? Kind regards, Annet. -- Subscription settings: http://groups.google.com/group/web2py/subscribe?hl=en
[web2py] Re: _href and src url not rendered
Maybe the following information is of help to help me solve the problem. The mail function reads like: def send_mail(): mailinglist=db((db.bedrijfcontactpersoon.bedrijf==db.bedrijf.id)&(db.bedrijfcontactpersoon.bedrijf==db.bedrijfinschrijving.bedrijf)& \ (db.bedrijfcontactpersoon.contactpersoon==db.contactpersoon.id)&(db.bedrijfinschrijving.inschrijving==2)& \ (db.contactpersoon.subscription==True))\ .select(db.bedrijf.bedrijfsnaam,db.bedrijfcontactpersoon.bedrijf,db.contactpersoon.id,db.contactpersoon.email, \ orderby=db.bedrijfcontactpersoon.bedrijf) for item in mailinglist: context=dict(item=item) message=response.render('clublocatormail/ send_mail.html',context) recipient=item.contactpersoon.email boolean=mail.send(to=[recipient],subject='Bedrijfsgegevens ' + item.bedrijf.bedrijfsnaam + ' in Fitwise',message=[None,message]) if boolean: db.mailing_stats.insert(bedrijf=item.bedrijfcontactpersoon.bedrijf,contactpersoon=item.contactpersoon.id, \ controller='clublocatormail',functie='send_mail') else: db.admin_stats.insert(bedrijf=item.bedrijfcontactpersoon.bedrijf,contactpersoon=item.contactpersoon.id, \ controller='clublocatormail',functie='send_mail') return True And the view: Template - Single Column Having trouble viewing this email? {{=A('View it in your browser', _href=URL(r=request,c='clublocatormail',f='browser_version',args=[item.bedrijfcontactpersoon.bedrijf,item.contactpersoon.id]), _target="_blank")}} Fitwise Fitwise is een informatie en communicatie tool op internet waarmee u uw klanten en potentiële klanten moeiteloos bereikt en waarmee zij u moeiteloos kunnen vinden via onze {{=A('club locator', _href=URL(r=request,c='clublocatormail',f='clublocator',args=[item.bedrijfcontactpersoon.bedrijf,item.contactpersoon.id]), _target="_blank")}}. Als ondernemer wilt u natuurlijk dat uw bedrijfsgegevens in ons systeem up-to-date zijn. Controleer daarom {{=A('uw bedrijfsgegevens in Fitwise', _href=URL(r=request,c='clublocatormail',f='check_details',args=[item.bedrijfcontactpersoon.bedrijf,item.contactpersoon.id]), _target="_blank")}} Zijn uw bedrijfsgegevens in ons systeem niet up-to-date of wilt u uzelf als contactpersoon aanmelden. Vul dan het {{=A('wijzigingsformulier', _href=URL(r=request,c='clublocatormail',f='update_form',args=[item.bedrijfcontactpersoon.bedrijf,item.contactpersoon.id,]), _target="_blank")}} in. Zijn uw bedrijfsgegevens in ons systeem up- to-date? Laat het ons weten via het {{=A('bevestigingsformulier', _href=URL(r=request,c='clublocatormail',f='update_form',args=[item.bedrijfcontactpersoon.bedrijf,item.contactpersoon.id,]), _target="_blank")}}. Met vriendelijke groet Not interested anymore? {{=A('Unsubscribe', _href=URL(r=request,c='clublocatormail',f='unsubscribe',args=[item.bedrijfcontactpersoon.bedrijf,item.contactpersoon.id,]))}} When I change the mail function to read like: def not_send_mail(): item=db((db.bedrijfcontactpersoon.bedrijf==db.bedrijf.id)&(db.bedrijfcontactpersoon.bedrijf==db.bedrijfinschrijving.bedrijf)& \ (db.bedrijfcontactpersoon.contactpersoon==db.contactpersoon.id)&(db.bedrijfinschrijving.inschrijving==2)& \ (db.contactpersoon.subscription==True))\ .select(db.bedrijf.bedrijfsnaam,db.bedrijfcontactpersoon.bedrijf,db.contactpersoon.id,db.contactpersoon.email, \ orderby=db.bedrijfcontactpersoon.bedrijf) return dict(item=item) And in the view replace item with item[0]. Then, when I expose the not_send_mail function the view is rendered correctly: "Having trouble viewing this email?" Kind regards, Annet -- Subscription settings: http://groups.google.com/group/web2py/subscribe?hl=en