def get(self, summit_id, images=False): with self.get_cursor() as cur: cur.execute( """SELECT s.id, s.name, name_alt, height, interpretation, s.description, ridge_id, r.name AS ridge, coordinates, (SELECT COUNT(*) FROM summits WHERE height >= s.height ) AS number, (SELECT MAX(height)=s.height FROM summits WHERE ridge_id=s.ridge_id) AS main FROM summits s LEFT JOIN ridges r ON s.ridge_id = r.id WHERE s.id=%s""", (summit_id, )) if cur.rowcount < 1: return None # summit = self.__row2summit(cur.fetchone()) summit = Summit(**cur.fetchone()) summit.images = [] if images: summit.images = \ self.summits_images_dao.get_by_summit(summit_id) return summit
def climbed(self, user_id): climbed = [] sql = """SELECT year, month, day, comment, summits.id, summits.ridge_id, summits.name, height, ridges.name AS ridge FROM ridges LEFT JOIN summits ON ridges.id=summits.ridge_id LEFT JOIN climbs ON summits.id=climbs.summit_id WHERE climbs.user_id=%s ORDER BY year, month, day""" with self.get_cursor() as cur: cur.execute(sql, (user_id, )) for row in cur: s = Summit() s.name = row['name'] s.ridge = row['ridge'] s.ridge_id = row['ridge_id'] s.id = row['id'] s.height = row['height'] climbed.append({ 'summit': s, 'date': InexactDate.fromdict(row), 'comment': row['comment'] }) return climbed
def climbed(self, user_id): climbed = [] sql = """SELECT year, month, day, comment, summits.id, summits.ridge_id, summits.name, height, ridges.name AS ridge FROM ridges LEFT JOIN summits ON ridges.id=summits.ridge_id LEFT JOIN climbs ON summits.id=climbs.summit_id WHERE climbs.user_id=%s ORDER BY year, month, day""" with self.get_cursor() as cur: cur.execute(sql, (user_id, )) for row in cur: s = Summit() s.name = row['name'] s.ridge = row['ridge'] s.ridge_id = row['ridge_id'] s.id = row['id'] s.height = row['height'] climbed.append( {'summit': s, 'date': InexactDate.fromdict(row), 'comment': row['comment']}) return climbed
def __get_many(self, query, params): with self.get_cursor() as cur: cur.execute(query, params) return self.__rate_by_field([Summit(**row) for row in cur], 'height')