Get all data in user row?

Hello, I am new to Python and Anvil, I would appreciate a little help to get up and running.

What I’m trying to do:
I have created another column in the user database table. I have been trying to figure out how to get it to check that column for true or false, for the current login user.

What I’ve tried and what’s not working:
I have tried so many different variations of the if line below. But obviously I haven’t got the right one :slight_smile: That is even if I’m on the right track.

  user = anvil.users.get_user() 
  if user['mainlink']: 
    form.load_component(Component_my_stuff_profile_mainlink())
  else:
    form.load_component(Component_home_anon())

Thanks
Jason

Is your Users Data Table client-readable (that is, accessible to forms)? You’d have to change a setting in Data Tables to make it so. Then I think that code should work.

As the linked docs explain, though, this is not advisable from a security standpoint. (It would expose your users’ email addresses, etc. to potential attackers.) Instead, I would retrieve the desired information from the Users table using a server function.

The table I am using is the one Anvil creates for users which is not readable or writable in forms. Even if I change the ability to read or write it still does not work, I get the same error.

TypeError: ‘NoneType’ does not support indexing

Thanks
Jason

get_user () will return None when there is no user currently logged in.

3 Likes

Got it thanks a lot guys!

Here is what I used

  user = anvil.users.get_user()
  if user is not None and user['mainlink'] is False:
    form.load_component(Component_my_stuff_profile_mainlink())
  elif user is not None and user['mainlink'] is True:
    form.load_component(Component_my_stuff_profile())
  else:
    form.load_component(Component_home_anon())

Thanks
Jason

Just a style thing, but Python lets you write this more concisely:

if user and not user['mainlink']:
    form.load_component(Component_my_stuff_profile_mainlink())
  elif user and user['mainlink']:
    form.load_component(Component_my_stuff_profile())
  else:
    form.load_component(Component_home_anon())

[/quote]

1 Like

Thank you, I bet that makes coding a lot easier in the long run.
As a side note I didn’t even know concisely was a word. I looked up and feel smarter now. :slight_smile:

Thanks
Jason

1 Like