Add messages
This commit is contained in:
@@ -4,6 +4,7 @@
|
|||||||
|
|
||||||
{% block body %}
|
{% block body %}
|
||||||
<h1>Dashboard</h1>
|
<h1>Dashboard</h1>
|
||||||
|
{% include "notes/messages.html" %}
|
||||||
|
|
||||||
<h2>Notes for you</h2>
|
<h2>Notes for you</h2>
|
||||||
{% if notes %}
|
{% 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 %}
|
{% block body %}
|
||||||
<h1>Post a Note</h1>
|
<h1>Post a Note</h1>
|
||||||
|
{% include "notes/messages.html" %}
|
||||||
<form method="post">{% csrf_token %}
|
<form method="post">{% csrf_token %}
|
||||||
{{ form.as_p }}
|
{{ form.as_p }}
|
||||||
<button type="submit">Post!</button>
|
<button type="submit">Post!</button>
|
||||||
|
|||||||
@@ -4,9 +4,10 @@
|
|||||||
|
|
||||||
{% block body %}
|
{% block body %}
|
||||||
<h1>Profile</h1>
|
<h1>Profile</h1>
|
||||||
|
{% include "notes/messages.html" %}
|
||||||
<form method="post">
|
<form method="post">
|
||||||
{% csrf_token %}
|
{% csrf_token %}
|
||||||
{{ form.as_p }}
|
{{ form.as_p }}
|
||||||
<button type="submit">Post!</button>
|
<button type="submit">Save</button>
|
||||||
</form>
|
</form>
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
|||||||
@@ -6,7 +6,7 @@
|
|||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="body">
|
<div class="body">
|
||||||
<div class="login">
|
{% include "notes/messages.html" %}
|
||||||
<form action="{% url 'login' %}" method="POST">
|
<form action="{% url 'login' %}" method="POST">
|
||||||
{% csrf_token %}
|
{% csrf_token %}
|
||||||
<h2>Welcome!</h2>
|
<h2>Welcome!</h2>
|
||||||
@@ -15,5 +15,4 @@
|
|||||||
<button type="submit">Login</button>
|
<button type="submit">Login</button>
|
||||||
</form>
|
</form>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
from datetime import timedelta
|
from datetime import timedelta
|
||||||
from typing import Any
|
from typing import Any
|
||||||
|
from django.contrib import messages
|
||||||
from django.contrib.auth.mixins import LoginRequiredMixin
|
from django.contrib.auth.mixins import LoginRequiredMixin
|
||||||
from django.urls import reverse_lazy
|
from django.urls import reverse_lazy
|
||||||
from django.utils import timezone
|
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.expiry = timezone.now() + timedelta(seconds=note.to_user.expiry_seconds)
|
||||||
note.from_user = self.request.user
|
note.from_user = self.request.user
|
||||||
note.save()
|
note.save()
|
||||||
|
messages.success(self.request, "Note has been posted!")
|
||||||
return FormMixin.form_valid(self, form)
|
return FormMixin.form_valid(self, form)
|
||||||
|
|
||||||
|
|
||||||
@@ -43,3 +45,8 @@ class ProfileView(LoginRequiredMixin, UpdateView):
|
|||||||
|
|
||||||
def get_object(self):
|
def get_object(self):
|
||||||
return self.request.user
|
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