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;
|
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 {
|
button.logout {
|
||||||
border: none;
|
border: none;
|
||||||
outline: none;
|
outline: none;
|
||||||
|
|
|
||||||
|
|
@ -29,6 +29,15 @@
|
||||||
</ul>
|
</ul>
|
||||||
</nav>
|
</nav>
|
||||||
</header>
|
</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 %}
|
{% block content %}{% endblock content %}
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
|
|
@ -1,5 +1,7 @@
|
||||||
|
from django.contrib import messages
|
||||||
from django.contrib.auth.views import LoginView as BaseLoginView, LogoutView as BaseLogoutView
|
from django.contrib.auth.views import LoginView as BaseLoginView, LogoutView as BaseLogoutView
|
||||||
from django.shortcuts import redirect
|
from django.shortcuts import redirect
|
||||||
|
from django.utils.translation import gettext as _
|
||||||
from django.urls import reverse_lazy
|
from django.urls import reverse_lazy
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -12,6 +14,8 @@ class LoginView(BaseLoginView):
|
||||||
return super().get(request, *args, **kwargs)
|
return super().get(request, *args, **kwargs)
|
||||||
|
|
||||||
def get_success_url(self):
|
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"))
|
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.core.exceptions import PermissionDenied
|
||||||
from django.shortcuts import redirect
|
from django.shortcuts import redirect
|
||||||
|
from django.utils.translation import gettext as _
|
||||||
from django.views.generic import FormView
|
from django.views.generic import FormView
|
||||||
|
|
||||||
from moku.constants import EMOJI_CATEGORIES, Verbs
|
from moku.constants import EMOJI_CATEGORIES, Verbs
|
||||||
|
|
@ -15,7 +17,8 @@ class FeedView(FormView):
|
||||||
if not self.request.user.is_authenticated:
|
if not self.request.user.is_authenticated:
|
||||||
raise PermissionDenied
|
raise PermissionDenied
|
||||||
form.instance.created_by = self.request.user
|
form.instance.created_by = self.request.user
|
||||||
form.instance.save()
|
form.save()
|
||||||
|
messages.success(self.request, _("your post was made!"))
|
||||||
return redirect("feed")
|
return redirect("feed")
|
||||||
|
|
||||||
def get_context_data(self, **kwargs):
|
def get_context_data(self, **kwargs):
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,7 @@
|
||||||
|
from django.contrib import messages
|
||||||
from django.shortcuts import redirect
|
from django.shortcuts import redirect
|
||||||
|
from django.utils.translation import gettext as _
|
||||||
from django.views.generic import FormView, TemplateView
|
from django.views.generic import FormView, TemplateView
|
||||||
from django.urls import reverse
|
|
||||||
|
|
||||||
from moku.forms.user import ProfileForm, UserForm
|
from moku.forms.user import ProfileForm, UserForm
|
||||||
from moku.models.user import User
|
from moku.models.user import User
|
||||||
|
|
@ -12,6 +13,7 @@ class EditProfileView(FormView):
|
||||||
|
|
||||||
def form_valid(self, form):
|
def form_valid(self, form):
|
||||||
form.save()
|
form.save()
|
||||||
|
messages.success(self.request, _("profile updated successfully!"))
|
||||||
return redirect("profile", username=form.instance.username)
|
return redirect("profile", username=form.instance.username)
|
||||||
|
|
||||||
def get_form(self):
|
def get_form(self):
|
||||||
|
|
@ -34,5 +36,7 @@ class SignupView(FormView):
|
||||||
template_name = "moku/signup.jinja"
|
template_name = "moku/signup.jinja"
|
||||||
form_class = UserForm
|
form_class = UserForm
|
||||||
|
|
||||||
def get_success_url(self):
|
def form_valid(self, form):
|
||||||
return reverse("feed")
|
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