Beispiel #1
0
 def get_posts_by_user(id):
     user_posts = dao.read(USER_POST)
     post_ids = [
         int(row['post_id']) for row in user_posts if int(row['uid']) == id
     ]
     post_objs = list(map(PostManager.get_post_by_id, post_ids))
     return post_objs
Beispiel #2
0
 def category_search(category):
     data = dao.read(POSTS)
     data = [
         row for row in data
         if category == row['category'] or category == 'all'
     ]
     data = [Discount_post(row) for row in data]
     return data
Beispiel #3
0
    def get_users_categories():
        data = dao.read(USER_CATEGORIES)
        rels = defaultdict(list)
        for rel in data:
            if rel['category'] not in rel['user_id']:
                rels[rel['user_id']].append(rel['category'])

        return rels
Beispiel #4
0
 def add_post(data_dict, uploaded_file=None):
     all_posts = dao.read(POSTS)
     data_dict['id'] = len(all_posts)
     if uploaded_file is not None:
         filename = str(data_dict['id']) + ".jpg"
         uploaded_file.save(
             os.path.join(app.config['UPLOAD_FOLDER'], filename))
     data_dict.pop('file', None)
     dao.write(POSTS, [data_dict], mode="a")
Beispiel #5
0
 def get_post_by_id(id):
     post_dict = next(filter(lambda u: int(u['id']) == id, dao.read(POSTS)))
     return Discount_post(post_dict)
Beispiel #6
0
 def get_all_posts():
     data = dao.read(POSTS)
     data = [Discount_post(row) for row in data]
     print(data)
     return data
Beispiel #7
0
 def name_search(name):
     data = dao.read(POSTS)
     data = [row for row in data if name in row['name']]
     data = [Discount_post(row) for row in data]
     return data
Beispiel #8
0
 def remove_post(post):
     data = dao.read(POSTS)
     data = [row for row in data if int(row['id']) != post.id]
     dao.write(POSTS, data, mode="w")
Beispiel #9
0
 def get_users():
     return [User(user_dict) for user_dict in dao.read(USERS)]
Beispiel #10
0
 def get_user_by_id(id):
     all_users = dao.read(USERS)
     for user in all_users:
         if user['id'] == str(id):
             return User(user)
     return None
Beispiel #11
0
 def add_user(user_form):
     # count curr user number
     uid = len(dao.read(USERS)) + 1
     user_form['id'] = uid
     dao.write(USERS, [user_form])