Commit 6ec3b3e8 authored by berumuron's avatar berumuron
Browse files

add: #14 Provide projects modification

parent df739040
......@@ -259,6 +259,28 @@ class Project:
return cls.find_by_id(cursor.lastrowid)
def save(self):
try:
database = db.get_db()
database.execute(
(
"UPDATE projects "
"SET name = ?, is_private = ?, responsible = ?, description = ? "
"WHERE id = ?"
),
(
self.name,
self.is_private,
self.responsible,
self.description,
self.id,
),
)
database.commit()
return True
except sqlite3.DatabaseError:
return False
def delete(self):
try:
database = db.get_db()
......
from flask import Blueprint, request, redirect, url_for, flash, render_template, g
from flask import (
Blueprint,
request,
redirect,
url_for,
flash,
render_template,
g,
abort,
)
from .auth import login_required
from .models import Project
......@@ -37,6 +46,30 @@ def create():
return render_template("projects/create.html")
@bp.route("/update/<project_id>", methods=("GET", "POST"))
@login_required
def update(project_id):
project = Project.find_by_id(project_id)
if not project:
abort(404)
if request.method == "POST":
project.name = request.form["name"].strip()
project.is_private = request.form["is_private"].strip() == "yes"
project.responsible = request.form["responsible"].strip()
project.description = request.form["description"].strip()
if not project.name:
flash("Le nom est requis.")
elif not project.save():
flash("Le projet n’a pas pu être modifié.")
else:
flash("Le projet a été modifié.", "success")
return redirect(url_for("projects.index"))
return render_template("projects/update.html", project=project)
@bp.route("/delete/<project_id>", methods=["DELETE"])
@login_required
def delete(project_id):
......
......@@ -4,6 +4,7 @@
--main-color-muted: #52486E;
--secondary-color: #542DBC;
--contrast-color: #F2F2F2;
--contrast-color-muted: #E0E0E0;
}
* {
......@@ -426,20 +427,35 @@ button.button-ghost {
content: "👤";
}
.project .project-header .project-delete {
position: absolute;
top: -1.75rem;
left: 0;
.project .project-actions {
display: flex;
margin-top: .5rem;
padding: .25rem .5rem;
opacity: 0;
visibility: hidden;
transition: opacity .2s ease-out;
justify-content: space-between;
background-color: var(--contrast-color-muted);
border-radius: .25rem;
}
.project .project-header:hover .project-delete {
opacity: 1;
visibility: visible;
.project .project-actions .project-update {
vertical-align: middle;
margin-right: 1rem;
padding: .25rem .5rem;
text-decoration: none;
background-color: var(--contrast-color);
border: 1px solid var(--secondary-color);
border-radius: .25rem;
}
.project .project-actions .project-update::before {
content: "✎";
}
.project .project-actions .project-delete {
margin-right: 0;
}
.project .project-header .project-delete::before {
.project .project-actions .project-delete::before {
content: "🗑";
}
......
......@@ -34,17 +34,6 @@
{% endif %}
</h2>
{% if g.current_user %}
<button
class="button-ghost project-delete"
data-confirm="Êtes-vous certain·e de vouloir supprimer ce projet ?"
data-action="{{ url_for('projects.delete', project_id=project.id ) }}"
data-method="delete"
>
Supprimer
</button>
{% endif %}
{% if project.responsible %}
<span class="project-responsible">
{{ project.responsible }}
......@@ -92,6 +81,23 @@
</li>
{% endfor %}
</ul>
{% if g.current_user %}
<div class="project-actions">
<a class="project-update" href="{{ url_for('projects.update', project_id=project.id) }}">
Modifier
</a>
<button
class="button-ghost project-delete"
data-confirm="Êtes-vous certain·e de vouloir supprimer ce projet ?"
data-action="{{ url_for('projects.delete', project_id=project.id) }}"
data-method="delete"
>
Supprimer
</button>
</div>
{% endif %}
</section>
{% endfor %}
</div>
......
{% extends 'layout.html' %}
{% block content %}
<div class="container container-small">
<h1>Modifier un projet</h1>
<form action="" method="post">
{% include "alerts.html" %}
<div class="form-group">
<label for="name">Nom</label>
<input type="text" name="name" id="name" value="{{ project.name }}" required autofocus />
</div>
<div class="form-group form-group-radios">
<input type="radio" name="is_private" id="is_private" value="yes" {{ 'checked' if project.is_private }} />
<label for="is_private">Privé</label>
<input type="radio" name="is_private" id="is_public" value="no" {{ 'checked' if not project.is_private }} />
<label for="is_public">Public</label>
</div>
<div class="form-group">
<label for="responsible">Responsable <span class="text-muted">(facultatif)</span></label>
<input type="text" name="responsible" id="responsible" value="{{ project.responsible }}" />
</div>
<div class="form-group">
<label for="description">Description <span class="text-muted">(facultatif)</span></label>
<textarea name="description" id="description">{{ project.description }}</textarea>
</div>
<div class="form-group form-group-actions">
<button type="submit" class="button-primary">
Modifier
</button>
<a href="{{ url_for('projects.index') }}">
Retour aux projets
</a>
</div>
</form>
</div
{% endblock %}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment