add to stacks
This commit is contained in:
parent
7beca18eb7
commit
cd0edeca92
@ -35,7 +35,7 @@ class StackForm(FlaskForm):
|
|||||||
create = SubmitField(label='Create')
|
create = SubmitField(label='Create')
|
||||||
|
|
||||||
class AddtoStackForm(FlaskForm):
|
class AddtoStackForm(FlaskForm):
|
||||||
select = SelectField('Stacks', validators=[InputRequired()])
|
select_stack = SelectField('Stacks', validators=[InputRequired()])
|
||||||
|
|
||||||
class SearchForm(FlaskForm):
|
class SearchForm(FlaskForm):
|
||||||
choices = [('All', 'All'),
|
choices = [('All', 'All'),
|
||||||
|
@ -97,7 +97,7 @@ class Stack(db.Model):
|
|||||||
self.stack_description = stack_description
|
self.stack_description = stack_description
|
||||||
|
|
||||||
def __repr__(self):
|
def __repr__(self):
|
||||||
return '<Stack %r>' % self.stack
|
return '<Stack %r>' % self.stack_name
|
||||||
|
|
||||||
class AuthorSchema(Schema):
|
class AuthorSchema(Schema):
|
||||||
id = fields.Int(dump_only=True)
|
id = fields.Int(dump_only=True)
|
||||||
|
@ -10,19 +10,12 @@
|
|||||||
|
|
||||||
</div>
|
</div>
|
||||||
<p>These are all the stacks that have been built so far.</p>
|
<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>
|
||||||
|
31
app/views.py
31
app/views.py
@ -276,19 +276,6 @@ def add_stack():
|
|||||||
stack = Stack(stack_name, stack_description)
|
stack = Stack(stack_name, stack_description)
|
||||||
db.session.add(stack)
|
db.session.add(stack)
|
||||||
stacks = db.session.query(Stack).all()
|
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))
|
flash("%s stack created" % (stack_name))
|
||||||
return render_template('add_stack.html', stacks=stacks, form=form)
|
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')
|
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):
|
def add_to_stack(id):
|
||||||
stacks = db.session.query(Stack).all()
|
stacks = db.session.query(Stack).all()
|
||||||
book = Book.query.get(id)
|
add_form = AddtoStackForm(request.form)
|
||||||
add = AddtoStackForm(request.form)
|
add_form.select_stack.choices = [(stack.id, stack.stack_name) for stack in stacks]
|
||||||
|
if request.method == 'GET':
|
||||||
return render_template('add_to_stacks.html', id=id, stacks=stacks, book=book, add=add)
|
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
|
# The API
|
||||||
|
Loading…
Reference in New Issue
Block a user