Commit ae9bbb40 authored by ibuler's avatar ibuler

Add flash message template

parent 8e5e788b
{% if messages %}
{% for message in messages %}
<div class="alert alert-{{ message.tags }}" style="margin: 20px auto 0px">
{{ message|safe }}
</div>
{% endfor %}
{% endif %}
......@@ -20,6 +20,7 @@
{% include '_left_side_bar.html' %}
<div id="page-wrapper" class="gray-bg">
{% include '_header_bar.html' %}
{% include '_message.html' %}
{% block content %}{% endblock %}
{% include '_footer.html' %}
</div>
......
# ~*~ coding: utf-8 ~*~
from django.shortcuts import get_object_or_404
from __future__ import unicode_literals
from django.shortcuts import get_object_or_404, reverse
from django.urls import reverse_lazy
from django.db.models import Q
from django.views.generic.list import ListView
from django.views.generic.edit import CreateView, DeleteView, UpdateView
from django.views.generic.detail import DetailView
from django.contrib.messages.views import SuccessMessageMixin
from django.conf import settings
from .models import User, UserGroup, Role
......@@ -37,11 +40,12 @@ class UserListView(ListView):
return context
class UserAddView(CreateView):
class UserAddView(SuccessMessageMixin, CreateView):
model = User
form_class = UserAddForm
template_name = 'users/user_add.html'
success_url = reverse_lazy('users:user-list')
success_message = '添加用户 <a href="%s">%s</a> 成功 .'
def get_context_data(self, **kwargs):
context = super(UserAddView, self).get_context_data(**kwargs)
......@@ -54,6 +58,12 @@ class UserAddView(CreateView):
user.save()
return super(UserAddView, self).form_valid(form)
def get_success_message(self, cleaned_data):
return self.success_message % (
reverse_lazy('users:user-detail', kwargs={'pk': self.object.pk}),
self.object.name,
)
class UserUpdateView(UpdateView):
model = User
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment