mirror of
https://github.com/skylanix/MamieHenriette.git
synced 2026-02-06 06:40:35 +01:00
Création d'une page de gestion des humeurs
This commit is contained in:
@@ -6,7 +6,12 @@ webapp.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///database.db'
|
|||||||
db = SQLAlchemy(webapp)
|
db = SQLAlchemy(webapp)
|
||||||
|
|
||||||
with webapp.app_context():
|
with webapp.app_context():
|
||||||
with open('database/schema.sql', 'r') as f:
|
with open('database/schema.sql', 'r') as f:
|
||||||
sql_script = f.read()
|
sql = f.read()
|
||||||
db.session.execute(text(sql_script))
|
connection = db.session.connection().connection
|
||||||
db.session.commit()
|
try:
|
||||||
|
cursor = connection.cursor()
|
||||||
|
cursor.executescript(sql)
|
||||||
|
cursor.close()
|
||||||
|
finally:
|
||||||
|
connection.close()
|
||||||
|
|||||||
@@ -1,6 +1,10 @@
|
|||||||
# from webapp import db
|
|
||||||
from database 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):
|
class Message(db.Model):
|
||||||
id = db.Column(db.Integer, primary_key=True)
|
id = db.Column(db.Integer, primary_key=True)
|
||||||
enable = db.Column(db.Boolean, default=False)
|
enable = db.Column(db.Boolean, default=False)
|
||||||
@@ -3,4 +3,10 @@ CREATE TABLE IF NOT EXISTS `message` (
|
|||||||
`enable` BOOLEAN NOT NULL DEFAULT FALSE,
|
`enable` BOOLEAN NOT NULL DEFAULT FALSE,
|
||||||
`text` VARCHAR(256) NULL,
|
`text` VARCHAR(256) NULL,
|
||||||
periodicity INTEGER NULL
|
periodicity INTEGER NULL
|
||||||
);
|
);
|
||||||
|
|
||||||
|
CREATE TABLE IF NOT EXISTS `humeur` (
|
||||||
|
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||||
|
`enable` BOOLEAN NOT NULL DEFAULT TRUE,
|
||||||
|
`text` VARCHAR(256) NULL
|
||||||
|
);
|
||||||
|
|||||||
@@ -2,4 +2,4 @@ from flask import Flask
|
|||||||
|
|
||||||
webapp = Flask(__name__)
|
webapp = Flask(__name__)
|
||||||
|
|
||||||
from webapp import commandes, index, messages, moderation
|
from webapp import commandes, index, humeurs, messages, moderation
|
||||||
|
|||||||
@@ -3,4 +3,4 @@ from webapp import webapp
|
|||||||
|
|
||||||
@webapp.route("/commandes")
|
@webapp.route("/commandes")
|
||||||
def commandes():
|
def commandes():
|
||||||
return render_template("commandes.html")
|
return render_template("commandes.html")
|
||||||
|
|||||||
22
webapp/humeurs.py
Normal file
22
webapp/humeurs.py
Normal file
@@ -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/<id>')
|
||||||
|
def delHumeur(id):
|
||||||
|
Humeur.query.filter_by(id=id).delete()
|
||||||
|
db.session.commit()
|
||||||
|
return redirect(url_for('listHumeurs'))
|
||||||
@@ -1,11 +1,6 @@
|
|||||||
from flask import render_template
|
from flask import render_template
|
||||||
from webapp import webapp
|
from webapp import webapp
|
||||||
# from database import db
|
|
||||||
# from database.message import Message
|
|
||||||
|
|
||||||
@webapp.route("/")
|
@webapp.route("/")
|
||||||
def index():
|
def index():
|
||||||
# message = Message(text="bla bla", periodicity = 3600)
|
return render_template("index.html")
|
||||||
# db.session.add(message)
|
|
||||||
# db.session.commit()
|
|
||||||
return render_template("index.html")
|
|
||||||
|
|||||||
@@ -1,11 +1,6 @@
|
|||||||
from flask import render_template
|
from flask import render_template
|
||||||
from webapp import webapp
|
from webapp import webapp
|
||||||
# from database import db
|
|
||||||
# from database.message import Message
|
|
||||||
|
|
||||||
@webapp.route("/messages")
|
@webapp.route("/messages")
|
||||||
def messages():
|
def messages():
|
||||||
# message = Message(text="bla bla", periodicity = 3600)
|
return render_template("messages.html")
|
||||||
# db.session.add(message)
|
|
||||||
# db.session.commit()
|
|
||||||
return render_template("messages.html")
|
|
||||||
|
|||||||
@@ -3,4 +3,4 @@ from webapp import webapp
|
|||||||
|
|
||||||
@webapp.route("/moderation")
|
@webapp.route("/moderation")
|
||||||
def moderation():
|
def moderation():
|
||||||
return render_template("moderation.html")
|
return render_template("moderation.html")
|
||||||
|
|||||||
28
webapp/templates/humeurs.html
Normal file
28
webapp/templates/humeurs.html
Normal file
@@ -0,0 +1,28 @@
|
|||||||
|
{% extends "template.html" %}
|
||||||
|
|
||||||
|
{% block content %}
|
||||||
|
<h1>Humeurs de Mamie.</h1>
|
||||||
|
<table>
|
||||||
|
<thead>
|
||||||
|
<tr>
|
||||||
|
<th>Text</th>
|
||||||
|
<th>Action</th>
|
||||||
|
</tr>
|
||||||
|
</thead>
|
||||||
|
<tbody>
|
||||||
|
{% for humeur in humeurs %}
|
||||||
|
<tr>
|
||||||
|
<td>{{humeur.text}}</td>
|
||||||
|
<td><a href="{{ url_for('delHumeur', id = humeur.id) }}">Supprimer</a></td>
|
||||||
|
</tr>
|
||||||
|
{% endfor %}
|
||||||
|
</tbody>
|
||||||
|
</table>
|
||||||
|
|
||||||
|
<h2>Ajouter une humeur</h2>
|
||||||
|
<form action="{{ url_for('addHumeur') }}" method="POST">
|
||||||
|
<label for="text">Text</label>
|
||||||
|
<input name="text" type="text" />
|
||||||
|
<input type="Submit" value="Ajouter">
|
||||||
|
</form>
|
||||||
|
{% endblock %}
|
||||||
@@ -19,6 +19,7 @@
|
|||||||
<a href="/"><img src="/static/ico/favicon.ico"></a>
|
<a href="/"><img src="/static/ico/favicon.ico"></a>
|
||||||
<ul>
|
<ul>
|
||||||
<li><a href="/commandes">Commandes</a></li>
|
<li><a href="/commandes">Commandes</a></li>
|
||||||
|
<li><a href="/humeurs">Humeurs</a></li>
|
||||||
<li><a href="/messages">Messages</a></li>
|
<li><a href="/messages">Messages</a></li>
|
||||||
<li><a href="/moderation">Modération</a></li>
|
<li><a href="/moderation">Modération</a></li>
|
||||||
</ul>
|
</ul>
|
||||||
|
|||||||
Reference in New Issue
Block a user