|
1 | | -from django.utils.translation import gettext as _ |
| 1 | +from django.utils.translation import gettext_lazy as _ |
2 | 2 | from openwisp_notifications.signals import notify |
3 | 3 | from swapper import load_model |
4 | 4 |
|
5 | 5 | from .. import settings as app_settings |
6 | 6 |
|
7 | 7 | MESSAGE_MAP = { |
8 | | - "device_error": { |
| 8 | + "whois_device_error": { |
| 9 | + "type": "generic_message", |
| 10 | + "level": "error", |
9 | 11 | "message": _( |
10 | 12 | "Failed to fetch WHOIS details for device" |
11 | 13 | " [{notification.target}]({notification.target_link})" |
12 | 14 | ), |
13 | 15 | "description": _("WHOIS details could not be fetched for ip: {ip_address}."), |
14 | | - "level": "error", |
15 | 16 | }, |
16 | | - "location_error": { |
| 17 | + "estimated_location_error": { |
| 18 | + "level": "error", |
| 19 | + "type": "estimated_location_info", |
17 | 20 | "message": _( |
18 | 21 | "Unable to create estimated location for device " |
19 | 22 | "[{notification.target}]({notification.target_link}). " |
20 | 23 | "Please assign/create a location manually." |
21 | 24 | ), |
22 | 25 | "description": _("Multiple devices found for IP: {ip_address}"), |
23 | | - "level": "error", |
| 26 | + }, |
| 27 | + "estimated_location_created": { |
| 28 | + "type": "estimated_location_info", |
| 29 | + "description": _("Estimated Location {notification.verb} for IP: {ip_address}"), |
| 30 | + }, |
| 31 | + "estimated_location_updated": { |
| 32 | + "type": "estimated_location_info", |
| 33 | + "message": _( |
| 34 | + "Estimated location [{notification.actor}]({notification.actor_link})" |
| 35 | + " for device" |
| 36 | + " [{notification.target}]({notification.target_link})" |
| 37 | + " updated successfully." |
| 38 | + ), |
| 39 | + "description": _("Estimated Location updated for IP: {ip_address}"), |
24 | 40 | }, |
25 | 41 | } |
26 | 42 |
|
27 | 43 |
|
28 | | -def send_whois_task_notification(device_pk, notify_type): |
| 44 | +def send_whois_task_notification(device_pk, notify_type, actor=None): |
29 | 45 | Device = load_model("config", "Device") |
30 | 46 |
|
31 | 47 | device = Device.objects.get(pk=device_pk) |
32 | 48 | notify_details = MESSAGE_MAP[notify_type] |
33 | 49 | notify.send( |
34 | | - sender=device, |
35 | | - type="generic_message", |
| 50 | + sender=actor or device, |
36 | 51 | target=device, |
37 | 52 | action_object=device, |
38 | | - level=notify_details["level"], |
39 | | - message=notify_details["message"], |
40 | | - description=notify_details["description"].format(ip_address=device.last_ip), |
| 53 | + ip_address=device.last_ip, |
| 54 | + **notify_details, |
41 | 55 | ) |
42 | 56 |
|
43 | 57 |
|
|
0 commit comments