Skip to content

Commit

Permalink
v0.0.8 : Изменены статусы нотификации
Browse files Browse the repository at this point in the history
  • Loading branch information
Sapunov committed Dec 17, 2017
1 parent 468d34e commit ddf31a5
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 24 deletions.
45 changes: 22 additions & 23 deletions tsanta/api/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -623,13 +623,12 @@ class Notification(models.Model):

STATES = (
(0, 'Created'),
(1, 'SendedToProvider'),
(2, 'RejectedByProvider'),
(3, 'Accepted'),
(4, 'TemporaryFailed'),
(5, 'FailedPermanently'),
(6, 'Delivered'),
(7, 'Opened')
(1, 'Rejected'),
(2, 'Accepted'),
(3, 'TemporaryFailed'),
(4, 'FailedPermanently'),
(5, 'Delivered'),
(6, 'Opened')
)

name = models.CharField(max_length=100)
Expand Down Expand Up @@ -668,9 +667,12 @@ def send_email_confirmation(self):
['email_confirmation'])

if provider_answer:
self.state = 1
self.state = 2
self.provider_mail_id = provider_answer
self.save()
else:
self.state = 1

self.save()

def send_participation_confirmation(self):

Expand Down Expand Up @@ -723,20 +725,20 @@ def send_ward(self):
['ward'])

if provider_answer:
self.state = 1
self.state = 2
self.provider_mail_id = provider_answer
self.save()

self.questionnaire.is_closed = True
self.questionnaire.save()
else:
raise ValueError(provider_answer)
self.state = 1

self.save()

@classmethod
def send_queued(cls):

for notification in cls.objects.all():
if notification.state == 0:
if notification.state == 0 or notification.state == 1:
if notification.type == 0:
notification.send_email_confirmation()
elif notification.type == 1:
Expand All @@ -762,7 +764,6 @@ def update_states(cls):
messages_processed = set()

for item in items:

try:
message_id = item['message']['headers']['message-id']
except KeyError:
Expand All @@ -782,25 +783,23 @@ def update_states(cls):
old_state = notification.state

if item['event'] == 'accepted':
notification.state = 3
elif item['event'] == 'rejected':
notification.state = 2
elif item['event'] == 'delivered':
notification.state = 6
notification.state = 5
elif item['event'] == 'failed':
if item['severity'] == 'temporary':
notification.state = 4
notification.state = 3
elif item['severity'] == 'permanent':
notification.state = 5
notification.state = 4
# Ниже одинаковые статусы так как любой и данных статусов
# провайдера означает открытое письмо, а открытие - финишный
# статус нотификации
elif item['event'] == 'opened':
notification.state = 7
notification.state = 6
elif item['event'] == 'clicked':
notification.state = 7
notification.state = 6
elif item['event'] == 'complained':
notification.state = 7
notification.state = 6
else:
continue

Expand Down
2 changes: 1 addition & 1 deletion tsanta/tsanta/settings.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import os


APP_VERSION = '0.0.7'
APP_VERSION = '0.0.8'

BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))

Expand Down

0 comments on commit ddf31a5

Please sign in to comment.