예제 #1
0
def update_story(story_to_read):
    formatted_inputs = {}
    form_data = request.form
    for key in form_data:
        value_key = key
        key = key.split("-")
        key = key[0]
        if key in formatted_inputs:
            formatted_inputs[key].append(form_data[value_key])
        else:
            formatted_inputs[f"{key}"] = []
            formatted_inputs[key].append(form_data[value_key])
    genres = formatted_inputs.get("genre")
    if genres is None:
        genres = []
    if form_data["newgenre"] != "":
        genres.append(form_data.get("newgenre"))
    fandoms = formatted_inputs.get("fandom")
    if form_data["newfandom"] != "":
        fandoms.append(form_data.get("newfandom"))

    stories_collection.find_one_and_update({"url": story_to_read}, {
        "$set": {
            "title": request.form.get('title'),
            "summary": request.form.get('summary'),
            "author": session['username'],
            "genres": genres,
            "rating": request.form.get('rating'),
            "fandoms": fandoms,
            "disclaimer": request.form.get('disclaimer'),
        }
    })
    return redirect(url_for('profile', user=session['username']))
예제 #2
0
def add_chapter(story_url):
    chapter_title = request.form['chapter_title']
    if request.form['editor'] == '\"<p><br></p>\"':
        flash("You cannot send in empty posts!")
        return redirect(url_for("new_chapter", story_url=story_url))
    elif request.form['editor'] == "":
        flash("You cannot send in empty posts!")
        return redirect(url_for("new_chapter", story_url=story_url))
    elif len(request.form['editor']) < 50:
        flash("Chapter length must be 50 characters or more!")
        return redirect(url_for("new_chapter", story_url=story_url))
    else:
        chapter_content = json.loads(request.form['editor'])
        chapter_number = request.form['chapter_number']
        chapter = {
            "chapter_number": chapter_number,
            "chapter_title": chapter_title,
            "chapter_content": chapter_content
        }
        stories_collection.find_one_and_update(
            {"url": story_url}, {"$push": {
                "chapters": chapter
            }}, upsert=True)

        return redirect(
            url_for('read',
                    story_to_read=story_url,
                    chapter_number=chapter_number))
예제 #3
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"))
예제 #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"))
예제 #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))
예제 #6
0
def post_feedback(story_to_read, chapter_number):
    story = story_to_read
    chapter = chapter_number
    if request.form['editor'] == '\"<p><br></p>\"':
        flash("You cannot send in empty posts!")
    elif request.form['editor'] == "":
        flash("You cannot send in empty posts!")
    else:
        feedback = json.loads(request.form['editor'])
        posted_by = request.form['posted_by']
        feedback_post = {
            "fb_for_chapter": chapter,
            "posted_by": posted_by,
            "feedback_content": feedback
        }
        stories_collection.find_one_and_update(
            {"url": story}, {"$push": {
                "feedback": feedback_post
            }},
            upsert=True)
        flash("Feedback Posted")
    return redirect(
        url_for("display_fb_page", story_to_read=story,
                chapter_number=chapter))