Get a single row, column value from Users table

What I’m trying to do:

  1. I have a boolean column (isAdded) in my Users table. When a user registers, I would like to set the column cell to True. If not, to False

  2. When the user logs in, I’d like to pull out the value in the boolean column for this user and use the value to call a specific form, eg. if True, load the form TeamOne else load form TeamTwo.

What I’ve tried and what’s not working:
I haven’t tried anything on Issue No. 1 other than manually setting it in the User table. On Issue No. 2, here’s what I have done but is not working. I am just posting here the class MainPage.

  def __init__(self, **properties):

    self.init_components(**properties)
    user = anvil.users.get_user()
    self.set_account_state(user)
   
  def link_logout_click(self, **event_args):
    # alert ('Program is here')
    anvil.users.logout()
    self.set_account_state(None)
    self.load_component(MainPage())

  def link_login_click(self, **event_args):
    user = anvil.users.login_with_form(allow_cancel=True)
    user_id = app_tables.users.search(isAdded = True)
    alert (f'This is the user_id: {user_id}')
    if not user:
      self.load_component(MainPage())
    else:
      if user_id==True:
        self.load_component(TeamOne())
      else:
        self.load_component(TeamTwo())```

I viewed meredydd's YouTube tutorial on multiple users to get some idea but 
that seems a bit different from what I want since I am not pulling a 
data row from the server.  I also looked at other posts in this 
forum that might help viz., setting global variable and creating 
a module Globals but I just could not get the right handle. 
The TalkPython Anvil tutorial would have helped when the tutor 
mentioned about having an 'isPro' boolean later but he stopped short.

I would greatly appreciate help on setting the value of the boolean cell 
and pulling out the cell value to be used later. 

**Code Sample:**
```python
# this is a formatted code snippet.
# paste your code between ``` 

Clone link:
share a copy of your app

When you do:

what you get back is a row from the Users table that contains the values for the columns in that table. If there’s a column named isAdded in that table, you just use user['isAdded'] to get to that value. No need for another search.

2 Likes

Thank you for another good lesson.
I will try it out.

A lot of thanks @jshaffstall. It worked very nicely. I also used user[‘isAdded’] to set the column data (True or False) when users log-in. Now, I can save a manual visit to the User table. :sweat_smile:

What’ll i do without helpful people like you in this forum? :clap:

2 Likes