def create(): form_errors = None conn, cur = get_sql() if request.method == 'POST': for k,v in request.form.iteritems(): print k,v form_errors = collect_form_errors(request.form) if not len(form_errors) > 1: form_items = {} for k, v in request.form.iteritems(): print "key = {} value = {}".format(k,v) if (k == 'editor1'): form_items['html'] = request.form[k] elif (k == 'file'): form_items['preview'] = request.form[k] elif (v != ''): form_items[k] = v form_items['author'] = session.get('current_user') form_items['date_added'] = int(time()) tid = insert_row('template', form_items, conn, cur) if not tid: return render_template('server_error.html') return redirect(url_for('templates.edit', tid=tid)) return render_template('templates/details.html', form_errors=form_errors)
def create(): form_errors = None conn, cur = get_sql() if request.method == "POST": form_errors = collect_form_errors(request.form) if not form_errors: form_items = {} for k, v in request.form.iteritems(): if v != "": form_items[k] = v form_items["author"] = session.get("current_user") form_items["date_added"] = int(time()) lid = insert_row("list", form_items, conn, cur) if not lid: return render_template("server_error.html") return redirect(url_for("lists.edit", lid=lid)) return render_template("lists/details.html", form_errors=form_errors, editing=False)
def create(): form_errors = None conn, cur = get_sql() companies = get_companies(conn, cur) staff = get_staff(conn, cur) if request.method == 'POST': form_errors = collect_form_errors(request.form) if not form_errors: form_items = {} for k, v in request.form.iteritems(): if (v != '' and k[len(k) - 3:] != 'sel'): form_items[k] = v form_items['author'] = session.get('current_user') form_items['date_added'] = int(time()) nid = insert_row('newsletter', form_items, conn, cur) if not nid: return render_template('server_error.html') return redirect(url_for('lists.index', nid=nid)) return render_template('newsletters/details.html', companies=companies, staff=staff, form_errors=form_errors)
def edit(): form_errors = None conn, cur = get_sql() companies = get_companies(conn, cur) staff = get_staff(conn, cur) # for k,v in request.args.iteritems(): # print k,v if request.method == 'GET': nid = request.args.get('nid') cur.execute('SELECT * FROM `newsletter` WHERE newsletter_id = %d' % int(nid)) res = cur.fetchone() if res: cols = tuple([d[0].decode('utf8') for d in cur.description]) newsletter = dict(zip(cols, res)) company_name = cur.execute("""SELECT name FROM company WHERE company_id = %d""" % int(newsletter['company'])) comp_name = cur.fetchone()[0] newsletter['company'] = (newsletter['company'], comp_name) return render_template('newsletters/details.html', newsletter=newsletter, staff=staff, companies=companies, nid=nid) return render_template('404.html') if request.method == 'POST': nid = request.args.get('nid') form_errors = collect_form_errors(request.form) if not form_errors: form_items = {} for k, v in request.form.iteritems(): if (v != '' and k[len(k) - 3:] != 'sel'): form_items[k] = v form_items['date_added'] = int(time()) nid = update_row('newsletter', form_items, conn, cur, nid) if not nid: return render_template('server_error.html') return redirect(url_for('lists.index', nid=nid)) return render_template('newsletters/details.html', newsletter=newsletter, staff=staff, companies=companies, nid=nid, form_errors=form_errors)