Commit 18e18dfa by Bach Dániel

Merge branch 'feature-renew-url' into 'master'

Renew url 

See merge request !332
parents de40af4b 38fe0dda
...@@ -17,6 +17,7 @@ ...@@ -17,6 +17,7 @@
from __future__ import absolute_import from __future__ import absolute_import
from datetime import timedelta
from itertools import chain from itertools import chain
from hashlib import md5 from hashlib import md5
from logging import getLogger from logging import getLogger
...@@ -31,6 +32,7 @@ from django.db.models import ( ...@@ -31,6 +32,7 @@ from django.db.models import (
) )
from django.db.models.signals import post_save, pre_delete, post_delete from django.db.models.signals import post_save, pre_delete, post_delete
from django.templatetags.static import static from django.templatetags.static import static
from django.utils import timezone
from django.utils.html import escape from django.utils.html import escape
from django.utils.translation import ugettext_lazy as _ from django.utils.translation import ugettext_lazy as _
from django_sshkey.models import UserKey from django_sshkey.models import UserKey
...@@ -132,6 +134,17 @@ class Notification(TimeStampedModel): ...@@ -132,6 +134,17 @@ class Notification(TimeStampedModel):
def message(self, value): def message(self, value):
self.message_data = None if value is None else value.to_dict() self.message_data = None if value is None else value.to_dict()
@property
def has_valid_renew_url(self):
params = self.message_data['params']
return ('token' in params and 'suspend' in params and
self.modified > timezone.now() - timedelta(days=3))
@property
def renew_url(self):
return (settings.DJANGO_URL.rstrip("/") +
str(self.message_data['params'].get('token')))
class ConnectCommand(Model): class ConnectCommand(Model):
user = ForeignKey(User, related_name='command_set') user = ForeignKey(User, related_name='command_set')
......
...@@ -4,7 +4,9 @@ ...@@ -4,7 +4,9 @@
{% blocktrans count n=messages|length %}You have a new notification:{% plural %}You have {{n}} new notifications:{% endblocktrans %} {% blocktrans count n=messages|length %}You have a new notification:{% plural %}You have {{n}} new notifications:{% endblocktrans %}
{% for msg in messages %} * {{msg.subject}} {% for msg in messages %} * {{msg.subject}}{% if msg.has_valid_renew_url %}
{% trans "You can renew it without logging in:" %}
{{ msg.renew_url }}{% endif %}
{% endfor %} {% endfor %}
{% blocktrans with url=url count n=messages|length %}See it in detail on <{{url}}>.{% plural %} See them in detail on <{{url}}>.{% endblocktrans %} {% blocktrans with url=url count n=messages|length %}See it in detail on <{{url}}>.{% plural %} See them in detail on <{{url}}>.{% endblocktrans %}
......
This source diff could not be displayed because it is too large. You can view the blob instead.
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