Ahh right thats ok, I understand now, on the Python Idle, all the globals were just held until we did a calculation at the end. As long as I know that you cant do that, I wont spend hours trying to make it work
Thanks again!
My locationdetails table has just fully populated, so thats good. I think I’m all done - at least on this question. 
@jshaffstall sorry I spoke too soon. Originally I got this error on the locationdetail table
<LiveObject: anvil.tables.SearchIterator>
It appears to need this. Data Grid - Repeating Panel Errors - #2
So I followed the tutorial, and now I get this.
Exception: Data Binding update failed with 2 errors. Did you initialise all data binding sources before initialising this component?
- Error binding
text of label_1
toself.item['Location']['Location']:
list indices must be integers or slices, not str
- Error binding
text of label_2
toself.item['Location']['LocationPercent']:
list indices must be integers or slices, not str
The only thing I havent done is a variation on this print(app_tables.employees.get(name="Bob")['team']['team_name']) which is as per their example, where [‘team’]['team_name']
I did try adding one of the bindings at the end of my repeating panel but it didnt make any difference
self.repeating_panel_ages.items = anvil.server.call('get_all_ages',self.ageall ['Location']['Location'])
@anvil.server.callable
def get_all_location_details(location):
results = app_tables.locationdetail.search(LocationDetailCountry=q.ilike(location))
return results[0]
In this you are returning a single locationdetail row. When you call it, though:
self.repeating_panel_location.items = anvil.server.call('get_all_location_details', self.location)
You are setting the return into the items property of a repeating panel. Repeating panel items must be lists, but you’ve giving it a single row. That won’t work.
Either the server function must return a list, not a single row, or you don’t really want a repeating panel for displaying the results.
It looks like what you want is to display the location info that’s in the locationdetail row, so a repeating panel isn’t what you want. Just some labels you can set the text property of after the server call.
I’ve now removed all the original repeating panels and replaced them with print statements for the time being.
I can use my original SQL Query on my external table
def locationQuery (currentcountry):
conn = connect()
with conn.cursor() as cur:
cur.execute("SELECT location.LocationID, location.Location,location.LocationPercent FROM location INNER JOIN locationdetail ON (locationdetail.LocationID = location.LocationID)WHERE locationdetail.LocationDetailCountry = '{currentcountry}' ORDER BY locationdetail.LocationDetailCountry LIMIT 1".format(currentcountry=currentcountry))
return cur.fetchall()
On this client side code
# Prints out the output of Location Input as a Location Country, Location Rating Area and Percent
for m in anvil.server.call('locationQuery',self.location):
fmt = 'Location {} Rating Area:{} Rating:{}'
data = (self.location, m['Location'], m['LocationPercent'])
print(fmt.format(*data))
It outputs the correct print statement of Location Spain Rating Area:Europe Rating:0
But, if I try and use Anvil Tables
@anvil.server.callable
def get_all_location_details(location):
results = app_tables.locationdetail.search(LocationDetailCountry=q.ilike(location))
return results[0]
I get this error TypeError: list indices must be integers or slices, not str
at Quotation, line 130
Line 130 is data = (m['Location'], m['LocationPercent'])
I’m really stuck on this.
return results[0]
When you return a single row, you cannot then use a for loop on the client to process it.
m = anvil.server.call('locationQuery',self.location)
fmt = 'Location {} Rating Area:{} Rating:{}'
data = (self.location, m['Location'], m['LocationPercent'])
print(fmt.format(*data))
Just use the row directly.
Ok, its all finally sorted, I had to modify the client code a bit and change one of my table column names. Here is the final code.
# Prints out the output of Location Input as a Location Country, Location Rating Area and Percent
m = anvil.server.call('get_all_location_details',self.location)
fmt = 'Location: {} Region:{} Rating:{}'
data = (self.location, m['Location']['LocationRegion'], m['Location']['LocationPercent'])
print(fmt.format(*data))
Thank you so much @jshaffstall!!
you have the patience of a saint…