Ejemplo n.º 1
0
def clear_reports(story_to_read, loop_index):
    list_index = int(loop_index) - 1
    story = stories_collection.find_one({"url": story_to_read})
    report = story['reports'][list_index]
    stories_collection.find_one_and_update({"url": story_to_read},
                                           {'$pull': {
                                               'reports': report
                                           }})
    return redirect(url_for("admin_page"))
Ejemplo n.º 2
0
def delete_story(story_to_read):
    story = stories_collection.find_one({"url": story_to_read})
    if session.get('username') is not None:
        if session['username'] == story['author']:
            stories_collection.remove({"url": story_to_read})
            flash("Story deleted!")
            return redirect(url_for('profile', user=session['username']))
        else:
            flash("You cannot delete someone else's story!")
    else:
        session['next'] = request.url
        flash("You must be signed in to delete stories!")
    return redirect(url_for('login'))
Ejemplo n.º 3
0
def edit_chapter(story_to_read, chapter_number):
    story = stories_collection.find_one({"url": story_to_read})
    chapter_index = int(chapter_number) - 1
    if session.get('username') is not None:
        if session['username'] == story['author']:
            chapter = story['chapters'][chapter_index]
            return render_template("editchapter.html",
                                   story_to_read=story_to_read,
                                   story=story,
                                   chapter=chapter,
                                   chapter_number=chapter_number)
        else:
            flash("You cannot edit someone else's story!")
            return redirect(url_for("index"))
    else:
        session['next'] = request.url
        flash("You must be signed in to edit your stories!")
        return redirect(url_for("login"))
Ejemplo n.º 4
0
def delete_chapter(story_to_read, chapter_number):
    story = stories_collection.find_one({"url": story_to_read})
    chapter_index = int(chapter_number) - 1
    if session.get('username') is not None:
        if session['username'] == story['author']:
            chapter = story['chapters'][chapter_index]
            stories_collection.find_one_and_update(
                {"url": story_to_read}, {"$pull": {
                    "chapters": chapter
                }},
                upsert=True)
            flash("Chapter deleted!")
            return redirect(url_for("edit_story", story_to_read=story_to_read))
        else:
            flash("You cannot delete someone else's story!")
            return redirect(url_for("index"))
    else:
        session['next'] = request.url
        flash("You must be signed in to delete chapters!")
        return redirect(url_for("index"))
Ejemplo n.º 5
0
def update_chapter(story_to_read, chapter_number):
    if request.form['editor'] == '\"<p><br></p>\"':
        flash("You cannot send in empty posts!")
        return redirect(
            url_for("edit_chapter",
                    story_to_read=story_to_read,
                    chapter_number=chapter_number))
    elif request.form['editor'] == "":
        flash("You cannot send in empty posts!")
        return redirect(
            url_for("edit_chapter",
                    story_to_read=story_to_read,
                    chapter_number=chapter_number))
    elif len(request.form['editor']) < 50:
        flash("Chapter length must be 50 characters or more!")
        return redirect(
            url_for("edit_chapter",
                    story_to_read=story_to_read,
                    chapter_number=chapter_number))
    else:
        story = stories_collection.find_one({'url': story_to_read})
        chapters = story['chapters']
        chapter_index = int(chapter_number) - 1
        chapters[chapter_index]['chapter_title'] = request.form[
            'chapter_title']
        chapters[chapter_index]['chapter_content'] = json.loads(
            request.form['editor'])
        stories_collection.find_one_and_update(
            {"url": story_to_read}, {"$set": {
                "chapters": chapters
            }},
            upsert=True)

        return redirect(
            url_for('read',
                    story_to_read=story_to_read,
                    chapter_number=chapter_number))