Ejemplo n.º 1
0
    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
Ejemplo n.º 2
0
    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
Ejemplo n.º 3
0
 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
Ejemplo n.º 4
0
 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
Ejemplo n.º 5
0
 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')