Exemple #1
0
def main_page():
    """
    Render the main page with news.
    """
    return render_template('base.html',
                           title='Главная страница',
                           news=get_news(0, 10),
                           templates=["news.html", "news_scroll.html"])
Exemple #2
0
def news(offset):
    news = get_news(offset, 10)
    print(offset)
    print(news)
    if news:
        return render_template('news.html', news=news, templates=["news.html"])
    else:
        return jsonify('No content'), 204
Exemple #3
0
 def get(self):
     take = 20
     page = self.get_argument("page", default="1")
     page = int(page)
     skip = (page - 1) * take
     news_result = yield db.get_news(skip=skip, take=take)
     news = news_result["news"]
     total = news_result["total"]
     total_pages = total / take
     self.render(
         'index.html',
         news=news,
         page=page,
         take=take,
         total_pages=total_pages,
     )
Exemple #4
0
def admin_news():
    """
    GET: render the admin page where the admin can add news.
    POST: read and parse news requests made on this page.
    """
    if request.method == 'GET':
        return render_template('admin_news.html',
                               news=get_news(0, 10),
                               templates=["news.html", "news_scroll.html"])
    if request.method == 'POST':
        date = request.form['date']
        text = json.loads(request.form['text'])
        text = process_editorjs_text(text)
        if not (date and text):
            return jsonify(success=False)
        news_id = add_news(date, text)
        if request.files:
            for image in request.files.values():
                if image.content_type.startswith('image/'):
                    add_image(image.filename.lower(), f'news/{news_id}',
                              image.read())
        return jsonify(success=True)
Exemple #5
0
def mynews():
    news = db.get_news(current_user)
    return render_template('mynews.htm', news=news)