Commit 7eb6a33f by Bach Dániel

vm: fix notifications

parent 4684a0a9
...@@ -70,7 +70,9 @@ class Notification(TimeStampedModel): ...@@ -70,7 +70,9 @@ class Notification(TimeStampedModel):
def send(cls, user, subject, template, context, def send(cls, user, subject, template, context,
valid_until=None, subject_context=None): valid_until=None, subject_context=None):
hro = create_readable(template, user=user, **context) hro = create_readable(template, user=user, **context)
subject = create_readable(subject, subject_context or context) if subject_context is None:
subject_context = context
subject = create_readable(subject, **subject_context)
return cls.objects.create(to=user, return cls.objects.create(to=user,
subject_data=subject.to_dict(), subject_data=subject.to_dict(),
message_data=hro.to_dict(), message_data=hro.to_dict(),
......
...@@ -642,6 +642,13 @@ class Instance(AclBase, VirtualMachineDescModel, StatusModel, OperatedMixin, ...@@ -642,6 +642,13 @@ class Instance(AclBase, VirtualMachineDescModel, StatusModel, OperatedMixin,
:param again: Notify already notified owners. :param again: Notify already notified owners.
""" """
notification_msg = ugettext_noop(
'Your instance <a href="%(url)s">%(instance)s</a> is going to '
'expire. It will be suspended at %(suspend)s and destroyed at '
'%(delete)s. Please, either <a href="%(token)s">renew</a> '
'or <a href="%(url)s">destroy</a> it now.')
if not again and self._is_notified_about_expiration(): if not again and self._is_notified_about_expiration():
return False return False
success, failed = [], [] success, failed = [], []
...@@ -672,10 +679,10 @@ class Instance(AclBase, VirtualMachineDescModel, StatusModel, OperatedMixin, ...@@ -672,10 +679,10 @@ class Instance(AclBase, VirtualMachineDescModel, StatusModel, OperatedMixin,
try: try:
token = VmRenewView.get_token_url(self, u) token = VmRenewView.get_token_url(self, u)
u.profile.notify( u.profile.notify(
_('%s expiring soon') % unicode(self), ugettext_noop('%(instance)s expiring soon'),
'dashboard/notifications/vm-expiring.html', notification_msg, url=self.get_absolute_url(),
{'instance': self, 'token': token}, valid_until=min( instance=self, suspend=self.time_of_suspend,
self.time_of_delete, self.time_of_suspend)) token=token, delete=self.time_of_delete)
except Exception as e: except Exception as e:
failed.append((u, e)) failed.append((u, e))
else: else:
......
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