Commits

Kenneth Love  committed c525de0 Merge

merge

  • Participants
  • Parent commits f30088d, 37e2001

Comments (0)

Files changed (2)

     key_name = TextField('Key', validators=[Required()])
     key_value = TextField('Value', validators=[Required()])
 
+class SetForm(Form):
+    """
+    Form for creating a new set
+    """
+    key_name = TextField('Key', validators=[Required()])
+    member = TextField('Member', validators=[Required()])
+
 @app.context_processor
 def get_db_size():
     r = get_redis_connection(session)
     else:
         return render_template('new_string.html', form=form)
 
+@app.route('/key/new/set', methods=['GET', 'POST'])
+def new_set():
+    """
+    View for creating a new set/member
+    """
+    form = SetForm(request.form or None)
+    if form.validate_on_submit():
+        key = request.form['key_name']
+        member = request.form['member']
+
+        r = get_redis_connection(session)
+        if not r:
+            return redirect(url_for('setup'))
+
+        result = r.sadd(key, member)
+
+        if result:
+            flash('%s was created.' % key)
+        else:
+            flash('%s already contains that member. Nothing changed.' % key)
+        return redirect('#%s' % key)
+
+    return render_template('new_set.html', form=form)
+
 @app.route('/key/delete/<key>', methods=['GET'])
 def delete(key):
     """ Delete key """

File templates/new_set.html

+{% extends "layout.html" %}
+{% block leftblock %}
+<article>
+	<header>
+		<h1>Add New Set</h1>
+	</header>
+	{% from "_partials.html" import render_field %}
+	<form action="/key/new/set" method="post" id="new_key_form">
+		{{ form.csrf }}
+		{{ render_field(form.key_name) }}
+		{{ render_field(form.member) }}
+		<input type="submit" value="Submit">
+	</form>
+
+</article>
+{% endblock %}