def new_application(): user = require_user() errors = [] title = 'New Application' if request.form.get('submit'): name = request.form.get('name') if not name: errors.append('Missing application name') version = request.form.get('version') if not version: errors.append('Missing version number') email = request.form.get('email') if not email: errors.append('Missing email address') if email and not is_valid_email(email): errors.append('Invalid email address') website = request.form.get('website') if website and not is_valid_url(website): errors.append('Invalid website URL') if not errors: insert_application(db.session.connection(), { 'name': name, 'version': version, 'email': email, 'website': website, 'account_id': user.id, }) db.session.commit() return redirect(url_for('.applications')) return render_template('new-application.html', title=title, form=request.form, errors=errors)
def new_application(): user = require_user() errors = [] title = 'New Application' if request.form.get('submit'): name = request.form.get('name') if not name: errors.append('Missing application name') version = request.form.get('version') if not version: errors.append('Missing version number') email = request.form.get('email') if email and not is_valid_email(email): errors.append('Invalid email address') website = request.form.get('website') if website and not is_valid_url(website): errors.append('Invalid website URL') if not errors: insert_application(db.session.connection(), { 'name': name, 'version': version, 'email': email, 'website': website, 'account_id': user.id, }) db.session.commit() return redirect(url_for('.applications')) return render_template('new-application.html', title=title, form=request.form, errors=errors)
def edit_application(application_id): user = require_user() conn = db.session.connection() application = conn.execute( """ SELECT * FROM application WHERE id = %s """, (application_id, )).fetchone() if application is None: abort(404) if user.id != application['account_id']: abort(404) errors = [] title = 'Edit Application' if request.form.get('submit'): form = request.form name = request.form.get('name') if not name: errors.append('Missing application name') version = request.form.get('version') if not version: errors.append('Missing version number') email = request.form.get('email') if email and not is_valid_email(email): errors.append('Invalid email address') website = request.form.get('website') if website and not is_valid_url(website): errors.append('Invalid website URL') if not errors: update_application( conn, application.id, { 'name': name, 'version': version, 'email': email, 'website': website, 'account_id': user.id, }) db.session.commit() return redirect( url_for('.application', application_id=application.id)) else: form = {} form['name'] = application['name'] form['version'] = application['version'] or '' form['email'] = application['email'] or '' form['website'] = application['website'] or '' return render_template('edit-application.html', title=title, form=form, errors=errors, app=application)
def edit_application(application_id): user = require_user() conn = db.session.connection() application = conn.execute(""" SELECT * FROM application WHERE id = %s """, (application_id,)).fetchone() if application is None: abort(404) if user.id != application['account_id']: abort(404) errors = [] title = 'Edit Applications' if request.form.get('submit'): form = request.form name = request.form.get('name') if not name: errors.append('Missing application name') version = request.form.get('version') if not version: errors.append('Missing version number') email = request.form.get('email') if email and not is_valid_email(email): errors.append('Invalid email address') website = request.form.get('website') if website and not is_valid_url(website): errors.append('Invalid website URL') if not errors: update_application(conn, application.id, { 'name': name, 'version': version, 'email': email, 'website': website, 'account_id': user.id, }) db.session.commit() return redirect(url_for('.applications')) else: form = {} form['name'] = application['name'] form['version'] = application['version'] or '' form['email'] = application['email'] or '' form['website'] = application['website'] or '' return render_template('edit-application.html', title=title, form=form, errors=errors, app=application)