Beispiel #1
0
    def all(self):
        posts = dict()
        result = super(Post, self).all('posts')
        while True:
            post = result.fetch_row(1,1)
            if not post: break
            post_id = post[0]['post_id']
            posts[post_id] = { 'post_id' : str(post[0]['post_id']),
                               'user_id' : str(post[0]['user_id']),
                               'lat' : str(post[0]['lat']),
                               'lng' : str(post[0]['lng']),
                               'post' : str(post[0]['post']),
                               'comments' : dict(),
                               'created_at' : post[0]['created_at'].strftime('%m/%d/%Y')
                               }
            #get the comments
            select = SelectBuilder()
            select.setStatement('select *')
            select.setTables('from comments')
            select.setWhere('where post_id = ' + str(post[0]['post_id']))
            comments = self._db.execute(select)

            while True:
                comment = comments.fetch_row(1,1)
                if not comment: break
                comment_id = comment[0]['comment_id']
                posts[post_id]['comments'][comment_id] = { 'comment_id' : str(comment[0]['comment_id']),
                                                  'user_id' : str(comment[0]['user_id']),
                                                  'comment' : str(comment[0]['comment']),
                                                  'created_at' : comment[0]['created_at'].strftime('%m/%d/%Y')
                                                  }
        return posts
Beispiel #2
0
    def return_pw(self, user_name = None):
        password = ''

        if user_name:
            select = SelectBuilder()
            select.setStatement('select password')
            select.setTables('from users')
            select.setWhere('where user_name = "' + user_name + '"')
            result = self._db.execute(select)
            row = result.fetch_row(1,1)
            password = row[0]

        return password
Beispiel #3
0
    def load(self,user_name = None):
        self._user_name = user_name

        if self._user_name:
            select = SelectBuilder()
            select.setStatement('select *')
            select.setTables('from users')
            select.setWhere('where user_name = "' + self._user_name +'"')
            result = self._db.execute(select)
            row = result.fetch_row(1,1)
            
            self._user_id = row[0]['user_id']
            self._user_name = row[0]['user_name']
            self._role = row[0]['role']