Browse Source

added add to stack first part

ansible-setup-and-deploy
Alice 6 years ago
parent
commit
7beca18eb7
  1. 3
      app/forms.py
  2. 7
      app/static/css/style.css
  3. 36
      app/templates/add_stack.html
  4. 44
      app/templates/add_to_stacks.html
  5. 14
      app/templates/show_books.html
  6. 18
      app/templates/show_stack_detail_tab.html
  7. 13
      app/views.py

3
app/forms.py

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

7
app/static/css/style.css

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

36
app/templates/add_stack.html

@ -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 %}

44
app/templates/add_to_stacks.html

@ -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 %}

14
app/templates/show_books.html

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

18
app/templates/show_stack_detail_tab.html

@ -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 %}

13
app/views.py

@ -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
import json
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.cover import get_cover
from os import environ
@ -267,8 +267,7 @@ def show_stacks():
def add_stack():
form = StackForm()
stacks = db.session.query(Stack).all()
#if request.method == 'GET':
# return render_template('add_stack.html', stacks=stacks, form=form)
if request.method == 'POST':
stack_name = form.stack_name.data
stack_description = form.stack_description.data
@ -372,6 +371,14 @@ def test1():
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

Loading…
Cancel
Save