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
|
@ -54,6 +54,7 @@ INSTALLED_APPS = (
|
||||||
'django.contrib.sites',
|
'django.contrib.sites',
|
||||||
'easy_thumbnails',
|
'easy_thumbnails',
|
||||||
'utils',
|
'utils',
|
||||||
|
'stored_messages',
|
||||||
'mptt',
|
'mptt',
|
||||||
'parler',
|
'parler',
|
||||||
'taggit',
|
'taggit',
|
||||||
|
|
|
@ -3,12 +3,13 @@ import os
|
||||||
from django.db import models
|
from django.db import models
|
||||||
from django.utils.translation import ugettext_lazy as _
|
from django.utils.translation import ugettext_lazy as _
|
||||||
from django.utils.functional import cached_property
|
from django.utils.functional import cached_property
|
||||||
from membership.models import StripeCustomer
|
|
||||||
from utils.models import BillingAddress
|
|
||||||
|
|
||||||
from Crypto.PublicKey import RSA
|
from Crypto.PublicKey import RSA
|
||||||
|
from stored_messages.settings import stored_messages_settings
|
||||||
|
|
||||||
|
from membership.models import StripeCustomer
|
||||||
|
from utils.models import BillingAddress
|
||||||
from .managers import VMPlansManager
|
from .managers import VMPlansManager
|
||||||
|
|
||||||
|
|
||||||
|
@ -118,6 +119,13 @@ class VirtualMachinePlan(models.Model):
|
||||||
name = 'vm-%s' % self.id
|
name = 'vm-%s' % self.id
|
||||||
return name
|
return name
|
||||||
|
|
||||||
|
@cached_property
|
||||||
|
def notifications(self):
|
||||||
|
stripe_customer = StripeCustomer.objects.get(hostingorder__vm_plan=self)
|
||||||
|
backend = stored_messages_settings.STORAGE_BACKEND()
|
||||||
|
messages = backend.inbox_list(stripe_customer.user)
|
||||||
|
return messages
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def create(cls, data, user):
|
def create(cls, data, user):
|
||||||
instance = cls.objects.create(**data)
|
instance = cls.objects.create(**data)
|
||||||
|
|
|
@ -71,7 +71,11 @@
|
||||||
<i class="fa fa-credit-card"></i> My Orders
|
<i class="fa fa-credit-card"></i> My Orders
|
||||||
</a>
|
</a>
|
||||||
</li>
|
</li>
|
||||||
|
<li>
|
||||||
|
<a href="{% url 'hosting:notifications' %}">
|
||||||
|
<i class="fa fa-bell"></i> Notifications
|
||||||
|
</a>
|
||||||
|
</li>
|
||||||
<li class="dropdown">
|
<li class="dropdown">
|
||||||
<a class="dropdown-toggle" role="button" data-toggle="dropdown" href="#">
|
<a class="dropdown-toggle" role="button" data-toggle="dropdown" href="#">
|
||||||
<i class="glyphicon glyphicon-user"></i> {{request.user.name}} <span class="caret"></span></a>
|
<i class="glyphicon glyphicon-user"></i> {{request.user.name}} <span class="caret"></span></a>
|
||||||
|
|
90
hosting/templates/hosting/notifications.html
Normal file
90
hosting/templates/hosting/notifications.html
Normal file
|
@ -0,0 +1,90 @@
|
||||||
|
{% extends "hosting/base_short.html" %}
|
||||||
|
{% load staticfiles bootstrap3 %}
|
||||||
|
{% block content %}
|
||||||
|
<div>
|
||||||
|
<div class="container virtual-machine-container dashboard-container ">
|
||||||
|
<div class="row">
|
||||||
|
<div class="col-md-9 col-md-offset-2">
|
||||||
|
<div class="col-sm-12">
|
||||||
|
<h3><i class="fa fa-bell" aria-hidden="true"></i> Notifications</h3>
|
||||||
|
<hr/>
|
||||||
|
<div class="col-md-3"> <!-- required for floating -->
|
||||||
|
<!-- Nav tabs -->
|
||||||
|
<ul class="nav nav-tabs tabs-left sideways">
|
||||||
|
<li class="active">
|
||||||
|
<a href="#unread-v" data-toggle="tab">
|
||||||
|
Unread <span class="badge">{{unread_notifications|length}}</span>
|
||||||
|
</a>
|
||||||
|
</li>
|
||||||
|
<li>
|
||||||
|
<a href="#all-v" data-toggle="tab">
|
||||||
|
All
|
||||||
|
</a>
|
||||||
|
</li>
|
||||||
|
</ul>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="col-md-9">
|
||||||
|
<!-- Tab panes -->
|
||||||
|
<div class="tab-content">
|
||||||
|
<div class="tab-pane active" id="unread-v">
|
||||||
|
<div class="row">
|
||||||
|
<div class="col-md-12">
|
||||||
|
<h3>Unread notifications</h3>
|
||||||
|
<hr>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="row">
|
||||||
|
<div class="col-md-12">
|
||||||
|
{% for notification in unread_notifications %}
|
||||||
|
<form method="POST" action="{% url 'hosting:read_notification' notification.id %}">
|
||||||
|
{% csrf_token %}
|
||||||
|
<span>{{notification}} -</span>
|
||||||
|
<button type="submit" class="btn btn-link">Mark as read</button>
|
||||||
|
<span class="pull-right" style="font-size: 11px;color: #999;">{{notification.date}}</span>
|
||||||
|
</form>
|
||||||
|
<hr/>
|
||||||
|
{% endfor %}
|
||||||
|
</div><!--/col-12-->
|
||||||
|
</div><!--/row-->
|
||||||
|
</div>
|
||||||
|
<div class="tab-pane" id="all-v">
|
||||||
|
<div class="row">
|
||||||
|
<div class="col-md-12">
|
||||||
|
<h3>All notifications</h3>
|
||||||
|
<hr>
|
||||||
|
{% for notification in all_notifications %}
|
||||||
|
<span>{{notification.message}} </span>
|
||||||
|
<span class="pull-right" style="font-size: 11px;color: #999;">{{notification.message.date}}</span>
|
||||||
|
<hr/>
|
||||||
|
{% endfor %}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="row">
|
||||||
|
<div class="col-md-12">
|
||||||
|
</div><!--/col-12-->
|
||||||
|
</div><!--/row-->
|
||||||
|
</div>
|
||||||
|
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="clearfix"></div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
</div>
|
||||||
|
|
||||||
|
{%endblock%}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -3,7 +3,8 @@ from django.conf.urls import url
|
||||||
from .views import DjangoHostingView, RailsHostingView, PaymentVMView,\
|
from .views import DjangoHostingView, RailsHostingView, PaymentVMView,\
|
||||||
NodeJSHostingView, LoginView, SignupView, IndexView, \
|
NodeJSHostingView, LoginView, SignupView, IndexView, \
|
||||||
OrdersHostingListView, OrdersHostingDetailView, VirtualMachinesPlanListView,\
|
OrdersHostingListView, OrdersHostingDetailView, VirtualMachinesPlanListView,\
|
||||||
VirtualMachineDetailView, GenerateVMSSHKeysView, OrdersHostingDeleteView
|
VirtualMachineDetailView, GenerateVMSSHKeysView, OrdersHostingDeleteView, NotificationsView, \
|
||||||
|
MarkAsReadNotificationView
|
||||||
|
|
||||||
urlpatterns = [
|
urlpatterns = [
|
||||||
# url(r'pricing/?$', VMPricingView.as_view(), name='pricing'),
|
# url(r'pricing/?$', VMPricingView.as_view(), name='pricing'),
|
||||||
|
@ -20,6 +21,9 @@ urlpatterns = [
|
||||||
name='virtual_machines'),
|
name='virtual_machines'),
|
||||||
url(r'my-virtual-machines/(?P<pk>\d+)/key/?$', GenerateVMSSHKeysView.as_view(),
|
url(r'my-virtual-machines/(?P<pk>\d+)/key/?$', GenerateVMSSHKeysView.as_view(),
|
||||||
name='virtual_machine_key'),
|
name='virtual_machine_key'),
|
||||||
|
url(r'^notifications/$', NotificationsView.as_view(), name='notifications'),
|
||||||
|
url(r'^notifications/(?P<pk>\d+)/?$', MarkAsReadNotificationView.as_view(),
|
||||||
|
name='read_notification'),
|
||||||
url(r'login/?$', LoginView.as_view(), name='login'),
|
url(r'login/?$', LoginView.as_view(), name='login'),
|
||||||
url(r'signup/?$', SignupView.as_view(), name='signup'),
|
url(r'signup/?$', SignupView.as_view(), name='signup'),
|
||||||
url(r'^logout/?$', 'django.contrib.auth.views.logout',
|
url(r'^logout/?$', 'django.contrib.auth.views.logout',
|
||||||
|
|
|
@ -2,12 +2,17 @@
|
||||||
from django.shortcuts import get_object_or_404, render,render_to_response
|
from django.shortcuts import get_object_or_404, render,render_to_response
|
||||||
from django.core.urlresolvers import reverse_lazy, reverse
|
from django.core.urlresolvers import reverse_lazy, reverse
|
||||||
from django.contrib.auth.mixins import LoginRequiredMixin
|
from django.contrib.auth.mixins import LoginRequiredMixin
|
||||||
|
from django.views.generic import View, CreateView, FormView, ListView, DetailView,\
|
||||||
from django.views.generic import View, CreateView, FormView, ListView, DetailView, UpdateView, DeleteView
|
DeleteView, TemplateView, UpdateView
|
||||||
from django.http import HttpResponseRedirect, HttpResponse
|
from django.http import HttpResponseRedirect
|
||||||
from django.contrib.auth import authenticate, login
|
from django.contrib.auth import authenticate, login
|
||||||
from django.conf import settings
|
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 membership.models import CustomUser, StripeCustomer
|
||||||
from utils.stripe_utils import StripeUtils
|
from utils.stripe_utils import StripeUtils
|
||||||
|
@ -145,6 +150,34 @@ class SignupView(CreateView):
|
||||||
return HttpResponseRedirect(self.get_success_url())
|
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):
|
class GenerateVMSSHKeysView(LoginRequiredMixin, DetailView):
|
||||||
model = VirtualMachinePlan
|
model = VirtualMachinePlan
|
||||||
template_name = 'hosting/virtual_machine_key.html'
|
template_name = 'hosting/virtual_machine_key.html'
|
||||||
|
@ -282,6 +315,7 @@ class OrdersHostingDeleteView(LoginRequiredMixin, DeleteView):
|
||||||
success_url = reverse_lazy('hosting:orders')
|
success_url = reverse_lazy('hosting:orders')
|
||||||
model = HostingOrder
|
model = HostingOrder
|
||||||
|
|
||||||
|
|
||||||
class VirtualMachinesPlanListView(LoginRequiredMixin, ListView):
|
class VirtualMachinesPlanListView(LoginRequiredMixin, ListView):
|
||||||
template_name = "hosting/virtual_machines.html"
|
template_name = "hosting/virtual_machines.html"
|
||||||
login_url = reverse_lazy('hosting:login')
|
login_url = reverse_lazy('hosting:login')
|
||||||
|
|
|
@ -18,6 +18,7 @@ easy_thumbnails
|
||||||
django-polymorphic
|
django-polymorphic
|
||||||
model-mommy
|
model-mommy
|
||||||
pycryptodome
|
pycryptodome
|
||||||
|
django-stored-messages
|
||||||
|
|
||||||
#PLUGINS
|
#PLUGINS
|
||||||
djangocms_flash
|
djangocms_flash
|
||||||
|
|
Loading…
Reference in a new issue