Hi Anvil community,
I’m building an employee tasks page where a logged-in user can see all their assigned tasks. The tasks are stored in a Data Table with fields like:
Task Name
Description
Status (Not Started, In Progress, Completed)
Due Date
Assignee (username)
What I’m trying to do:
On my page, I’m using a Data Grid with a Repeating Panel, and I want to:
Show all tasks for the currently logged-in user
Display them in a table layout (like Task Name, Description, Status, Due Date)
Sort the tasks so they appear in this order:
- Not Started
- In Progress
- Completed
What I’ve tried and what’s not working:
I’ve created a server function get_user() that returns the current session user.
Another server function get_employee_tasks(username) returns all tasks for that user from the tasks table.
Code Sample:
# this is a formatted code snippet.
# paste your code between
This is the client code for Employee_tasks.
``` def form_show(self, **event_args):
"""This method is called when the form is shown on the page"""
current_user = anvil.server.call('get_user')
print(current_user)
This is the server code:
def user_login(username, password):
#Authenitcates a user by comparing the entered username and password to the stored credentials in the data table
#get the user record from the 'users' table
#app_tables is a data table function in Anvil, which stores the user credentials in this case
user = app_tables.users.get(username=username)
#Validate the password and return the user role if login is successful
if user and user['password'] == password:
return user['role']
#return False if authentication fails
return False
@anvil.server.callable
def vet():
user = anvil.server.session.get('user', None)
if user is None:
return None
role = user['role']
if role == 'admin':
return 'Admin_Dashboard'
elif role == 'employee':
return 'Employee_Dashboard'
else:
return None
@anvil.server.callable
def get_employee_tasks(username):
return app_tables.tasks.search(Assignee=username)
@anvil.server.callable
def get_user():
return anvil.server.session.get('user', None)```