示例#1
0
def edit_application(application_id):
    next_url = request.args.get('next') or url_for('pages.index')
    if request.method == 'GET':
        app = Applications.fetch_one(application_id)
        if app is None:
            flash('Invalid application')
            return redirect(url_for('pages.applications'))

        if app['user']['id'] != g.user.id:
            flash('Application not found for user')
            return redirect(url_for('pages.applications'))

        return render_template('application.html', next_url=next_url, application=app)
    else:
        application_id = application_id
        title = request.form.get('title')
        description = request.form.get('description')
        link = request.form.get('link')

        if title is None or description is None:
            flash('Please fill all the mandatory fields.')
            return redirect(url_for('pages.new_application'))

        Applications.update(application_id, title, description, link)

        flash("Application details updated successfully")
        return redirect(url_for('pages.applications'))
示例#2
0
def delete_application(application_id):
    next_url = request.args.get('next') or url_for('pages.index')
    if request.method == 'GET':
        app = Applications.fetch_one(application_id)

        if app is None:
            flash('Invalid application')
            return redirect(url_for('pages.applications'))

        if app['user']['id'] != g.user.id:
            flash('Application not found for user')
            return redirect(url_for('pages.applications'))

        Applications.delete_one(application_id)
        return redirect(url_for('pages.applications'))