diff options
Diffstat (limited to 'budget')
| -rw-r--r-- | budget/forms.py | 1 | ||||
| -rw-r--r-- | budget/models.py | 4 | ||||
| -rw-r--r-- | budget/templates/edit_project.html | 7 | ||||
| -rw-r--r-- | budget/templates/forms.html | 5 | ||||
| -rw-r--r-- | budget/web.py | 5 |
5 files changed, 20 insertions, 2 deletions
diff --git a/budget/forms.py b/budget/forms.py index 7342762..36bde64 100644 --- a/budget/forms.py +++ b/budget/forms.py @@ -51,7 +51,6 @@ class EditProjectForm(Form): name = TextField(_("Project name"), validators=[Required()]) password = TextField(_("Private code"), validators=[Required()]) contact_email = TextField(_("Email"), validators=[Required(), Email()]) - submit = SubmitField(_("Edit the project")) def save(self): """Create a new project with the information given by this form. diff --git a/budget/models.py b/budget/models.py index 152ad34..b889794 100644 --- a/budget/models.py +++ b/budget/models.py @@ -70,6 +70,10 @@ class Project(db.Model): db.session.commit() return person + def remove_project(self): + db.session.delete(self) + db.session.commit() + def __repr__(self): return "<Project %s>" % self.name diff --git a/budget/templates/edit_project.html b/budget/templates/edit_project.html index 0349fe7..e84ad97 100644 --- a/budget/templates/edit_project.html +++ b/budget/templates/edit_project.html @@ -1,5 +1,12 @@ {% extends "layout.html" %} +{% block js %} + $('#delete-project').click(function () + { + $(this).html("<a style='color:red; ' href='{{ url_for('.remove_project') }}' >{{_("you sure?")}}</a>"); + }); +{% endblock %} + {% block content %} <h2>{{ _("Edit this project") }}</h2> <form method="post"> diff --git a/budget/templates/forms.html b/budget/templates/forms.html index 0a06001..9e5ecd6 100644 --- a/budget/templates/forms.html +++ b/budget/templates/forms.html @@ -65,7 +65,10 @@ {{ input(form.name) }} {{ input(form.password) }} {{ input(form.contact_email) }} - {{ submit(form.submit) }} + <div class="actions"> + <button class="btn primary">{{ _("Edit the project") }}</button> + <a id="delete-project" style="color:red; margin-left:10px; cursor:pointer; ">{{ _("delete") }}</a> + </div> {% endmacro %} diff --git a/budget/web.py b/budget/web.py index 9509dec..715a223 100644 --- a/budget/web.py +++ b/budget/web.py @@ -185,6 +185,11 @@ def edit_project(): return render_template("edit_project.html", form=form) +@main.route("/<project_id>/delete", methods=["GET"]) +def remove_project(): + g.project.remove_project() + + return redirect(url_for(".home")) @main.route("/exit") def exit(): |
