update upload form extra questions

This commit is contained in:
nberting 2018-06-11 17:24:30 +02:00
parent 644ed7d621
commit f1b27bff5d
7 changed files with 94 additions and 40 deletions

View File

@ -25,7 +25,6 @@ class UploadForm(FlaskForm):
sameness = DecimalRangeField('sameness', default=0) sameness = DecimalRangeField('sameness', default=0)
diversity = DecimalRangeField('diversity', default=0) diversity = DecimalRangeField('diversity', default=0)
gender = DecimalRangeField('gender', default=50) gender = DecimalRangeField('gender', default=50)
time = StringField('time', [validators.Length(max=5)],default=None)
choices = [('Student', 'Student'), choices = [('Student', 'Student'),
('Librarian', 'Librarian'), ('Librarian', 'Librarian'),
('Pirate', 'Pirate'), ('Pirate', 'Pirate'),
@ -43,6 +42,17 @@ class EditForm(FlaskForm):
year_published = StringField('year published', [validators.Length(max=4)],default=None) year_published = StringField('year published', [validators.Length(max=4)],default=None)
file = FileField() file = FileField()
message = StringField('message') message = StringField('message')
sameness = DecimalRangeField('sameness', default=0)
diversity = DecimalRangeField('diversity', default=0)
gender = DecimalRangeField('gender', default=50)
choices = [('Student', 'Student'),
('Librarian', 'Librarian'),
('Pirate', 'Pirate'),
('Teacher', 'Teacher'),
('Institution', 'Institution'),
('All of the above', 'All of the above'),
('None of the above', 'None of the above')]
who = SelectField('', choices=choices, default='Student')
class ChatForm(FlaskForm): class ChatForm(FlaskForm):
message = StringField('message', validators=[InputRequired()]) message = StringField('message', validators=[InputRequired()])

View File

@ -46,10 +46,9 @@ class Book(db.Model):
diversity = db.Column(db.Numeric()) diversity = db.Column(db.Numeric())
gender = db.Column(db.Numeric()) gender = db.Column(db.Numeric())
who = db.Column(db.String(255)) who = db.Column(db.String(255))
time = db.Column(db.Numeric())
def __init__(self, title, file, cover, fileformat, category, year_published, message, sameness, diversity, gender, who, time): def __init__(self, title, file, cover, fileformat, category, year_published, message, sameness, diversity, gender, who):
self.title = title self.title = title
self.file = file self.file = file
self.cover = cover self.cover = cover
@ -64,7 +63,6 @@ class Book(db.Model):
self.diversity = diversity self.diversity = diversity
self.gender = gender self.gender = gender
self.who = who self.who = who
self.time = time
def __repr__(self): def __repr__(self):

View File

@ -68,17 +68,12 @@ Check the bibliography. How diverse are the references in this book? <br>
<br><hr align="left" style="width:96%;"><br> <br><hr align="left" style="width:96%;"><br>
Check the writing. Who is speaking? Is the voice more often male or female? <br> Check the writing. Who is speaking? Is the voice more often male or female? <br>
{{ form.diversity(min=1, max=100, oninput="outputUpdate3(value)") }} &nbsp; {{ form.gender(min=1, max=100, oninput="outputUpdate3(value)") }} &nbsp;
<span style="color: #d3d3d3;"><output for="diversity" id="selected-gender">{{ form.gender.data }} </output> % female</span> <span style="color: #d3d3d3;"><output for="diversity" id="selected-gender">{{ form.gender.data }} </output> % female</span>
<br><hr align="left" style="width:96%;"><br> <br><hr align="left" style="width:96%;"><br>
Who are you? {{ render_field(form.who) }} Who are you? {{ render_field(form.who) }}
<br><hr align="left" style="width:96%;"><br>
How much time have you spent with this item?
Include the time spent looking for it, and uploading it.<br>
{{ form.time (size = 50, class="form-control")}} <span style="color: #d3d3d3;">hours</span>
<br>
<br><hr align="left" style="width:96%;"><br> <br><hr align="left" style="width:96%;"><br>
<div style="width: 40%;"> <div style="width: 40%;">

View File

@ -1,22 +1,36 @@
{% extends 'base.html' %} {% extends 'base.html' %}
{% block main %} {% block main %}
{% from "_formhelpers.html" import render_field %}
<head>
<script>
function outputUpdate(sameness) {
document.querySelector('#selected-sameness').value = sameness;
}
function outputUpdate2(diversity) {
document.querySelector('#selected-diversity').value = diversity;
}
function outputUpdate3(gender) {
document.querySelector('#selected-gender').value = gender;
}
</script>
</head>
<div class="container"> <div class="container">
<a href="{{ url_for('show_book_by_id', id=book.id )}}">back</a> <a href="{{ url_for('show_book_by_id', id=book.id )}}">back</a>
<form method="POST" action="{{ url_for('edit_book_by_id', id=book.id )}}" enctype=multipart/form-data> <form method="POST" action="{{ url_for('edit_book_by_id', id=book.id )}}" enctype=multipart/form-data>
{{ form.csrf_token }} {{ form.csrf_token }}
<div class="form-group"><h1 class="header">{{ form.title.label }} {{ form.title(size=20, class="form-control") }}</h1></div> <div class="form-group"><h1 class="header">{{ form.title.label }} {{ form.title(size=20, class="form-control") }}</h1></div>
<img class="no_cover" id="{{ book.title }}" src="/uploads/cover/{{ book.cover }}" width="150" onerror="if (this.src != '/uploads/cover/{{ book.cover }}') this.src = '/static/img/default_cover.gif';"> <div style="float:right; padding-right: 300px;">
<img class="no_cover" id="{{ book.title }}" src="../uploads/cover/{{ book.cover }}" width="280px" onerror="if (this.src != '/uploads/cover/{{ book.cover }}') this.src = '/static/img/default_cover.gif';"></div>
<br> <br> <br>
<div data-toggle="fieldset" id="phone-fieldset"> <div data-toggle="fieldset" id="phone-fieldset">
{{ form.author.label }} <button type="button" data-toggle="fieldset-add-row" {{ form.author.label }}*: <button type="button" data-toggle="fieldset-add-row"
data-target="#phone-fieldset">+</button> data-target="#phone-fieldset">+</button>
<table> <table>
<tr> <tr>
@ -25,28 +39,45 @@
</tr> </tr>
{% for author in form.author %} {% for author in form.author %}
<tr data-toggle="fieldset-entry"> <tr data-toggle="fieldset-entry">
<td>{{ author.author_name }}</td> <td>{{ author.author_name (size=50, class="form-control") }}</td>
<td><button type="button" data-toggle="fieldset-remove-row" id="phone-{{loop.index0}}-remove">-</button></td> <td><button type="button" data-toggle="fieldset-remove-row" id="phone-{{loop.index0}}-remove">-</button></td>
</tr> </tr>
{% endfor %} {% endfor %}
</table> </table><br>
</div><br> <br>
<div class="form-group" style="padding-bottom: 10px;"> Category:* <br> {{ form.category(size=50, class="form-control") }} <br><br>
Category: {{ form.category(size=20, Year published: <br> {{ form.year_published(size=8, class="form-control") }} <br><br>
class="form-control") }}
</div> How different is this item to the rest of the collection?
<div class="form-group" style="padding-bottom: 10px;"> Or is it more of the same? <br>
Year published: {{ form.year_published(size=8, class="form-control") }} {{ form.sameness(min=0, max=100, oninput="outputUpdate(value)") }} &nbsp;
</div> <span style="color: #d3d3d3;"><output for="sameness" id="selected-sameness">{{ form.sameness.data }} </output> % different</span>
<br><hr align="left" style="width:40%;"><br>
Check the bibliography. How diverse are the references in this book? <br>
{{ form.diversity(min=0, max=100, oninput="outputUpdate2(value)") }} &nbsp;
<span style="color: #d3d3d3;"><output for="diversity" id="selected-diversity">{{ form.diversity.data }} </output> % diverse</span>
<br><hr align="left" style="width:40%;"><br>
Check the writing. Who is speaking? Is the voice more often male or female? <br>
{{ form.gender(min=1, max=100, oninput="outputUpdate3(value)") }} &nbsp;
<span style="color: #d3d3d3;"><output for="diversity" id="selected-gender">{{ form.gender.data }} </output> % female</span>
<br><hr align="left" style="width:40%;"><br>
Who are you? {{ render_field(form.who)}}
<br><hr align="left" style="width:40%;"><br>
<div class="form-group" style="padding-bottom: 10px;"> <div class="form-group" style="padding-bottom: 10px;">
Current file: {{ book.file }} Current file: {{ book.file }} &nbsp;&nbsp;&nbsp;&nbsp; Upload new file: {{form.file}}
</div>
<div class="form-group" style="padding-bottom: 10px;">
Upload new file: {{form.file}}
</div> </div>
<div class="form-group" style="padding-bottom: 10px;"> <div class="form-group" style="padding-bottom: 10px;">
If uploading, write a new message: {{form.message(size=150, class="form-control") }} </div>
<div class="form-group" style="padding-bottom: 10px;">
If uploading, write a new message: <br>{{form.message(size=135, class="form-control") }}
</div> </div>
<br> <br>

View File

@ -1,6 +1,8 @@
{% extends 'base.html' %} {% extends 'base.html' %}
{% block main %} {% block main %}
<div class="container"> <div class="container">
<h1 class="header">{{ book.title }}</h1> <h1 class="header">{{ book.title }}</h1>
<div style="float:right; padding-right: 140px;"> <div style="float:right; padding-right: 140px;">
@ -58,10 +60,6 @@
<td>Who is uploading<br></td> <td>Who is uploading<br></td>
<td>{{ book.who or '?' }} </td> <td>{{ book.who or '?' }} </td>
</tr> </tr>
<tr>
<td>How much time has been spent with this item?<br></td>
<td>{{ book.time or '?' }} </td>
</tr>
</tbody> </tbody>
</table> </table>

View File

@ -172,7 +172,7 @@ def remove_book_by_id(id):
@app.route('/books/<int:id>/edit', methods=['POST', 'GET']) @app.route('/books/<int:id>/edit', methods=['POST', 'GET'])
def edit_book_by_id(id): def edit_book_by_id(id):
book_to_edit = Book.query.filter_by(id=id).first() book_to_edit = Book.query.filter_by(id=id).first()
user_form = EditForm(title = book_to_edit.title, author =book_to_edit.authors, category = book_to_edit.category, year_published= book_to_edit.year_published, message= book_to_edit.message) user_form = EditForm(title = book_to_edit.title, author =book_to_edit.authors, category = book_to_edit.category, year_published= book_to_edit.year_published, message= book_to_edit.message, sameness=book_to_edit.sameness, gender=book_to_edit.gender, diversity=book_to_edit.diversity, who=book_to_edit.who)
if request.method == 'POST': if request.method == 'POST':
if user_form.validate_on_submit(): if user_form.validate_on_submit():
@ -182,6 +182,11 @@ def edit_book_by_id(id):
category = user_form.category.data category = user_form.category.data
year_published = user_form.year_published.data year_published = user_form.year_published.data
message = user_form.message.data message = user_form.message.data
sameness = user_form.sameness.data
gender = user_form.gender.data
diversity = user_form.diversity.data
who = user_form.who.data
if year_published=="": if year_published=="":
year_published = None year_published = None
book = Book.query.filter_by(id=id).first() book = Book.query.filter_by(id=id).first()
@ -189,6 +194,10 @@ def edit_book_by_id(id):
book.category = category book.category = category
book.year_published = year_published book.year_published = year_published
book.message = message book.message = message
book.sameness = sameness
book.gender = gender
book.diversity = diversity
book.who = who
#authors update #authors update
book.authors.clear() book.authors.clear()
@ -258,7 +267,6 @@ def add_book():
sameness = upload_form.sameness.data sameness = upload_form.sameness.data
gender = upload_form.gender.data gender = upload_form.gender.data
diversity = upload_form.diversity.data diversity = upload_form.diversity.data
time = upload_form.time.data
who = upload_form.who.data who = upload_form.who.data
if year_published=="": if year_published=="":
@ -308,9 +316,8 @@ def add_book():
html_string = render_template('potential_pdf.html', pbooks = pbooks) html_string = render_template('potential_pdf.html', pbooks = pbooks)
html = HTML(string=html_string) html = HTML(string=html_string)
html.write_pdf(target='app/uploads/potential.pdf'); html.write_pdf(target='app/uploads/potential.pdf');
print ('potential_pdf')
book = Book(title, filename, cover, file_extension, category, year_published, message, sameness, diversity, gender, who, time) book = Book(title, filename, cover, file_extension, category, year_published, message, sameness, diversity, gender, who)
db.session.add(book) db.session.add(book)
for author in authors: for author in authors:
author_name = author.get("author_name") author_name = author.get("author_name")
@ -667,17 +674,32 @@ def import_csv():
print("allreadyexists") print("allreadyexists")
else: else:
cover = '' cover = ''
if row['file']: if row['file'] == '':
file = 'potential.pdf'
# file_extension = '.pdf'
# ptitle = row['title']
# pbook = Potential(ptitle)
# db.session.add(pbook)
# db.session.commit()
# pbooks = Potential.query.all()
# template = 'app/templates/potential_pdf.html'
# html_string = render_template('potential_pdf.html', pbooks = pbooks)
# html = HTML(string=html_string)
# html.write_pdf(target='app/uploads/potential.pdf')
# print ('writing to potential_pdf')
else:
fullpath = os.path.join(app.config['UPLOAD_FOLDER'], row['file']) fullpath = os.path.join(app.config['UPLOAD_FOLDER'], row['file'])
name, file_extension = os.path.splitext(row['file']) name, file_extension = os.path.splitext(row['file'])
print ('get_cover', fullpath, name) print ('get_cover', fullpath, name)
cover = get_cover(fullpath, name) cover = get_cover(fullpath, name)
file = str(id) + "_" + row['file']
if row['year_published']: if row['year_published']:
year_published = int(row['year_published']) year_published = int(row['year_published'])
else: else:
year_published = None; year_published = None;
book = Book(row['title'], row['file'], cover, row['fileformat'], row['category'],year_published, None, None, None, None, None, None) book = Book(row['title'], file, cover, row['fileformat'], row['category'],year_published, None, None, None, None, None)
book.scapeX = float(row['scapeX']) book.scapeX = float(row['scapeX'])
book.scapeY = float(row['scapeY']) book.scapeY = float(row['scapeY'])

View File

@ -20,7 +20,7 @@ with open(args.csv) as f:
print ('get_cover', fullpath, name) print ('get_cover', fullpath, name)
cover = get_cover(fullpath, name) cover = get_cover(fullpath, name)
book = Book(row['Title'], row['Filename'], cover, row['Format'], row['Category'], None, None, None, None, None, None, None) book = Book(row['Title'], row['Filename'], cover, row['Format'], row['Category'], None, None, None, None, None, None)
db.session.add(book) db.session.add(book)
authors = row['Author'].split(',') authors = row['Author'].split(',')