コード例 #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'))
コード例 #3
0
def new_application():
    next_url = request.args.get('next') or url_for('pages.index')
    if request.method == 'GET':
        return render_template('share.html', next_url=next_url)
    else:
        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.create(g.user, title, description, link)

        flash("Your application is successfully published")
        return redirect(url_for('pages.applications'))
コード例 #4
0
def user_applications():
    next_url = request.args.get('next') or url_for('pages.index')
    user_id = g.user.id
    apps = Applications.fetch(user_id)
    return render_template('applications.html', next_url=next_url, applications=apps)
コード例 #5
0
def applications():
    apps = Applications.fetch_all()
    return render_template('applications.html', applications=apps)