Commit b8e19b76 by Bach Dániel

dashboard: invalidate template fragment cache in Message*Views

parent c6ef1eb4
...@@ -16,6 +16,8 @@ ...@@ -16,6 +16,8 @@
# with CIRCLE. If not, see <http://www.gnu.org/licenses/>. # with CIRCLE. If not, see <http://www.gnu.org/licenses/>.
from django.contrib.messages.views import SuccessMessageMixin from django.contrib.messages.views import SuccessMessageMixin
from django.core.cache import cache
from django.core.cache.utils import make_template_fragment_key
from django.core.urlresolvers import reverse from django.core.urlresolvers import reverse
from django.utils.translation import ugettext as _ from django.utils.translation import ugettext as _
from django.views.generic import CreateView, DeleteView, UpdateView from django.views.generic import CreateView, DeleteView, UpdateView
...@@ -28,29 +30,37 @@ from ..models import Message ...@@ -28,29 +30,37 @@ from ..models import Message
from ..tables import MessageListTable from ..tables import MessageListTable
class InvalidateMessageCacheMixin(object):
def post(self, *args, **kwargs):
key = make_template_fragment_key('broadcast_messages')
cache.delete(key)
return super(InvalidateMessageCacheMixin, self).post(*args, **kwargs)
class MessageList(LoginRequiredMixin, SuperuserRequiredMixin, SingleTableView): class MessageList(LoginRequiredMixin, SuperuserRequiredMixin, SingleTableView):
template_name = "dashboard/message-list.html" template_name = "dashboard/message-list.html"
model = Message model = Message
table_class = MessageListTable table_class = MessageListTable
class MessageDetail(LoginRequiredMixin, SuperuserRequiredMixin, class MessageDetail(InvalidateMessageCacheMixin, LoginRequiredMixin,
SuccessMessageMixin, UpdateView): SuperuserRequiredMixin, SuccessMessageMixin, UpdateView):
model = Message model = Message
template_name = "dashboard/message-edit.html" template_name = "dashboard/message-edit.html"
form_class = MessageForm form_class = MessageForm
success_message = _("Broadcast message successfully updated.") success_message = _("Broadcast message successfully updated.")
class MessageCreate(LoginRequiredMixin, SuperuserRequiredMixin, class MessageCreate(InvalidateMessageCacheMixin, LoginRequiredMixin,
SuccessMessageMixin, CreateView): SuperuserRequiredMixin, SuccessMessageMixin, CreateView):
model = Message model = Message
template_name = "dashboard/message-create.html" template_name = "dashboard/message-create.html"
form_class = MessageForm form_class = MessageForm
success_message = _("New broadcast message successfully created.") success_message = _("New broadcast message successfully created.")
class MessageDelete(LoginRequiredMixin, SuperuserRequiredMixin, DeleteView): class MessageDelete(InvalidateMessageCacheMixin, LoginRequiredMixin,
SuperuserRequiredMixin, DeleteView):
model = Message model = Message
template_name = "dashboard/confirm/base-delete.html" template_name = "dashboard/confirm/base-delete.html"
......
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 sign in to comment