diff --git a/database/__init__.py b/database/__init__.py index ee9864c..007f2a5 100644 --- a/database/__init__.py +++ b/database/__init__.py @@ -6,7 +6,12 @@ webapp.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///database.db' db = SQLAlchemy(webapp) with webapp.app_context(): - with open('database/schema.sql', 'r') as f: - sql_script = f.read() - db.session.execute(text(sql_script)) - db.session.commit() + with open('database/schema.sql', 'r') as f: + sql = f.read() + connection = db.session.connection().connection + try: + cursor = connection.cursor() + cursor.executescript(sql) + cursor.close() + finally: + connection.close() diff --git a/database/message.py b/database/models.py similarity index 60% rename from database/message.py rename to database/models.py index 08be331..9223926 100644 --- a/database/message.py +++ b/database/models.py @@ -1,6 +1,10 @@ -# from webapp import db from database import db +class Humeur(db.Model): + id = db.Column(db.Integer, primary_key=True) + enable = db.Column(db.Boolean, default=True) + text = db.Column(db.String(200)) + class Message(db.Model): id = db.Column(db.Integer, primary_key=True) enable = db.Column(db.Boolean, default=False) diff --git a/database/schema.sql b/database/schema.sql index 833224d..01742cf 100644 --- a/database/schema.sql +++ b/database/schema.sql @@ -3,4 +3,10 @@ CREATE TABLE IF NOT EXISTS `message` ( `enable` BOOLEAN NOT NULL DEFAULT FALSE, `text` VARCHAR(256) NULL, periodicity INTEGER NULL -); \ No newline at end of file +); + +CREATE TABLE IF NOT EXISTS `humeur` ( + id INTEGER PRIMARY KEY AUTOINCREMENT, + `enable` BOOLEAN NOT NULL DEFAULT TRUE, + `text` VARCHAR(256) NULL +); diff --git a/webapp/__init__.py b/webapp/__init__.py index 1f5bac2..3adc80b 100644 --- a/webapp/__init__.py +++ b/webapp/__init__.py @@ -2,4 +2,4 @@ from flask import Flask webapp = Flask(__name__) -from webapp import commandes, index, messages, moderation +from webapp import commandes, index, humeurs, messages, moderation diff --git a/webapp/commandes.py b/webapp/commandes.py index c81a936..b764609 100644 --- a/webapp/commandes.py +++ b/webapp/commandes.py @@ -3,4 +3,4 @@ from webapp import webapp @webapp.route("/commandes") def commandes(): - return render_template("commandes.html") + return render_template("commandes.html") diff --git a/webapp/humeurs.py b/webapp/humeurs.py new file mode 100644 index 0000000..8fef853 --- /dev/null +++ b/webapp/humeurs.py @@ -0,0 +1,22 @@ +from flask import render_template, request, redirect, url_for +from webapp import webapp +from database import db +from database.models import Humeur + +@webapp.route("/humeurs") +def listHumeurs(): + humeurs = Humeur.query.all() + return render_template("humeurs.html", humeurs = humeurs) + +@webapp.route('/humeurs/add', methods=['POST']) +def addHumeur(): + humeur = Humeur(text=request.form['text']) + db.session.add(humeur) + db.session.commit() + return redirect(url_for('listHumeurs')) + +@webapp.route('/humeurs/del/') +def delHumeur(id): + Humeur.query.filter_by(id=id).delete() + db.session.commit() + return redirect(url_for('listHumeurs')) diff --git a/webapp/index.py b/webapp/index.py index 63dff92..10f735b 100644 --- a/webapp/index.py +++ b/webapp/index.py @@ -1,11 +1,6 @@ from flask import render_template from webapp import webapp -# from database import db -# from database.message import Message @webapp.route("/") def index(): - # message = Message(text="bla bla", periodicity = 3600) - # db.session.add(message) - # db.session.commit() - return render_template("index.html") + return render_template("index.html") diff --git a/webapp/messages.py b/webapp/messages.py index ab2de0f..3be8b4d 100644 --- a/webapp/messages.py +++ b/webapp/messages.py @@ -1,11 +1,6 @@ from flask import render_template from webapp import webapp -# from database import db -# from database.message import Message @webapp.route("/messages") def messages(): - # message = Message(text="bla bla", periodicity = 3600) - # db.session.add(message) - # db.session.commit() - return render_template("messages.html") + return render_template("messages.html") diff --git a/webapp/moderation.py b/webapp/moderation.py index 842e0d0..7d59731 100644 --- a/webapp/moderation.py +++ b/webapp/moderation.py @@ -3,4 +3,4 @@ from webapp import webapp @webapp.route("/moderation") def moderation(): - return render_template("moderation.html") + return render_template("moderation.html") diff --git a/webapp/templates/humeurs.html b/webapp/templates/humeurs.html new file mode 100644 index 0000000..812eea4 --- /dev/null +++ b/webapp/templates/humeurs.html @@ -0,0 +1,28 @@ +{% extends "template.html" %} + +{% block content %} +

Humeurs de Mamie.

+ + + + + + + + + {% for humeur in humeurs %} + + + + + {% endfor %} + +
TextAction
{{humeur.text}}Supprimer
+ +

Ajouter une humeur

+
+ + + +
+{% endblock %} \ No newline at end of file diff --git a/webapp/templates/template.html b/webapp/templates/template.html index 1f389b6..3a71819 100644 --- a/webapp/templates/template.html +++ b/webapp/templates/template.html @@ -19,6 +19,7 @@