Exemple #1
0
def edit_ideas(id):
    """
    Edit an Idea
    """
    check_admin()

    add_ideas = False

    ideas = IdeaTable.query.get_or_404(id)
    form = IdeaForm(obj=ideas)
    if form.validate_on_submit():
        ideas.title = form.title.data
        ideas.description = form.description.data
        db.session.commit()
        flash('You have successfully edited this Idea.')

        # redirect to the departments page
        return redirect(url_for('admin.list_ideas'))

    form.description.data = ideas.description
    form.title.data = ideas.title
    return render_template('admin/ideas/idea.html',
                           action="Edit",
                           add_ideas=add_ideas,
                           form=form,
                           ideas=ideas,
                           title="Edit Ideas")
Exemple #2
0
def add_ideas():
    """
    Add an Idea to the database
    """
    # check_admin()

    add_ideas = True

    form = IdeaForm()
    if form.validate_on_submit():
        idea = IdeaTable(title=form.title.data,
                         description=form.description.data)
        try:
            # add idea to the database
            db.session.add(idea)
            db.session.commit()
            flash('You have successfully added a new Idea.')
        except:
            # in case idea name already exists
            flash('Error: department name already exists.')

        # redirect to departments page
        return redirect(url_for('admin.list_ideas'))

    # load department template
    return render_template('admin/ideas/idea.html',
                           action="Add",
                           add_ideas=add_ideas,
                           form=form,
                           title="Create Ideas")
Exemple #3
0
def new_idea():
    form = IdeaForm()

    if request.method == 'POST' and form.validate_on_submit():
        user_id = session.get('user_id')
        if not user_id:
            abort(403)
        user = User.query.filter_by(id=int(user_id)).first()
        idea = Idea(title=form.title.data,
                    body=form.body.data,
                    user=user)
        db.session.add(idea)
        db.session.commit()
        return redirect(url_for('get_feed'))
    return render_template('new_idea.html', form=form)