**I am trying to create a clock in/out system. I created a row and a function to get the current time. I want to get the new row that I create in - “def clock_in_button_click(self, **event_args)” and update the row “Clock_Out_Lunch” with variable “Out_For_Lunch_LA_time” in function clock_out_button_click(self, **event_args) **
**I read the docs and tried a multitude of variations to get this to work. I know I am making a dumb mistake somewhere, but I just can’t see it.
The error I keep getting is:
TypeError: ‘NoneType’ does not support item assignment at [Main, line 87]
which is
out_for_lunch_table[‘Clock_Out_Lunch’] = Out_For_Lunch_LA_time
**
The results of this is None . Since it was not found in the database.
Since None cannot be assigned to, you got the error:
Another bug here is when you are calling .strftime() you are not passing the timezone back into it making it an unaware datetime object. If you tried to pass this back to the database, the time will be corrected twice. When you pass an unaware timestamp to anvil it gets adjusted to make it aware compared to the clients origin. This will not happen from inside the server which is utc time, it would automatically (correctly) get utc.
I got a hint at what is wrong, but I cannot figure out how to fix it.
Between the time I click on Clock in and wait 1 min, the Clock out button does not work. If I click on the clock out button right after I click on the clock in, and then it works.
It seems as if it stops recognizing something after 1 minute, but what is it and how to fix it is the question. Aghh
Because you’re calling Start_time to calculate the starting time. But that just gives you the current time.
You’re using the wrong approach. There’s no way to calculate the starting time when they click the clock out button, you have to remember the starting time in some fashion. e.g. using self.whatever variables, using the User record, etc.
This happens quite often to beginners, you might be confusing yourself with the varable names you are choosing. you call it out_for_lunch_table but you are trying to assign it a row from that table that is the result of a single row search operation (.get()).
You should really just look at the docs for .get() , .search() etc. :
And then write your architecture / logic around that, I think in another thread someone mentioned you have to make design decisions about how many users you will have etc.
Here is an example of some logic, you don’t have to use it, but its what I came up with because I do stuff like this often.
Create a new column of type bool. This column will be called clocked_in.
Create a single “Clock in and out” button.
Have the logic .get() the row that has both the current users email andclocked_in == True
Store this in a variable called row (for clarity)
Do an equivalency test.
if row is None:
#write code that clocks --in-- the user with by creating a new row
#don't forget to set row['clocked_in'] = True
#set clocked in time to "now"
...
else:
#write code that clocks --out-- the user with by modifying the existing row
#don't forget to set row['clocked_in'] = False
#set clocked OUT time to "now"
#you can now modify by calling the keys from the row variable, it is not None.
...
If it is None, they are not clocked in, and they need to be clocked in. If instead it retrieved a row, then it found a clocked in user, and it should clock them out, by setting the bool column to False and writing the clocked out timestamp to the correct column.
If you are really interested in learning python (It is easier that you might think) you might start at any of these places: