added add to stack first part

geo
Alice 7 years ago
parent 11f82645bf
commit 7beca18eb7

@ -34,6 +34,9 @@ class StackForm(FlaskForm):
stack_description = StringField('Description', validators=[InputRequired()]) stack_description = StringField('Description', validators=[InputRequired()])
create = SubmitField(label='Create') create = SubmitField(label='Create')
class AddtoStackForm(FlaskForm):
select = SelectField('Stacks', validators=[InputRequired()])
class SearchForm(FlaskForm): class SearchForm(FlaskForm):
choices = [('All', 'All'), choices = [('All', 'All'),
('Title', 'Title'), ('Title', 'Title'),

@ -97,10 +97,17 @@ background-color: #E8E8E8!important;
.library_table li{ .library_table li{
list-style-type:none; list-style-type:none;
text-align: center;
padding-right: 5px; padding-right: 5px;
display: inline-block; display: inline-block;
} }
#plus {
text-align: center;
font-size: 10px;
}
.library_table tr:nth-child(even){ .library_table tr:nth-child(even){
background-color: #fafafa; background-color: #fafafa;
} }

@ -0,0 +1,36 @@
{% extends 'base.html' %}
{% block main %}
<div class="container">
<!-- {% from "_formhelpers.html" import render_field %}
<h1 class="page-header">Add Stack</h1>
{% with messages = get_flashed_messages() %}
{% if messages %}
<div class="alert alert-danger">
<ul>
{% for message in messages %}
<li>{{ message }}</li>
{% endfor %}
</ul>
</div>
{% endif %}
{% endwith %} -->
<form method="POST" action="{{ url_for('add_stack') }}" enctype=multipart/form-data>
{{form.hidden_tag()}}
<br>
{{ render_field(form.stack_name)}}
{{ render_field(form.stack_description)}}
<button type="submit" class='button'>Create</button>
</form>
</div>
{% endblock %}

@ -0,0 +1,44 @@
{% extends 'base.html' %}
{% block main %}
<div class="container">
<div> Chosen book:
<h1 class="header">{{ book.title }}</h1>
<img class="no_cover" id="{{ book.title }}" src="../uploads/cover/{{ book.cover }}" width="150" onerror="if (this.src != '../static/img/{{ book.cover }}') this.src = '../static/img/default_cover.png';">
</div>
<p>These are all the stacks that have been built so far.</p>
<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>
<p><a href= {{ url_for('add_stack') }}>Add Stack</a></p>
<div id="draggable" class="ui-widget-content">
<p>List of books</p>
</div>
<div id="droppable" class="ui-widget-header">
<p>Stack</p>
</div>
</div>
{% endblock %}

@ -32,6 +32,7 @@
<th>Filetype</th> <th>Filetype</th>
<th>Category</th> <th>Category</th>
<th>Stack</th> <th>Stack</th>
<th>Add to stack</th>
</tr> </tr>
</thead> </thead>
<tbody> <tbody>
@ -58,7 +59,18 @@
<li><a href="{{url_for('show_stack_by_id', id=stack.id)}}">{{ stack.stack_name }}</a> </li> <li><a href="{{url_for('show_stack_by_id', id=stack.id)}}">{{ stack.stack_name }}</a> </li>
{% endfor %} {% endfor %}
</td> </td>
<td id='plus'><a href='{{url_for('add_to_stack', id=book.id)}}'>
\│/<br>
─ ─ <br>
/│\<br>
</a></td>
</tr> </tr>
{% endfor %} {% endfor %}

@ -0,0 +1,18 @@
{% block main %}
<div class="container">
<h1 class="header">{{ stack.stack_name }}</h1>
<p>Stack description: {{ stack.stack_description }} </p>
<p>Books in this stack: {% for book in stack.books %}
<li> <a href="{{url_for('show_book_by_id', id=book.id)}}">{{book.title}}</a> </li>
{% endfor %}</p>
</div>
{% endblock %}

@ -9,7 +9,7 @@ from app import app, db, socketio, DOMAIN
from flask import Flask, Response, render_template, request, redirect, url_for, flash, send_from_directory, jsonify, abort from flask import Flask, Response, render_template, request, redirect, url_for, flash, send_from_directory, jsonify, abort
import json import json
from sqlalchemy.sql.expression import func, select from sqlalchemy.sql.expression import func, select
from app.forms import UploadForm, EditForm, SearchForm, ChatForm, StackForm from app.forms import UploadForm, EditForm, SearchForm, ChatForm, StackForm, AddtoStackForm
from app.models import Book, BookSchema, Author, AuthorSchema, Stack, StackSchema, UserIns, Chat, ChatSchema from app.models import Book, BookSchema, Author, AuthorSchema, Stack, StackSchema, UserIns, Chat, ChatSchema
from app.cover import get_cover from app.cover import get_cover
from os import environ from os import environ
@ -267,8 +267,7 @@ def show_stacks():
def add_stack(): def add_stack():
form = StackForm() form = StackForm()
stacks = db.session.query(Stack).all() stacks = db.session.query(Stack).all()
#if request.method == 'GET':
# return render_template('add_stack.html', stacks=stacks, form=form)
if request.method == 'POST': if request.method == 'POST':
stack_name = form.stack_name.data stack_name = form.stack_name.data
stack_description = form.stack_description.data stack_description = form.stack_description.data
@ -372,6 +371,14 @@ 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>')
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)
### ###
# The API # The API

Loading…
Cancel
Save