Error in database giving 'NoneType' object has no attribute 'first_name'.

259 views
Skip to first unread message

Sai Harsh Tondomker

unread,
Jun 29, 2015, 9:02:32 AM6/29/15
to web...@googlegroups.com
db.define_table("Questions",
  Field('quesno', unique=True),
  Field('question', 'text'),
  Field('optionA', 'string'),
  Field('optionB', 'string'),
  Field('optionC', 'string'),
  Field('optionD', 'string'),
  Field('answer', 'string'),
  Field('extra1','string'),
  Field('extra2','string'))

db.define_table("secret",
  Field('name','string'),
  Field('quesstatus', 'integer',default=1),
  Field('score', 'integer',default=0),
  Field('score1', 'integer',default=0),
  Field('Test', 'integer',default=1),
  Field('correct', 'integer',default=0),
  Field('wrong', 'integer',default=0),
  Field('unanswered', 'integer',default=0),
  Field('Level1Hint','integer'))

auth_count = db(db.auth_user.id >= 0).count()
secret_count = db(db.secret.id >= 0).count()
if(auth_count > secret_count):
    db.secret.insert(name = auth.user.first_name)
    db(db.secret.name == auth.user.first_name).update(quesstatus= 1)
    db(db.secret.name == auth.user.first_name).update(score = 0)
    db(db.secret.name == auth.user.first_name).update(Test = 1)
    db(db.secret.name == auth.user.first_name).update(correct = 0)
    db(db.secret.name == auth.user.first_name).update(wrong = 0)
    db(db.secret.name == auth.user.first_name).update(unanswered = 0)
    db(db.secret.name == auth.user.first_name).update(Level1Hint = 0)
elif(auth_count == secret_count):
    db.secret(name = auth.user.first_name).update(quesstatus= 1)
    db.secret(name = auth.user.first_name).update(score1 = 0)
    db.secret(name = auth.user.first_name).update(Test = 1)
    db.secret(name = auth.user.first_name).update(correct = 0)
    db.secret(name = auth.user.first_name).update(wrong = 0)
    db.secret(name = auth.user.first_name).update(unanswered = 0)
    db.secret(name = auth.user.first_name).update(Level1Hint = 0)

Giving Error as 

<type 'exceptions.AttributeError'> 'NoneType' object has no attribute 'first_name'

    db(db.secret.name == auth.user.first_name).update(correct = 0)
db(db.secret.name == auth.user.first_name).update(wrong = 0)
db(db.secret.name == auth.user.first_name).update(unanswered = 0)
db(db.secret.name == auth.user.first_name).update(Level1Hint = 0)
elif(auth_count == secret_count):
db.secret(name = auth.user.first_name).update(quesstatus= 1)

db.secret(name = auth.user.first_name).update(score1 = 0)
db.secret(name = auth.user.first_name).update(Test = 1)
db.secret(name = auth.user.first_name).update(correct = 0)
db.secret(name = auth.user.first_name).update(wrong = 0)

Showing there is an error in color line. I am unable to find the error please help me to solve to problem argent.
Regards,
T.SaiHarsh

Massimo Di Pierro

unread,
Jun 29, 2015, 9:30:29 AM6/29/15
to web...@googlegroups.com, saihar...@iiits.in
That code may run when no user is logged in so auth.user is None

Sai Harsh Tondomker

unread,
Jul 1, 2015, 10:01:19 AM7/1/15
to web...@googlegroups.com, saihar...@iiits.in
Then What I need to do to solve the problem.

And how to take data from XML file to data base.

Waiting for your response

Regards
T.Sai Harsh

Anthony

unread,
Jul 1, 2015, 10:14:32 AM7/1/15
to web...@googlegroups.com, saihar...@iiits.in
On Wednesday, July 1, 2015 at 10:01:19 AM UTC-4, Sai Harsh Tondomker wrote:
Then What I need to do to solve the problem.

Your code refers to auth.user, which presumes there is a user logged in. If there is no user logged, in, it won't work, so maybe decorate the action in question with @auth.requires_login to ensure there is a logged in user. If you don't want to require login for this action, then you need some other way to identify the user.

Anthony

Sai Harsh Tondomker

unread,
Jul 3, 2015, 12:00:22 PM7/3/15
to web...@googlegroups.com
Dear Anthony,

Yesterdays it self I have tried these but after logout it instead of redirecting to index page it show the error which I have mention.
What I need to do.
If you want I can explain you on what project I am working.
Please help me to solve this problem.

Waiting for your response.

Best regards
T.Sai Harsh

--
Resources:
- http://web2py.com
- http://web2py.com/book (Documentation)
- http://github.com/web2py/web2py (Source code)
- https://code.google.com/p/web2py/issues/list (Report Issues)
---
You received this message because you are subscribed to a topic in the Google Groups "web2py-users" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/web2py/cmrh-dv6oOw/unsubscribe.
To unsubscribe from this group and all its topics, send an email to web2py+un...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

黄祥

unread,
Jul 3, 2015, 1:53:49 PM7/3/15
to web...@googlegroups.com
i think you can achieve it in 2 parts
controllers
if you want to have a validator for check is user login or not in controller you can use : @auth.requires_login
e.g.
@auth.requires_login
def abcd():
    return locals()

models
you can also use if function for each of table definition
e.g.
auth_count = db(db.auth_user.id >= 0).count() if auth.user else None
secret_count = db(db.secret.id >= 0).count() if auth.user else None

best regards,
stifan

Anthony

unread,
Jul 3, 2015, 5:30:24 PM7/3/15
to web...@googlegroups.com, saihar...@iiits.in
It's not clear exactly what you have done. Please show some code.
To unsubscribe from this group and all its topics, send an email to web2py+unsubscribe@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages