tried to add edit

This commit is contained in:
Alice 2018-06-05 18:26:25 +02:00
parent 2ff2b6e9f0
commit 9a2bc3892f
9 changed files with 67 additions and 13 deletions

View File

@ -25,6 +25,7 @@ class EditForm(FlaskForm):
author = FieldList(FormField(AuthorForm, default=lambda: Author()), min_entries=1) author = FieldList(FormField(AuthorForm, default=lambda: Author()), min_entries=1)
category = StringField('category', validators=[InputRequired()]) category = StringField('category', validators=[InputRequired()])
year_published = StringField('year published', [validators.Length(max=4)],default=None) year_published = StringField('year published', [validators.Length(max=4)],default=None)
class ChatForm(FlaskForm): class ChatForm(FlaskForm):
message = StringField('message', validators=[InputRequired()]) message = StringField('message', validators=[InputRequired()])
send = SubmitField(label='Send') send = SubmitField(label='Send')
@ -36,7 +37,11 @@ class StackForm(FlaskForm):
class AddtoStackForm(FlaskForm): class AddtoStackForm(FlaskForm):
select_stack = SelectField('Stacks', validators=[InputRequired()]) select_stack = SelectField('Stacks', validators=[InputRequired()])
class EditStackForm(FlaskForm):
edit_stack_name = SelectField('Stack', validators=[InputRequired()])
edit_stack_description = SelectField('Description', validators=[InputRequired()])
class SearchForm(FlaskForm): class SearchForm(FlaskForm):
choices = [('All', 'All'), choices = [('All', 'All'),
('Title', 'Title'), ('Title', 'Title'),

View File

@ -0,0 +1,22 @@
{% extends 'base.html' %}
{% block main %}
<div class="container">
{% from "_formhelpers.html" import render_field %}
<form method="POST" action="{{ url_for('edit_stack_by_id', id=stack.id )}}">
{{ form.csrf_token }}
<br> <br>
<table>
<tr>
{{ render_field(form.edit_stack_name)}}
{{ render_field(form.edit_stack_description)}}
</tr>
<br>
<button type="submit" class="btn btn-primary">Update</button>
</form>
</div>
{% endblock %}

View File

@ -33,6 +33,8 @@
<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>
{% for book in books %} {% for book in books %}
<tr> <tr>
@ -51,6 +53,10 @@
<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)}}'>
==>
</a></td>
{% endfor %} {% endfor %}
</table> </table>
@ -68,6 +74,8 @@
<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>
{% for book in books_all %} {% for book in books_all %}
<tr> <tr>
@ -86,6 +94,9 @@
<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)}}'>
==>
</a></td>
{% endfor %} {% endfor %}
</table> </table>
<p> <p>

View File

@ -62,15 +62,8 @@
</td> </td>
<td id='plus'><a href='{{url_for('add_to_stack', id=book.id)}}'> <td id='plus'><a href='{{url_for('add_to_stack', id=book.id)}}'>
\│/<br> ==>
─ ─ <br>
/│\<br>
</a></td> </a></td>
</tr> </tr>
{% endfor %} {% endfor %}

View File

@ -18,6 +18,8 @@
<br> <br>
<p> <p>
<a href="{{ url_for('remove_stack_by_id', id=stack.id )}}">Delete</a> </p> <a href="{{ url_for('remove_stack_by_id', id=stack.id )}}">Delete</a> </p>
<a href="{{ url_for('edit_stack_by_id', id=stack.id )}}">Edit</a> </p>
<p><a href="{{url_for('show_stacks')}}">Go back to stacks</p> <p><a href="{{url_for('show_stacks')}}">Go back to stacks</p>

View File

@ -1,7 +1,12 @@
{% block main %} {% block main %}
<div class="container"> <div class="container">
<h1 class="header">{{ stack.stack_name }}</h1> <h1 class="header">
<a href="{{url_for('show_stack_by_id', id=stack.id)}}">
{{ stack.stack_name }} </a>
</h1>
<p>Stack description: {{ stack.stack_description }} </p> <p>Stack description: {{ stack.stack_description }} </p>

View File

@ -11,7 +11,11 @@
<ul> <ul>
{% for stack in stacks %} {% for stack in stacks %}
<li> <a href="stacks/tab/{{ stack.id }}">{{ stack.stack_name }}</a></td> <li> <a href="stacks/tab/{{ stack.id }}">
{{ stack.stack_name }}
</a></td>

View File

@ -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, AddtoStackForm from app.forms import UploadForm, EditForm, SearchForm, ChatForm, StackForm, AddtoStackForm, EditStackForm
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
@ -303,6 +303,18 @@ def remove_stack_by_id(id):
db.session.commit() db.session.commit()
return redirect(url_for('show_stacks')) return redirect(url_for('show_stacks'))
@app.route('/stacks/<int:id>/edit', methods=['POST', 'GET'])
def edit_stack_by_id(id):
stack = Stack.query.filter_by(id=id).first()
form = EditStackForm()
if request.method == 'POST':
if edit_stack_form.validate_on_submit():
stack_name = form.stack_name.data
stack_description = form.stack_description.data
db.session.commit()
return redirect(url_for('show_stack_by_id', id=id))
return render_template('edit_stack_detail.html', stack=stack, form=form)
## search ## search
## search ## search

View File

@ -39,7 +39,7 @@ with open(args.csv) as f:
if stack: if stack:
b = db.session.query(Stack).filter_by(stack_name=stack).first() b = db.session.query(Stack).filter_by(stack_name=stack).first()
if b == None: if b == None:
b = Stack(stack_name=stack, stack_description="test") b = Stack(stack_name=stack, stack_description=stack_description)
db.session.add(b) db.session.add(b)
book.stacks.append(b) book.stacks.append(b)