Skip to content

Commit a1978ac

Browse files
committed
refactor Task model to use DateTime for echeance_prochaine; update task creation and calendar display accordingly
1 parent 2f854d1 commit a1978ac

File tree

7 files changed

+10
-10
lines changed

7 files changed

+10
-10
lines changed

__pycache__/models.cpython-312.pyc

-14 Bytes
Binary file not shown.

__pycache__/routes.cpython-312.pyc

94 Bytes
Binary file not shown.

instance/calendar.db

0 Bytes
Binary file not shown.

models.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ class Task(db.Model):
2121
action_programmee = db.Column(db.String(200), nullable=False)
2222
periodicite = db.Column(db.String(50), nullable=False)
2323
responsable = db.Column(db.String(100), nullable=False)
24-
echeance_prochaine = db.Column(db.String(100), nullable=True)
24+
echeance_prochaine = db.Column(db.DateTime, nullable=False) # Changed from String to DateTime
2525
acteurs_externes = db.Column(db.String(200), nullable=True)
2626
last_completed = db.Column(db.DateTime, nullable=True)
2727

reset_db.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
# Create a new file called reset_db.py
21
from app import create_app
32
from models import db
43

routes.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,34 +23,34 @@ def login():
2323
@app.route('/add-task', methods=['GET', 'POST'])
2424
@login_required
2525
def add_task():
26-
"""Handle task creation (admin only)"""
2726
if current_user.role != 'admin':
2827
flash('Access denied. Admins only.', 'danger')
2928
return redirect(url_for('login'))
30-
29+
3130
form = TaskForm()
3231
if form.validate_on_submit():
3332
task = Task(
3433
volet=form.volet.data,
3534
action_programmee=form.action_programmee.data,
3635
periodicite=form.periodicite.data,
3736
responsable=form.responsable.data,
38-
echeance_prochaine=form.echeance_prochaine.data,
37+
echeance_prochaine=datetime.combine(form.echeance_prochaine.data, datetime.min.time()), # Convert date to datetime
3938
acteurs_externes=form.acteurs_externes.data
4039
)
4140
db.session.add(task)
4241
db.session.commit()
4342
flash('Task added successfully!', 'success')
44-
return redirect(url_for('add_task'))
43+
return redirect(url_for('tasks_calendar'))
4544
return render_template('add_task.html', form=form)
4645

4746
@app.route('/calendar')
4847
@login_required
4948
def tasks_calendar():
5049
tasks = Task.query.order_by(Task.echeance_prochaine).all()
5150
return render_template('tasks_calendar.html',
52-
tasks=tasks,
53-
today=datetime.now().date())
51+
tasks=tasks,
52+
today=datetime.now(),
53+
datetime=datetime)
5454

5555
@app.route('/complete-task/<int:task_id>', methods=['POST'])
5656
@login_required

templates/tasks_calendar.html

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,12 +26,13 @@ <h1>Tasks Calendar</h1>
2626
</thead>
2727
<tbody>
2828
{% for task in tasks %}
29-
<tr {% if task.echeance_prochaine.date() < today %}class="table-danger"{% endif %}>
29+
{% set echeance = task.echeance_prochaine if task.echeance_prochaine is not string else datetime.strptime(task.echeance_prochaine, '%Y-%m-%d') %}
30+
<tr {% if echeance < today %}class="table-danger"{% endif %}>
3031
<td>{{ task.volet }}</td>
3132
<td>{{ task.action_programmee }}</td>
3233
<td>{{ task.periodicite }}</td>
3334
<td>{{ task.responsable }}</td>
34-
<td>{{ task.echeance_prochaine.strftime('%Y-%m-%d') }}</td>
35+
<td>{{ echeance.strftime('%Y-%m-%d') }}</td>
3536
<td>{{ task.acteurs_externes or '-' }}</td>
3637
<td>
3738
{% if task.last_completed %}

0 commit comments

Comments
 (0)