Added mark a notification as read feature, Fixed some errors
This commit is contained in:
parent
c33c4f4148
commit
a846f42bf6
7 changed files with 153 additions and 11 deletions
|
|
@ -2,12 +2,17 @@
|
|||
from django.shortcuts import get_object_or_404, render,render_to_response
|
||||
from django.core.urlresolvers import reverse_lazy, reverse
|
||||
from django.contrib.auth.mixins import LoginRequiredMixin
|
||||
|
||||
from django.views.generic import View, CreateView, FormView, ListView, DetailView, UpdateView, DeleteView
|
||||
from django.http import HttpResponseRedirect, HttpResponse
|
||||
from django.views.generic import View, CreateView, FormView, ListView, DetailView,\
|
||||
DeleteView, TemplateView, UpdateView
|
||||
from django.http import HttpResponseRedirect
|
||||
from django.contrib.auth import authenticate, login
|
||||
from django.conf import settings
|
||||
from django.contrib import messages
|
||||
|
||||
|
||||
from stored_messages.settings import stored_messages_settings
|
||||
from stored_messages.models import Message
|
||||
from stored_messages.api import mark_read
|
||||
|
||||
|
||||
from membership.models import CustomUser, StripeCustomer
|
||||
from utils.stripe_utils import StripeUtils
|
||||
|
|
@ -145,6 +150,34 @@ class SignupView(CreateView):
|
|||
return HttpResponseRedirect(self.get_success_url())
|
||||
|
||||
|
||||
class NotificationsView(TemplateView):
|
||||
template_name = 'hosting/notifications.html'
|
||||
|
||||
def get_context_data(self, **kwargs):
|
||||
context = super(NotificationsView, self).get_context_data(**kwargs)
|
||||
backend = stored_messages_settings.STORAGE_BACKEND()
|
||||
unread_notifications = backend.inbox_list(self.request.user)
|
||||
read_notifications = backend.archive_list(self.request.user)
|
||||
context.update({
|
||||
'unread_notifications': unread_notifications,
|
||||
'all_notifications': read_notifications + unread_notifications
|
||||
})
|
||||
return context
|
||||
|
||||
|
||||
class MarkAsReadNotificationView(LoginRequiredMixin, UpdateView):
|
||||
model = Message
|
||||
success_url = reverse_lazy('hosting:notifications')
|
||||
fields = '__all__'
|
||||
|
||||
def post(self, *args, **kwargs):
|
||||
message = self.get_object()
|
||||
backend = stored_messages_settings.STORAGE_BACKEND()
|
||||
backend.archive_store([self.request.user], message)
|
||||
mark_read(self.request.user, message)
|
||||
return HttpResponseRedirect(reverse('hosting:notifications'))
|
||||
|
||||
|
||||
class GenerateVMSSHKeysView(LoginRequiredMixin, DetailView):
|
||||
model = VirtualMachinePlan
|
||||
template_name = 'hosting/virtual_machine_key.html'
|
||||
|
|
@ -278,10 +311,11 @@ class OrdersHostingListView(LoginRequiredMixin, ListView):
|
|||
|
||||
|
||||
class OrdersHostingDeleteView(LoginRequiredMixin, DeleteView):
|
||||
login_url=reverse_lazy('hosting:login')
|
||||
login_url = reverse_lazy('hosting:login')
|
||||
success_url = reverse_lazy('hosting:orders')
|
||||
model = HostingOrder
|
||||
|
||||
|
||||
class VirtualMachinesPlanListView(LoginRequiredMixin, ListView):
|
||||
template_name = "hosting/virtual_machines.html"
|
||||
login_url = reverse_lazy('hosting:login')
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue