Hello
Form is defined as form = auth()
Changing session.flash to response.flash still does not work after user
This is my whole user code
def user():
form = auth()
if request.args(0)=='profile':
#uporabnikov Id
uid = auth.user_id
#preberem podatke za tega userja iz obeh tabel
record = db((db.auth_user.organization==db.organizations.id) & (
db.auth_user.id == uid)).select().as_list()[0]
recordd = db((db.auth_user.organization==db.organizations.id) & (
db.auth_user.id == uid)).select().first()
#Skrijem nepotrebna polja
fields_to_hide_org = ['id', 'o_usern', 'o_useru',
'o_daten','o_dateu', 'o_status', 'o_code', 'o_faxnumber',\
'o_rootid', 'o_parentid', 'o_levelid',
'o_positionx','o_positiony' ]
for fieldname in fields_to_hide_org:
field = db.organizations[fieldname]
field.readable = field.writable = False
fields_to_hide_user = ['email', 'password', 'organization']
for fieldname in fields_to_hide_user:
field = db.auth_user[fieldname]
field.readable = field.writable = False
#org_name = db(db.organization.id ==
record["organization"]).select(db.organization.o_name).as_list()[0]["o_name"]
#nastavim vrednsoti polj, ki so ze v bazi
authfields = [field for field in db.auth_user if field.name != 'id']
#print record
for field in authfields:
#print field
field.default = recordd.auth_user[field.name]
orgfields = [field for field in db.organizations if field.name !=
'id']
for field in orgfields:
field.default = recordd.organizations[field.name]
form=SQLFORM.factory(db.auth_user,db.organizations, keepvalues =
True)
orgid = record["organizations"]['id']
#print orgid
if form.process().accepted:
#Updatam polja v bazi
org_forma = db.organizations._filter_fields(form.vars)
for key, value in org_forma.iteritems():
#print key, value
db(db.organizations._id==orgid).update(**{key:value})
#db(db.organization.id==orgid).update(key = value)
user_forma = db.auth_user._filter_fields(form.vars)
for key, value in user_forma.iteritems():
db(db.auth_user._id==orgid).update(**{key:value})
session.flash=T('Thanks for filling the form')
redirect(URL('index'))
return dict(form=form)
"""
Tole je sedaj tukaj ker ni delal foreing key na auth_user.organization
"""
if request.args(0) == 'register':
#form = auth.register()
if form.process().accepted:
database = str(db).rpartition('/')[-1].replace('">', '')
host = request.http_host
port = request.http_port
app = request.application
if host:
name = '%s/%s' % (host, app)
else:
name = app
#print form.vars
userid = form.vars.id
email = form.vars.email
first_name = form.vars.first_name
last_name =form.vars.last_name
org_name = form.vars.organization
add_organization(form, userid)
#glede na jezik se izbere formular
if any("adminLanguage=sl" in s for s in
request.env.HTTP_COOKIE.split(";")):
formFile = os.path.join(request.folder, 'private',
'formular_WoShi_podatki.doc')
else:
formFile = os.path.join(request.folder, 'private',
'form_WoShi_data.doc')
if not formFile or formFile is None:
attachment = None
else:
attachment = mail.Attachment(formFile, content_id='file')
#print URL(args=request.args, vars=request.get_vars, host=True)
app_Url = '%s://%s' % (request.env.wsgi_url_scheme,
request.env.http_host)
#print app_Url
regKey = db(db.auth_user.id ==
userid).select(db.auth_user.registration_key).first()
key = regKey.registration_key
message_content = T('Click on the link ') + app_Url +
URL(r=request,c='default',f='user',args=['verify_email']) + '/%s ' % (key)
+ T('to verify your email')
#print message_content
mail.send(to=[email],
subject='Woshi confirm registration',
message=message_content,
attachments = attachment
)
##dodamo še mail za [email protected]
mail.send(to = 'somerandommail',
subject= 'New user registered in WoShi',
message = 'A new user '+ first_name + " " + last_name
+' with e-mail address ' + email +" for organization " + org_name
+ ' has registered to Woshi with url
address '
+ name + ' in database ' + database
)
#session.flash = T('Thank you for registering. Please check
your e-mail account')
response.flash = T('Thank you for registering. Please check
your e-mail account for further instructions')
#auth.settings.register_onaccept=[session.flash]
#session.flash=response.flash
#print response.flash
#print session
redirect(URL(request.application, 'default', 'index'))
#redirect(URL('index'))
return dict(form = form)
2017-05-08 14:34 GMT+02:00 Anthony <[email protected]>:
> On Monday, May 8, 2017 at 5:08:59 AM UTC-4, Yebach wrote:
>>
>> Flash is show on my index page so the position <div
>> class="flash">{{=session.flash
>> or ''}}</div> is ok
>> I just put session.flash('Some random text') in my index function and it
>> works
>>
>
> session.flash is not intended to work that way. You use session.flash only
> when you are doing a redirect, in which case, it gets moved from
> session.flash to response.flash after the redirect. So, the template should
> have {{=response.flash}}, not {{=session.flash}}.
>
>
>> My code for user registration in index.py user
>>
>> if request.args(0) == 'register':
>>
>> #form = auth.register()
>> if form.process().accepted:
>>
>> #some code
>>
>> session.flash = ('Thank you for registering. Please check your
>> e-mail account')
>>
>> redirect(URL(request.application, 'default', 'index'))
>>
>>
> How is "form" defined above? If it is defined as form=auth.register(),
> then you cannot subsequently call form.process(), as auth.register()
> already calls form.process().
>
> Anthony
>
> --
> Resources:
> - http://web2py.com
> - http://web2py.com/book (Documentation)
> - http://github.com/web2py/web2py (Source code)
> - https://code.google.com/p/web2py/issues/list (Report Issues)
> ---
> You received this message because you are subscribed to a topic in the
> Google Groups "web2py-users" group.
> To unsubscribe from this topic, visit https://groups.google.com/d/
> topic/web2py/Yfvnke6ABWM/unsubscribe.
> To unsubscribe from this group and all its topics, send an email to
> [email protected].
> For more options, visit https://groups.google.com/d/optout.
>
--
Lep pozdrav
Vid Ogris
--
Resources:
- http://web2py.com
- http://web2py.com/book (Documentation)
- http://github.com/web2py/web2py (Source code)
- https://code.google.com/p/web2py/issues/list (Report Issues)
---
You received this message because you are subscribed to the Google Groups
"web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
For more options, visit https://groups.google.com/d/optout.