Completed
Branch master (206998)
by Paolo
04:19
created

submissions.helpers   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 41
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 2
eloc 14
dl 0
loc 41
rs 10
c 0
b 0
f 0

1 Function

Rating   Name   Duplication   Size   Complexity  
A send_message() 0 26 2
1
#!/usr/bin/env python3
2
# -*- coding: utf-8 -*-
3
"""
4
Created on Thu Jun 27 11:52:37 2019
5
6
@author: Paolo Cozzi <[email protected]>
7
"""
8
9
import asyncio
10
11
from common.constants import STATUSES
12
from common.helpers import send_message_to_websocket
13
14
15
def send_message(submission_obj, validation_message=None):
16
    """
17
    Update submission.status and submission message using django
18
    channels
19
20
    Args:
21
        submission_obj (image_app.models.Submission): an UID submission
22
        object
23
        validation_message (dict): set validation message
24
    """
25
26
    # define a message to send
27
    message = {
28
        'message': STATUSES.get_value_display(submission_obj.status),
29
        'notification_message': submission_obj.message,
30
    }
31
32
    # if validation message is needed, add to the final message
33
    if validation_message:
34
        message['validation_message'] = validation_message
35
36
    # now send the message to its submission
37
    asyncio.get_event_loop().run_until_complete(
38
        send_message_to_websocket(
39
            message,
40
            submission_obj.pk
41
        )
42
    )
43