From 847e33ed6ed01a671eee003fd7d7659199620530 Mon Sep 17 00:00:00 2001 From: Joey Hines Date: Sun, 22 Jul 2018 20:03:24 -0500 Subject: [PATCH] find command now shows tunnels --- DatabaseInterface.py | 10 ++++++---- DatabaseModels.py | 6 +++++- 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/DatabaseInterface.py b/DatabaseInterface.py index 82c8e00..5e9befe 100644 --- a/DatabaseInterface.py +++ b/DatabaseInterface.py @@ -140,7 +140,7 @@ class DatabaseInterface: return player def search_all_fields(self, session, search): - loc_string = '' + loc_string = '\n**Locations:**' count = 0 expr = Location.owner.has(Player.name.ilike('%{}%'.format(search))) | Location.name.ilike('%{}%'.format(search)) @@ -148,9 +148,11 @@ class DatabaseInterface: loc_string = "{}\n{}".format(loc_string, loc) count += 1 - expr = Tunnel.owner.has(Player.name.ilike('%{}%'.format(search))) & Tunnel.location is None - for loc in self.database.query_by_filter(session, Tunnel, expr): - loc_string = "{}\n{}".format(loc_string, loc) + loc_string = loc_string + '\n\n**Tunnels:**' + + expr = Tunnel.owner.has(Player.name.ilike('%{}%'.format(search))) & Tunnel.location == None + for tunnel in self.database.query_by_filter(session, Tunnel, expr): + loc_string = "{}\n{}".format(loc_string, tunnel.full_str()) count += 1 if count == 0: diff --git a/DatabaseModels.py b/DatabaseModels.py index 972a571..4db4293 100644 --- a/DatabaseModels.py +++ b/DatabaseModels.py @@ -154,6 +154,9 @@ class Tunnel(SQL_Base): except (ValueError, IndexError): raise TunnelInitError + def full_str(self): + return 'Owner: **{}**\'s Tunnel: **{}**'.format(self.owner.name, self.__str__()) + def __str__(self): return '{} {}'.format(self.tunnel_direction.value.title(), self.tunnel_number) @@ -201,7 +204,8 @@ class Location(SQL_Base): return '(x= {}, z= {}) in the {}'.format(self.x, self.z, self.dimension.value.title()) def info_str(self): - return "Name: **{}**, Type: **{}** Position: **{}**".format(self.name, self.type, self.pos_to_str()) + return "Name: **{}**, Type: **{}**, Owner: **{}** Position: **{}**".format(self.name, self.type, + self.owner.name, self.pos_to_str()) def full_str(self): return self.__str__() + '\n' + self.dynmap_link()