Browse Source

add to stacks

ansible-setup-and-deploy
Alice 7 years ago
parent
commit
cd0edeca92
  1. 4
      app/forms.py
  2. 2
      app/models.py
  3. 17
      app/templates/add_to_stacks.html
  4. 31
      app/views.py

4
app/forms.py

@ -35,8 +35,8 @@ class StackForm(FlaskForm):
create = SubmitField(label='Create')
class AddtoStackForm(FlaskForm):
select = SelectField('Stacks', validators=[InputRequired()])
select_stack = SelectField('Stacks', validators=[InputRequired()])
class SearchForm(FlaskForm):
choices = [('All', 'All'),
('Title', 'Title'),

2
app/models.py

@ -97,7 +97,7 @@ class Stack(db.Model):
self.stack_description = stack_description
def __repr__(self):
return '<Stack %r>' % self.stack
return '<Stack %r>' % self.stack_name
class AuthorSchema(Schema):
id = fields.Int(dump_only=True)

17
app/templates/add_to_stacks.html

@ -10,21 +10,14 @@
</div>
<p>These are all the stacks that have been built so far.</p>
{% from "_formhelpers.html" import render_field %}
<form method="POST">
<div class="search"> {{ render_field(add_form.select_stack) }} </div>
<button type="submit" class="button" value="Stack" name="add_book">Add to stack</button>
</form>
<table style="width:100%">
<ul>
{% for stack in stacks %}
<li> <a href="stacks/tab/{{ stack.id }}">{{ stack.stack_name }}</a></td>
{% endfor %}
</ul>
<br>
<br>
<h1 class="page-header">Build a stack</h1>

31
app/views.py

@ -276,19 +276,6 @@ def add_stack():
stack = Stack(stack_name, stack_description)
db.session.add(stack)
stacks = db.session.query(Stack).all()
#this potentially deals with the connection between books and stacks
#book = Book(title, filename, cover, file_extension, category,year_published)
#for book in books:
# book_title = book.get("title")
# if book_title:
# a = db.session.query(Book).filter_by(book_title=book_title).first()
# if a == None:
# a = Book(book_title=book_title)
# db.session.add(a)
# stacks.book.append(a)
#db.session.commit()
flash("%s stack created" % (stack_name))
return render_template('add_stack.html', stacks=stacks, form=form)
@ -371,14 +358,20 @@ def test1():
return Response(json.dumps(autocomplete_suggestions), mimetype='application/json')
@app.route('/add_to_stack/<int:id>')
@app.route('/add_to_stack/<int:id>', methods=['GET', 'POST'])
def add_to_stack(id):
stacks = db.session.query(Stack).all()
book = Book.query.get(id)
add = AddtoStackForm(request.form)
return render_template('add_to_stacks.html', id=id, stacks=stacks, book=book, add=add)
add_form = AddtoStackForm(request.form)
add_form.select_stack.choices = [(stack.id, stack.stack_name) for stack in stacks]
if request.method == 'GET':
book = Book.query.get(id)
return render_template('add_to_stacks.html', id=id, stacks=stacks, book=book, add_form=add_form)
else:
stack = Stack.query.get(int(add_form.select_stack.data))
book = Book.query.get(id)
stack.books.append(book)
db.session.commit()
return render_template('show_stack_detail.html', stack=stack)
###
# The API

Loading…
Cancel
Save