[web2py] Cannot set string field to None
I have a few additional fields set on my db_auth table, mainly in order to implement a simple invite system: auth.settings.extra_fields['auth_user']= [ Field('invite_sent', 'datetime', default=None), # None for activated users Field('invite_key')] When the invite has been accepted, I want to set both field to None. This works for db.auth_user.invite_sent but not for the second field. I try the following in the web2py python shell: db(db.auth_user.id==123).validate_and_update(invite_key=None) Row {'updated': None, 'errors': Row {'invite_key': 'enter from 0 to 255 characters'}} I tried to check for the field's attributes, but this looks alright to me: repr(db.auth_user.invite_key.default) 'None' db.auth_user.invite_key.notnull False Setting to a zero length string works, but that's not what I want. Also, I can set it to NULL in SQL, so the underlying DB scheme seems to be okay. I am running web2py Version 1.99.7 on Python 2.7.3 right now. What am I missing, why can I not set the field to be None? --
[web2py] Manually setting email for auth registration form
I have some custom requirements for registration, but I still want to use auth.register() with a custom form view to rely on web2py's form validation. Background: I have a table of allowed email addresses with a generated secret hash. (kind of like an invitation only registration). When you access the secret invite link I look up the secret hash in the database and want to use the auth.register() form without the email field so I can set the user's email to the one I already have. I have come across 2 problems: 1. When my custom form doesn't include an email field, the form does not seem to be processed and just redirects to itself. (see comment in view below) 2. When I set the email field to be not writable, the registration fails and I get a ticket: Traceback (most recent call last): File /Users/flo/Applications/web2py/gluon/restricted.py, line 205, inrestricted exec ccode in environment File /Users/flo/Applications/web2py/applications/main/controllers/signup.pyhttp://127.0.0.1:8000/admin/default/edit/main/controllers/signup.py , line 138, in module File /Users/flo/Applications/web2py/gluon/globals.py, line 173, in lambda self._caller = lambda f: f() File /Users/flo/Applications/web2py/applications/main/controllers/signup.pyhttp://127.0.0.1:8000/admin/default/edit/main/controllers/signup.py , line 62, in complete form = auth.register(onaccept=on_accept) File /Users/flo/Applications/web2py/gluon/tools.py, line 1959, in register user = Storage(table_user._filter_fields(user, id=True)) File /Users/flo/Applications/web2py/gluon/dal.py, line 6683, in_filter_fields return dict([(k, v) for (k, v) in record.items() if k AttributeError: 'NoneType' object has no attribute 'items' Here is the code that I think is relevant for this: Inside my controller: signup_data = db(db.signup.signup_key==signup_key).select(db.signup.ALL).first() def on_accept(form): # does a whole bunch of setting up additional db entries pass # stripped out for the example auth.settings.table_user.email.default = signup_data.email auth.settings.table_user.email.writable = False # causes error form = auth.register(onaccept=on_accept) # line 62 (see error log) Inside my view: {{=form.custom.begin }} div style=display: none; {{ # removing this field from markup causes the form submission to fail. :/}} {{=form.custom.widget.email }} /div {{=form.custom.widget.first_name }} ... all the other widgets ... {{=form.custom.end}} --
[web2py] Re: Sending emails with background queue problem
Yes, I am using mysql. I've accidentally posted this twice [0] on the group (sorry for that). Anthony asked: How are emails added to the database -- does that happen within the application, or also in a script? Emails are added to the database from within the application (a controller function adds a confirmation email to the queue) [0] https://groups.google.com/forum/?fromgroups#!topic/web2py/YT2jDMea6lU On Sunday, 12 August 2012 07:17:39 UTC+12, Massimo Di Pierro wrote: Are you using mysql? On Friday, 10 August 2012 23:11:03 UTC-5, Florian Letsch wrote: I want to send emails using a background queue as described in the web2py book: http://web2py.com/books/default/chapter/29/8#Sending-messages-using-a-background-task However, the queue only sends emails that have been in the database when I start the script. Database entries added lateron don't get picked up by the script. The only way I can achieve that is to add another db.commit() before the select(). I am sure this is not supposed to be necessary. Does anyone know why this is happening? import time while True: db.commit() # Only works if I add this line rows = db(db.queue.status=='pending').select() for row in rows: if mail.send(to=row.email, subject=row.subject, message=row.message): row.update_record(status='sent') else: row.update_record(status='failed') db.commit() time.sleep(60) # check every minute --
[web2py] Re: Sending email from background queue
I've accidentally posted this twice. Please have a look at the other thread: https://groups.google.com/forum/?fromgroups#!topic/web2py/u5R-vGcP580%5B1-25%5D I answered your question there (emails are added from within the application). On Sunday, 12 August 2012 06:17:15 UTC+12, Anthony wrote: How are emails added to the database -- does that happen within the application, or also in a script? On Saturday, August 11, 2012 12:55:40 AM UTC-4, Florian Letsch wrote: *My first post somehow didn't make it to the group, I don't know where it got lost. Sorry if I submit this twice, I have never participated in a news group before.* I am trying to set up a background queue for sending email as described in the web2py book. http://web2py.com/books/default/chapter/29/8#Sending-messages-using-a-background-task However, emails are only sent when they have been in the database before starting the script. Emails I add to the database when the queue is running do not get picked up for some reason. I got it to work by adding an additional db.commit() before the select() in every loop run. I assume this should not be needed. Does anyone have an idea why this is not working without that additional commit? import time while True: db.commit() # not working without this line rows = db(db.queue.status=='pending').select() for row in rows: if mail.send(to=row.email, subject=row.subject, message=row.message): row.update_record(status='sent') else: row.update_record(status='failed') db.commit() time.sleep(60) # check every minute --
[web2py] Sending emails with background queue problem
I want to send emails using a background queue as described in the web2py book: http://web2py.com/books/default/chapter/29/8#Sending-messages-using-a-background-task However, the queue only sends emails that have been in the database when I start the script. Database entries added lateron don't get picked up by the script. The only way I can achieve that is to add another db.commit() before the select(). I am sure this is not supposed to be necessary. Does anyone know why this is happening? import time while True: db.commit() # Only works if I add this line rows = db(db.queue.status=='pending').select() for row in rows: if mail.send(to=row.email, subject=row.subject, message=row.message): row.update_record(status='sent') else: row.update_record(status='failed') db.commit() time.sleep(60) # check every minute --
[web2py] Sending email from background queue
*My first post somehow didn't make it to the group, I don't know where it got lost. Sorry if I submit this twice, I have never participated in a news group before.* I am trying to set up a background queue for sending email as described in the web2py book. http://web2py.com/books/default/chapter/29/8#Sending-messages-using-a-background-task However, emails are only sent when they have been in the database before starting the script. Emails I add to the database when the queue is running do not get picked up for some reason. I got it to work by adding an additional db.commit() before the select() in every loop run. I assume this should not be needed. Does anyone have an idea why this is not working without that additional commit? import time while True: db.commit() # not working without this line rows = db(db.queue.status=='pending').select() for row in rows: if mail.send(to=row.email, subject=row.subject, message=row.message): row.update_record(status='sent') else: row.update_record(status='failed') db.commit() time.sleep(60) # check every minute --