Restructure code. Add frontend template. (logic to be done)

This commit is contained in:
siulkilulki 2018-05-04 23:25:07 +02:00
parent 6982ac2e59
commit c617018611
4 changed files with 80 additions and 10 deletions

View File

@ -1,9 +0,0 @@
from flask import Flask
app = Flask(__name__)
@app.route("/")
def hello():
return "<h1 style='color:blue'>Hello There!</h1>"
if __name__ == "__main__":
app.run(host='0.0.0.0')

24
webapp/app.py Normal file
View File

@ -0,0 +1,24 @@
from flask import Flask, render_template, request
app = Flask(__name__)
def post_action():
return get_action()
def get_action():
hour = '12.00'
left_context = 'Dawno, dawno temu był sobia para młoda, bardzo piękna para młoda. Msza rozpocznie się o godzinie '
right_context = '. Następnie para młoda uda się na wesele do Kubusia i będą się bawić do białego rana.'
return render_template('index.html', hour=hour, left_context=left_context, right_context=right_context)
@app.route("/", methods=['GET', 'POST'])
def root():
if request.method == 'POST':
return post_action()
else:
return get_action()
if __name__ == "__main__":
app.run(host='0.0.0.0', debug=True)

View File

@ -0,0 +1,55 @@
<!doctype html>
<html lang="pl">
<head>
<!-- Required meta tags -->
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=yes">
<!-- Bootstrap CSS -->
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.1/css/bootstrap.min.css" integrity="sha384-WskhaSGFgHYWDcbwN70/dfYBj47jz9qbsMId/iRN3ewGhXQFZCSftd1LZCfmhktB" crossorigin="anonymous">
<title>Annotator mszy świętych</title>
</head>
<body>
<div class="container">
<div class="container mt-1">
<div class="row justify-content-start">
<button type="button" class="btn btn-warning btn-sm" id="cofnij">Cofinj</button>
</div>
<div class="row justify-content-center">
<h2>Czy zaznaczono godzinę mszy świętej?</h2>
</div>
<div class="row justify-content-center">
<div class="jumbotron my-auto">
<p class="lead">{{ left_context }}<strong class="bg-warning h4">{{ hour }}</strong>{{right_context}}</p>
</div>
</div>
</div>
<div class="btn-group d-flex h-mx" role="group">
<button type="button" class="btn btn-danger btn-lg w-100" id="nie">Nie</button>
<button type="button" class="btn btn-success btn-lg w-100" id="tak">Tak</button>
</div>
</div>
<!-- Optional JavaScript -->
<!-- jQuery first, then Popper.js, then Bootstrap JS -->
<script src="https://code.jquery.com/jquery-3.3.1.min.js" integrity="sha256-FgpCb/KJQlLNfOu91ta32o/NMZxltwRo8QtmkMRdAu8=" crossorigin="anonymous"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.3/umd/popper.min.js" integrity="sha384-ZMP7rVo3mIykV+2+9J3UJ46jBk0WLaUAdn689aCwoqbBJiSnjAK/l8WvCWPIPm49" crossorigin="anonymous"></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.1.1/js/bootstrap.min.js" integrity="sha384-smHYKdLADwkXOn1EmN1qk/HfnUcbVRZyYmZ4qpPea6sjB/pTJ0euyQp0Mk8ck+5T" crossorigin="anonymous"></script>
<script type="text/javascript">
$("button#tak").click(function(){
$.post( "/", {result: "yes"}, function() {
console.log( "success" );
})
.done(function() {
console.log( "second success" );
})
.fail(function() {
console.log( "error" );
})
.always(function() {
console.log( "finished" );
});
});
</script>
</body>
</html>

View File

@ -1,4 +1,4 @@
from app import app from webapp.app import app
if __name__ == "__main__": if __name__ == "__main__":
app.run() app.run()