def uploaded_articles(username): if current_user.is_authenticated() and current_user.username == username: collection = 'NEWS_COLLECTION' total = app.config[collection].find({"user": username}).count() condition_key = "user" condition_value = username try: articles, articles_length, page, per_page, offset = get_articles( collection, condition_key, condition_value) pagination = get_pagination(page=page, per_page=per_page, total=total, record_name=articles) likes = app.config['USERS_COLLECTION'].find_one( {"_id": current_user.username})["likes"] return render_template('uploaded_articles.html', articles=articles, page=page, per_page=per_page, pagination=pagination, articles_length=articles_length, likes=likes) except ValueError: total = 0 return render_template('category.html', total=total) else: return render_template('404.html'), 404
def latest(): collection = 'NEWS_COLLECTION' sortby = 'createdAt' try: total = get_count(collection) articles, articles_length, page, per_page, offset = articles_stat( collection, sortby) pagination = get_pagination(page=page, per_page=per_page, total=total, record_name=articles) if current_user.is_authenticated(): likes = app.config['USERS_COLLECTION'].find_one( {"_id": current_user.username})["likes"] return render_template('trending.html', articles=articles, page=page, per_page=per_page, pagination=pagination, articles_length=articles_length, likes=likes) else: return render_template('trending.html', articles=articles, page=page, per_page=per_page, pagination=pagination, articles_length=articles_length) except ValueError: total = 0 return render_template('trending.html', total=total) except ValueError: total = 0 return render_template('latest.html', total=total)
def category_selection(category_type): article_category = [ item[0] for item in CATEGORIES if item[1] == category_type ] if len(article_category) > 0: collection = 'ARTICLES_COLLECTION' total = app.config[collection].find({ "category": article_category[0] }).count() condition_key = "category" condition_value = article_category[0] try: articles, articles_length, page, per_page, offset = get_articles( collection, condition_key, condition_value) pagination = get_pagination(page=page, per_page=per_page, total=total, record_name=articles) if current_user.is_authenticated(): # finding the articles liked by the current user likes = app.config['USERS_COLLECTION'].find_one( {"_id": current_user.username})["likes"] return render_template('trending.html', articles=articles, page=page, per_page=per_page, pagination=pagination, articles_length=articles_length, likes=likes) else: return render_template('trending.html', articles=articles, page=page, per_page=per_page, pagination=pagination, articles_length=articles_length) except ValueError: total = 0 return render_template('category.html', total=total) else: return render_template('404.html'), 404