Add messages
This commit is contained in:
@@ -4,6 +4,7 @@
|
||||
|
||||
{% block body %}
|
||||
<h1>Dashboard</h1>
|
||||
{% include "notes/messages.html" %}
|
||||
|
||||
<h2>Notes for you</h2>
|
||||
{% if notes %}
|
||||
|
||||
7
notes/templates/notes/messages.html
Normal file
7
notes/templates/notes/messages.html
Normal file
@@ -0,0 +1,7 @@
|
||||
{% if messages %}
|
||||
<div class="messages">
|
||||
{% for message in messages %}
|
||||
<div class="card">{{ message }}</li>
|
||||
{% endfor %}
|
||||
</div>
|
||||
{% endif %}
|
||||
@@ -4,6 +4,7 @@
|
||||
|
||||
{% block body %}
|
||||
<h1>Post a Note</h1>
|
||||
{% include "notes/messages.html" %}
|
||||
<form method="post">{% csrf_token %}
|
||||
{{ form.as_p }}
|
||||
<button type="submit">Post!</button>
|
||||
|
||||
@@ -4,9 +4,10 @@
|
||||
|
||||
{% block body %}
|
||||
<h1>Profile</h1>
|
||||
{% include "notes/messages.html" %}
|
||||
<form method="post">
|
||||
{% csrf_token %}
|
||||
{{ form.as_p }}
|
||||
<button type="submit">Post!</button>
|
||||
<button type="submit">Save</button>
|
||||
</form>
|
||||
{% endblock %}
|
||||
|
||||
@@ -6,14 +6,13 @@
|
||||
</div>
|
||||
|
||||
<div class="body">
|
||||
<div class="login">
|
||||
<form action="{% url 'login' %}" method="POST">
|
||||
{% csrf_token %}
|
||||
<h2>Welcome!</h2>
|
||||
<p>Please login to continue</p>
|
||||
{{ form.as_p }}
|
||||
<button type="submit">Login</button>
|
||||
</form>
|
||||
</div>
|
||||
{% include "notes/messages.html" %}
|
||||
<form action="{% url 'login' %}" method="POST">
|
||||
{% csrf_token %}
|
||||
<h2>Welcome!</h2>
|
||||
<p>Please login to continue</p>
|
||||
{{ form.as_p }}
|
||||
<button type="submit">Login</button>
|
||||
</form>
|
||||
</div>
|
||||
{% endblock %}
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
from datetime import timedelta
|
||||
from typing import Any
|
||||
from django.contrib import messages
|
||||
from django.contrib.auth.mixins import LoginRequiredMixin
|
||||
from django.urls import reverse_lazy
|
||||
from django.utils import timezone
|
||||
@@ -33,6 +34,7 @@ class PostNoteView(LoginRequiredMixin, CreateView):
|
||||
note.expiry = timezone.now() + timedelta(seconds=note.to_user.expiry_seconds)
|
||||
note.from_user = self.request.user
|
||||
note.save()
|
||||
messages.success(self.request, "Note has been posted!")
|
||||
return FormMixin.form_valid(self, form)
|
||||
|
||||
|
||||
@@ -43,3 +45,8 @@ class ProfileView(LoginRequiredMixin, UpdateView):
|
||||
|
||||
def get_object(self):
|
||||
return self.request.user
|
||||
|
||||
def form_valid(self, form):
|
||||
ret = super().form_valid(form)
|
||||
messages.success(self.request, "Profile has been updated!")
|
||||
return ret
|
||||
|
||||
Reference in New Issue
Block a user