feature: 💬 add info messages
This commit is contained in:
parent
c3f74be09a
commit
6c9a647141
5 changed files with 43 additions and 4 deletions
|
|
@ -39,6 +39,25 @@ body {
|
|||
margin-block-end: 1.6rem;
|
||||
}
|
||||
|
||||
.messages {
|
||||
margin-block-end: 1.6rem;
|
||||
display: grid;
|
||||
row-gap: .8rem;
|
||||
font-size: 1.5rem;
|
||||
}
|
||||
|
||||
.messages li.success::before {
|
||||
content: "✅ ";
|
||||
}
|
||||
|
||||
.messages li.error::before {
|
||||
content: "❌ ";
|
||||
}
|
||||
|
||||
.messages li.info::before {
|
||||
content: "ℹ️ ";
|
||||
}
|
||||
|
||||
button.logout {
|
||||
border: none;
|
||||
outline: none;
|
||||
|
|
|
|||
|
|
@ -29,6 +29,15 @@
|
|||
</ul>
|
||||
</nav>
|
||||
</header>
|
||||
{% if messages %}
|
||||
<ul class="messages">
|
||||
{% for message in messages %}
|
||||
<li{% if message.tags %} class="{{ message.tags }}"{% endif %}>
|
||||
{{ message }}
|
||||
</li>
|
||||
{% endfor %}
|
||||
</ul>
|
||||
{% endif %}
|
||||
{% block content %}{% endblock content %}
|
||||
</body>
|
||||
</html>
|
||||
|
|
@ -1,5 +1,7 @@
|
|||
from django.contrib import messages
|
||||
from django.contrib.auth.views import LoginView as BaseLoginView, LogoutView as BaseLogoutView
|
||||
from django.shortcuts import redirect
|
||||
from django.utils.translation import gettext as _
|
||||
from django.urls import reverse_lazy
|
||||
|
||||
|
||||
|
|
@ -12,6 +14,8 @@ class LoginView(BaseLoginView):
|
|||
return super().get(request, *args, **kwargs)
|
||||
|
||||
def get_success_url(self):
|
||||
if self.request.user.is_authenticated:
|
||||
messages.success(self.request, _("welcome back, %(username)s!") % {"username": self.request.user.username})
|
||||
return self.request.GET.get("next", reverse_lazy("feed"))
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -1,5 +1,7 @@
|
|||
from django.contrib import messages
|
||||
from django.core.exceptions import PermissionDenied
|
||||
from django.shortcuts import redirect
|
||||
from django.utils.translation import gettext as _
|
||||
from django.views.generic import FormView
|
||||
|
||||
from moku.constants import EMOJI_CATEGORIES, Verbs
|
||||
|
|
@ -15,7 +17,8 @@ class FeedView(FormView):
|
|||
if not self.request.user.is_authenticated:
|
||||
raise PermissionDenied
|
||||
form.instance.created_by = self.request.user
|
||||
form.instance.save()
|
||||
form.save()
|
||||
messages.success(self.request, _("your post was made!"))
|
||||
return redirect("feed")
|
||||
|
||||
def get_context_data(self, **kwargs):
|
||||
|
|
|
|||
|
|
@ -1,6 +1,7 @@
|
|||
from django.contrib import messages
|
||||
from django.shortcuts import redirect
|
||||
from django.utils.translation import gettext as _
|
||||
from django.views.generic import FormView, TemplateView
|
||||
from django.urls import reverse
|
||||
|
||||
from moku.forms.user import ProfileForm, UserForm
|
||||
from moku.models.user import User
|
||||
|
|
@ -12,6 +13,7 @@ class EditProfileView(FormView):
|
|||
|
||||
def form_valid(self, form):
|
||||
form.save()
|
||||
messages.success(self.request, _("profile updated successfully!"))
|
||||
return redirect("profile", username=form.instance.username)
|
||||
|
||||
def get_form(self):
|
||||
|
|
@ -34,5 +36,7 @@ class SignupView(FormView):
|
|||
template_name = "moku/signup.jinja"
|
||||
form_class = UserForm
|
||||
|
||||
def get_success_url(self):
|
||||
return reverse("feed")
|
||||
def form_valid(self, form):
|
||||
form.save()
|
||||
messages.success(self.request, _("that's it! just log in, and you're ready to go."))
|
||||
return redirect("login")
|
||||
|
|
|
|||
Loading…
Reference in a new issue