Commit f08a4701 by Kálmán Viktor

request: notify user when request is accepted

parent d09d309b
......@@ -1307,3 +1307,7 @@ textarea[name="new_members"] {
min-height: 80px;
}
}
.nowrap {
white-space: nowrap;
}
......@@ -22,7 +22,9 @@ from django.contrib.contenttypes.fields import GenericForeignKey
from django.contrib.contenttypes.models import ContentType
from django.contrib.auth.models import User
from django.core.validators import MinValueValidator
from django.utils.translation import ugettext_lazy as _, ugettext_noop
from django.utils.translation import (
ugettext_lazy as _, ugettext_noop, ungettext
)
from django.core.urlresolvers import reverse
from model_utils.models import TimeStampedModel
......@@ -36,6 +38,10 @@ class RequestAction(Model):
def accept(self):
raise NotImplementedError
@property
def accept_msg(self):
raise NotImplementedError
class Meta:
abstract = True
......@@ -109,6 +115,11 @@ class Request(TimeStampedModel):
self.closed_by = user
self.save()
self.user.profile.notify(
ugettext_noop("Request accepted"),
self.action.accept_msg
)
def decline(self, user, reason):
self.status = "DECLINED"
self.closed_by = user
......@@ -154,6 +165,21 @@ class ResourceChangeAction(RequestAction):
def accept(self, user):
self.instance.resources_request.async(user=user, resource_request=self)
@property
def accept_msg(self):
return _(
'The resources of <a href="%(url)s">%(name)s</a> were changed. '
'Number of cores: %(num_cores)d, RAM size: '
'<span class="nowrap">%(ram_size)d MiB</span>, '
'CPU priority: %(priority)d/100.'
) % {
'url': self.instance.get_absolute_url(),
'name': self.instance.name,
'num_cores': self.num_cores,
'ram_size': self.ram_size,
'priority': self.priority,
}
class ExtendLeaseAction(RequestAction):
instance = ForeignKey(Instance)
......@@ -163,6 +189,16 @@ class ExtendLeaseAction(RequestAction):
self.instance.renew(lease=self.lease_type.lease, save=True, force=True,
user=user)
@property
def accept_msg(self):
return _(
'The lease of <a href="%(url)s">%(name)s</a> got extended. '
'(suspend: %(suspend)s, remove: %(remove)s)'
) % {'name': self.instance.name,
'url': self.instance.get_absolute_url(),
'suspend': self.lease_type.lease.get_readable_suspend_time(),
'remove': self.lease_type.lease.get_readable_delete_time(), }
class TemplateAccessAction(RequestAction):
template_type = ForeignKey(TemplateAccessType)
......@@ -181,6 +217,14 @@ class TemplateAccessAction(RequestAction):
for t in self.template_type.templates.all():
t.set_user_level(self.user, self.level)
@property
def accept_msg(self):
return ungettext(
"You got access to the following template: %s",
"You got access to the following templates: %s",
self.template_type.templates.count()
) % ", ".join([x.name for x in self.template_type.templates.all()])
def send_notification_to_superusers(sender, instance, created, **kwargs):
if not created:
......@@ -207,4 +251,5 @@ def send_notification_to_superusers(sender, instance, created, **kwargs):
'<a href="%(request_url)s">link</a>.'), context
)
post_save.connect(send_notification_to_superusers, sender=Request)
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