Adjust Assessments Display¶
We can enter assessment details and we can view them. We even change the value of completed via a check box on the AssessmentPanel.
We can display all our assessments, but do we really want to display all assessments. What about assessments that have been completed?
In this tutorial you will adjust the HomeComponent so that it only displays the assessments that are still outstanding.
Change assessments displayed¶
Since the information on the repeating panel is derived from it’s items list, we will need to change the item list. The item list comes from the get_assessment function in the assessment_service, so we need to make changes there.
get_assessment code¶
Open the get_assessment function in the assessment_service and make the highlighted change to the code:
25 return app_tables.assessments.search(tables.order_by('due_date'),
26 user=user,
27 completed=False)
Code explaination
completed=False
→ just like line 26, this is a restriction on the rows that will be retrieved. Only those assessments that have not been completed will be retrieved.
Testing¶
Time to check if the code works.
Launch your web app
You should not see the assignment that you marked as completed in the previous tutorial.
To make sure, stop your web app
Go to the assessments table in the data section
Find and un-tick the assessment you marked as complete in the last tutorial
Relaunch your web app
You should now see that assessment on the Home page
Final code state¶
By the end of this tutorial your code should be the same as below:
Final assessment_service¶
1import anvil.users
2import anvil.tables as tables
3import anvil.tables.query as q
4from anvil.tables import app_tables
5import anvil.server
6
7@anvil.server.callable
8def add_assessment(subject, details, start_date, due_date):
9 user = anvil.users.get_user()
10
11 app_tables.assessments.add_row(user= user,
12 subject= subject,
13 details=details,
14 start_date=start_date,
15 due_date=due_date,
16 completed=False)
17
18@anvil.server.callable
19def get_assessment():
20 user = anvil.users.get_user()
21
22 return app_tables.assessments.search(tables.order_by('due_date'),
23 user=user,
24 completed=False)
25
26@anvil.server.callable
27def update_assessment_completed(assessment_id, completed):
28 assessment = app_tables.assessments.get_by_id(assessment_id)
29 if assessment:
30 assessment["completed"] = completed