I am trying to build a search where the results of my search populate a column panel below the textbox and the elements of the column panel are links to the student’s individual notes page which I have a form for as well. I am modifying the CRM app template. Somehow I am not passing the notes properly and after a couple of hours of fiddling I am putting it to the group.
Here is my TeacherHome form code:
from anvil import *
import anvil.server
import google.auth, google.drive
from google.drive import app_files
import tables
from tables import app_tables
from re import *
from StudentSearch import StudentSearch
class TeacherHome (TeacherHomeTemplate):
def init(self, tables, **kwargs):
self.init_components(**kwargs)
# Any code you write here will run when the form opens.
def search_btn_click (self, **event_args):
# This method is called when the button is clicked
text = self.search_box.text
students_row = anvil.server.call(‘search_students’, text)
self.notes = anvil.server.call(‘search_notes’, text)
self.student_pnl.add_component(StudentSearch(students_row, self.notes), index=0)
Here is my StudentSearch form code:
from anvil import *
import anvil.server
import google.auth, google.drive
from google.drive import app_files
import tables
from tables import app_tables
class StudentSearch (StudentSearchTemplate):
def init(self, row, notes, **kwargs):
# You must call self.init_components() before doing anything else in this function
self.init_components(**kwargs)
self.row = row
#self.notes = notes
self.notes = notes
# Any code you write here will run when the form opens.
self.searched_name_lbl.text = row['name']
self.searched_points_lbl.text = str(row['total_points']) + " points"
def open_link_click (self, **event_args):
# This method is called when the link is clicked
open_form("StudentNotes", self.row, self.notes)
and here are my server module functions:
@anvil.server.callable
def search_students(text):
if text is not None:
for row in app_tables.students.search():
if re.search(text, row[‘name’], re.IGNORECASE) is not None:
return row
@anvil.server.callable
def search_notes(text):
if text is not None:
return app_tables.notes
It seems to me that when you set notes in your CustomerList it was as easy as setting it to the table.
Thanks in advance