What I’m trying to do:
I am trying to set the items of a Repeating Panel (RP) to a row in my data table. In my data table it is perfectly normal to have many cells to be None! I have a high suspicion that this could be a bug, but on the other hand, I have done this exact way of setting an RP’s items in the past with no errors. I am pretty clueless.
What I’ve tried and what’s not working:
I have tried the code below but it gives me an error and tells me that self.item is in fact a list (no clue how this has come to be). I have tried printing out self.item within the RP and this is what shows me it is a list (see Console Output) and this is strange because when I am setting the items of my RP I printed it out and it is just a normal row. However, it looks like most of the data has been lost in transit.
Form Code:
print(f"Form: {dict(anvil.server.call('getPupWeightTitles', self.litterID))}")
self.rpPupWeightTitles.items = anvil.server.call('getPupWeightTitles', self.litterID)
Server Code:
'''Get PupWeights from datatable that matches ID'''
@anvil.server.callable
def getPupWeightTitles(matchID):
rows = app_tables.firstfortnightfile___pupweights.search(ID=matchID)
if len(rows) > 0: # Check if the list of rows is not empty
# print(f"PupWeights {matchID}: Existing row found")
# Return the first row matching the ID
return rows[0]
else: # If row doesn't exist, create a new row and return it
# print(f"PupWeights {matchID}: Creating new row")
raise Exception("Row does not exist")
RepeatingPanel Code:
class PupWeightsTitles(PupWeightsTitlesTemplate):
def __init__(self, **properties):
# Set Form properties and Data Bindings.
self.init_components(**properties)
# Any code you write here will run before the form opens.
self.fillLables()
def fillLables(self):
# f"{self.item['Name']}\n{self.item['CollarColour']}"
print(f"RP: {self.item}")
self.dateObj = self.item['StartingDate']
Console Output: Line 23 is: self.dateObj = self.item['StartingDate']
Form: {'Day6': None, 'Day8': None, 'CollarColour': 'Dark green', 'Day12': None, 'Day9': None, 'Name': 'Ben', 'StartingDate': datetime.date(2023, 6, 25), 'Day0': 1234, 'Day5': None, 'Day1': None, 'Day7': None, 'Day3': None, 'Day11': None, 'Day2': None, 'ID': 1, 'Day10': None, 'Day4': None, 'Day13': None}
RP: ['Day6', None]
TypeError: list indices must be integers or slices, not str
at FirstWhelpingFortnight.PupWeightsTitles, line 23
SOLVED
To fix this issue I followed what stefano.menci’s comment says and just put the single row that I was returning into a list:
return [rows[0]]