From d49738db2775a363d67d39b674542ee5fbcb91a9 Mon Sep 17 00:00:00 2001 From: nberting Date: Fri, 8 Jun 2018 16:15:09 +0200 Subject: [PATCH] connected search to chat --- app/models.py | 1 - app/static/css/style.css | 8 ++++---- app/templates/base.html | 2 +- app/templates/show_books.html | 6 +++++- app/views.py | 34 ++++++++++++++++++++++++++++++++-- run.py | 2 +- 6 files changed, 43 insertions(+), 10 deletions(-) diff --git a/app/models.py b/app/models.py index 80868ec..2a2939a 100755 --- a/app/models.py +++ b/app/models.py @@ -84,7 +84,6 @@ class Chat(db.Model): self.message = message self.time = datetime.datetime.utcnow() - class Stack(db.Model): __tablename__ = 'stacks' id = db.Column(db.Integer, primary_key = True) diff --git a/app/static/css/style.css b/app/static/css/style.css index de6ccad..02397ac 100755 --- a/app/static/css/style.css +++ b/app/static/css/style.css @@ -139,7 +139,7 @@ font-size: 18px; padding:6px 15px; left:0px; border:0px solid #dbdbdb; -background-color: grey; +background-color: #686d72; color:#fafafa; } @@ -225,7 +225,7 @@ div.marquee > div.marquee-text { padding: 10px; margin: 0px; height: 100%; - background-color: #551A8B; + background-color: #b4b9be; overflow-y: scroll; overflow-x: hidden; color: white; @@ -262,7 +262,7 @@ z-index: 100000; margin:0px!important; padding:0px!important; height: 40px; - font-size: 20px; + font-size: 16px; word-wrap: break-word; word-break: break-all; float: left; @@ -287,7 +287,7 @@ box-sizing: border-box; margin-top: 20px; } .messages .msg{ - font-size: 30px; + font-size: 24px; margin: 0px; margin-top: -15px; margin-bottom: 10px; diff --git a/app/templates/base.html b/app/templates/base.html index 76a7e06..44fb505 100755 --- a/app/templates/base.html +++ b/app/templates/base.html @@ -60,7 +60,7 @@ console.log(time) return ('0'+time.getDate()).slice(-2) + '.' + ('0'+(time.getMonth()+1)).slice(-2) + '.' + time.getFullYear() +" " + ('0'+time.getHours()).slice(-2)+":"+ ('0'+time.getMinutes()).slice(-2); } //change addr when ONLINE::::::-> -var socket = io.connect('http://localhost:5000'); +var socket = io.connect('http://localhost:8080'); var app = new Vue({ el: "#app", delimiters: ['[[', ']]'], diff --git a/app/templates/show_books.html b/app/templates/show_books.html index 69be928..04dbcc5 100755 --- a/app/templates/show_books.html +++ b/app/templates/show_books.html @@ -1,13 +1,17 @@ {% extends 'base.html' %} {% block main %} +
+ + {% from "_formhelpers.html" import render_field %}
{{ form.select(style="width: 100px; margin: 10px; float: left; font-size: 20px") }}
- + +


{{ form.grid(style="font-size:20px")}}{{ form.listview(style="font-size:20px")}}

diff --git a/app/views.py b/app/views.py index 2290a64..c32106f 100755 --- a/app/views.py +++ b/app/views.py @@ -45,6 +45,7 @@ def allowed_file(filename): def home(): chat_form = ChatForm() chat_messages = db.session.query(Chat).all() + username = 'librarian' # if request.method == 'POST': # if chat_form.validate_on_submit(): @@ -53,7 +54,7 @@ def home(): # db.session.add(msg) # db.session.commit() - return render_template('home.html',domain=DOMAIN,chat=chat_messages, channel = 1, username="librarian") + return render_template('home.html',domain=DOMAIN,chat=chat_messages, channel = 1, username=username) @app.route('/hello/') def hello(name): @@ -368,6 +369,23 @@ def show_books(): return render_template ('show_books.html', books=books, form=search) if request.method == 'POST': + newmsg = 'searched for: ' + search.search.data + # message = search.search.data + # newmessage = Chat(message) + # db.session.add(newmessage) + # db.session.commit() + # Send search to socket chat + socketio.emit('channel-' + str(1), { + 'username': 'Search form', + 'text': search.search.data, + 'time': str(datetime.datetime.utcnow().strftime("%d.%m.%Y %H:%M"))}, broadcast=True) + # Save message + my_new_chat = Chat(message=newmsg) + db.session.add(my_new_chat) + try: + db.session.commit() + except: + db.session.rollback() return redirect((url_for('search_results', searchtype=search.select.data, query=search.search.data, viewby=viewby))) return render_template('show_books.html', books=books, form=search) @@ -415,6 +433,19 @@ def search_results(searchtype, query, viewby): return render_template('results_grid.html', books=results, form=search, query=query, books_all=random_order, searchtype=search.select.data, count = count, whole = whole, percentage = percentage) if request.method == 'POST': + newmsg = 'searched for: ' + search.search.data + socketio.emit('channel-' + str(1), { + 'username': 'Search form', + 'text': search.search.data, + 'time': str(datetime.datetime.utcnow().strftime("%d.%m.%Y %H:%M"))}, broadcast=True) + # Save message + my_new_chat = Chat(message=newmsg) + db.session.add(my_new_chat) + try: + db.session.commit() + except: + db.session.rollback() + query = search.search.data results = [] if viewby == '1': @@ -562,7 +593,6 @@ def new_message(message): db.session.rollback() - if __name__ == '__main__': socketio.run(app) #app.run(debug=True,host="0.0.0.0",port="8080") diff --git a/run.py b/run.py index 2ba00ff..9b2708e 100755 --- a/run.py +++ b/run.py @@ -1,4 +1,4 @@ #! /usr/bin/env python from app import app, socketio -socketio.run(app) +socketio.run(app, port=8080) #app.run(debug=True,host="0.0.0.0",port=8080)