Hi, I've been having a bit of trouble with submittal form failing
without any error messages. I got it to work around mid-day but now
it's failing again and I can't get it back to the point where it would
work. At any rate just fixing it isn't even good enough for me: I need
to find out how to get errors in event of failure, because this is
really like wading in a dark room trying to find black Heisenberg's cat
and not get your eyes scratched out.
Anyway, I'm sure I'm not doing something right. I've searched the group
and I found several threads about this or similar thing but the things
that worked for other people don't work here.
BTW I'm using 1.0b2.
I'm using registration module for user registration things and the part
where user information is updated fails & goes back to user edit form.
If I put in a print message on the first line of update_user, it does
not print (in registration, edit_user() shows editing form and
update_user takes its output and updates the database).
I would expect to get something in the window where ./start_proj is
run. It only shows dictionary of parameters that form returns, which
look OK. Or in the form next to offending field. From searching, I
found that errors can be seen in cherrypy.request.input_values, but
it's empty. I also have seen that adding **kw to the function in
questions seems to result in the mentioned input_values to be
populated, but that doesn't help.
This is annoying me like hell, especially because I suspect it's
something very simple I'm missing, and I lost half a day on it, half a
christmas, no less :-/.
Here's the code:
@expose(template='.templates.register_edit_user')
@identity.require(identity.not_anonymous())
def edit_user(self, tg_errors=None, **kw):
"Edit current user information."
# print "##### tg_errors: %s, kw: %s" % (tg_errors, kw)
# print "#### cherrypy.request: %s" % dir(cherrypy.request)
# if hasattr(cherrypy.request, "input_values"): # error has
occured
# print "####### %s" % cherrypy.request.input_values
u = identity.current.user
if u.show:
show = True
else:
show = False
# print "### u.show, show, u.set_to_show: %s, %s, %s" % (u.show,
show, u.set_to_show)
form_values = dict(user_name=u.user_name,
email=u.email_address, old_password='', password_1='', password_2='',
city=u.city, show=show, description=u.description, rent=u.rent,
phone1=u.phone1, phone2=u.phone2, address=u.address, gender=u.gender,
need_or_have=u.need_or_have, pets=u.pets, smoking=u.smoking,
state=u.state, )
values = {"set_to_show": u.set_to_show}
# print "###edit_user: form_values"
# pprint()
return dict(display_name=u.display_name,
form=edit_user_form,
form_values=form_values,
values=values,
action="update_user")
@expose()
@identity.require(identity.not_anonymous())
@validate(form=edit_user_form)
@error_handler(edit_user)
def update_user(self, email, old_password, password1, password2,
city, description, rent, phone1, phone2, address, gender, need_or_have,
pets, smoking, state, img1=None, show="off", user_name=None, **kw):
"Updates the users information with new values."
# print "###update_user: show " + repr(show)
# print "###update_user: dir(img1), %s" % dir(img1)
gender = str(gender)
pets = str(pets)
need_or_have = str(need_or_have)
smoking = str(smoking)
state = str(state)
if kw.has_key("set_to_show"):
user.set_to_show = kw["set_to_show"]
user = identity.current.user
msg = ""
if password1:
user.password=password1
msg = "Your password was changed. "
if email and email != user.email_address:
self.mail_changed_email_validation(email)
msg = msg + "You will recieve an email at %s with
instructions to complete changing your email address." % email
if address:
user.address=address
img1=None
if img1:
user.img1=img1.file.read()
if city:
user.city=city
if show:
if show == "on":
user.show = True
user.set_to_show = int(time.time())
else:
user.show = False
if description:
user.description = description
if rent:
user.rent=int(rent)
if phone2:
user.phone2=phone2
if phone1:
user.phone1=phone1
if gender:
user.gender = gender
if pets:
user.pets = pets
if need_or_have:
user.need_or_have = need_or_have
if smoking:
user.smoking = smoking
if state:
user.state = state
# if rent:
# user.rent = rent
# not working??
# logging.basicConfig(level=logging.INFO,
filename="/home/ak/reg/log.txt", filemode="a")
mlog("user '%s' info was updated." % user.user_name)
turbogears.flash(msg)
redirect('edit_user')
#### validators:
class ExistingUserSchema(validators.Schema):
state = validators.UnicodeString(not_empty=True, max=40)
gender = validators.UnicodeString(max=40)
need_or_have = validators.UnicodeString(max=50)
pets = validators.UnicodeString(max=50)
gender = validators.OneOf(["male", "female"])
email = validators.All(validators.Email(not_empty=True, max=255),
UniqueEmail())
old_password = validators.All(validators.UnicodeString(max=40),
ValidPassword())
password1 = validators.UnicodeString(max=40)
password2 = validators.UnicodeString(max=40)
description = validators.UnicodeString(max=800)
chained_validators = [validators.FieldsMatch('password1',
'password2')]
city = validators.UnicodeString(not_empty=True, max=50)
rent = validators.Int(not_empty=True)
phone1 = validators.UnicodeString(not_empty=True)
phone2 = validators.UnicodeString()
address = validators.UnicodeString(not_empty=True, max=80)
show = validators.UnicodeString(max=20)
smoking = validators.UnicodeString(max=50)
rent = validators.String(not_empty=True, max=7)
# img1 = validators.FieldStorageUploadConverter()
#### form fields:
class ExistingUserFields(widgets.WidgetsList):
user_name = FakeInputWidget('user_name',
label="User Name" )
# un = HiddenField
email = widgets.TextField('email',
label="Email",
help_text="Your email address (this will be
validated).")
# display_name = widgets.TextField('display_name',
# label="Display Name",
# help_text="A longer user name that others will
see.")
old_password = widgets.PasswordField('old_password',
label="Current password",
help_text="The current (old) password.")
password_1 = widgets.PasswordField('password1',
label="New Password",
help_text="Your new password. (If you would like to
change it).")
password_2 = widgets.PasswordField('password2',
label="New Password (again)",
help_text="New password again (should match the
input above).")
address = widgets.TextField('address',
label= "Address",
help_text="Your address with appartment number.")
phone1 = widgets.TextField('phone1',
label= "Phone 1",
help_text="")
phone2 = widgets.TextField('phone2',
label= "Phone 2",
help_text="")
rent = widgets.TextField('rent',
label= "Rent",
help_text="")
description = widgets.TextArea(name='description',
label= "Short description of the room you have or
are looking for",
rows=5, cols=40)
city = widgets.TextField('city',
label= "City",
help_text="")
state = widgets.SingleSelectField('state',
options=[
(1,"Alabama"),
(2, "Alaska"),
(3, "Arizona"),
(4, "Arkansas"),
(5, "California"),
(6, "Colorado"),
(7, "Connecticut"),
(8, "Delaware"),
(9, "District of Columbia"),
(10, "Florida"),
(11, "Georgia"),
(12, "Hawaii"),
(13, "Idaho"),
(14, "Illinois"),
(15, "Indiana"),
(16, "Iowa"),
(17, "Kansas"),
(18, "Kentucky"),
(19, "Louisiana"),
(20, "Maine"),
(21, "Maryland"),
(22, "Massachusetts"),
(23, "Michigan"),
(24, "Minnesota"),
(25, "Mississippi"),
(26, "Missouri"),
(27, "Montana"),
(28, "Nebraska"),
(29, "Nevada"),
(30, "New Hampshire "),
(31, "New Jersey"),
(32, "New Mexico"),
(33, "New York"),
(34, "North Carolina"),
(35, "North Dakota"),
(36, "Ohio"),
(37, "Oklahoma"),
(38, "Oregon"),
(39, "Pennsylvania"),
(40, "Rhode Island"),
(41, "South Carolina"),
(42, "South Dakota"),
(43, "Tennessee "),
(44, "Texas"),
(45, "Utah"),
(46, "Vermont"),
(47, "Virginia"),
(48, "Washington"),
(49, "West Virginia"),
(50, "Wisconsin"),
(51, "Wyoming"),], default=1)
gender = widgets.RadioButtonList('gender', options=[(1, "Male"),
(2, "Female")], default=1)
pets = widgets.RadioButtonList('pets', options=[(1, "Pets
allowed"),
(2, "Pets not allowed")], default=1)
need_or_have = widgets.RadioButtonList('need_or_have',
label="Need a Room or Have a Room", options=[(1, "I need a
Room"),
(2, "I Have a Room")], default=1)
smoking = widgets.SingleSelectField("smoking",
options=[(1, "Non-smoking"), (2, "Smoke inside or
outside"),
(3, "Only smoke outside")], default=1)
# img1 = widgets.FileField('img1',
# label= "Photo #1",
# help_text="The photo will be resized to 260x260")
show = widgets.CheckBox('show',
label= "Make profile visible",
help_text="I CONFIRM THAT I WANT MY PROFILE TO BE
SEARCHABLE AND VISIBLE TO OTHER USERS (uncheck box to make it hidden)")
Anybody know? thanks!
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"TurboGears" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at
http://groups.google.com/group/turbogears?hl=en
-~----------~----~----~----~------~----~------~--~---