1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136
|
from django.core.exceptions import ImproperlyConfigured
from django.utils.six import string_types
from .base import BaseConfig
from ..settings import PUSH_NOTIFICATIONS_SETTINGS as SETTINGS
__all__ = [
"LegacyConfig"
]
class empty(object):
pass
class LegacyConfig(BaseConfig):
def _get_application_settings(self, application_id, settings_key, error_message):
"""Legacy behaviour"""
if not application_id:
value = SETTINGS.get(settings_key, empty)
if value is empty:
raise ImproperlyConfigured(error_message)
return value
else:
msg = (
"LegacySettings does not support application_id. To enable "
"multiple application support, use push_notifications.conf.AppSettings."
)
raise ImproperlyConfigured(msg)
def get_gcm_api_key(self, application_id=None):
msg = (
"Set PUSH_NOTIFICATIONS_SETTINGS[\"GCM_API_KEY\"] to send messages through GCM."
)
return self._get_application_settings(application_id, "GCM_API_KEY", msg)
def get_fcm_api_key(self, application_id=None):
msg = (
"Set PUSH_NOTIFICATIONS_SETTINGS[\"FCM_API_KEY\"] to send messages through FCM."
)
return self._get_application_settings(application_id, "FCM_API_KEY", msg)
def get_post_url(self, cloud_type, application_id=None):
key = "{}_POST_URL".format(cloud_type)
msg = (
"Set PUSH_NOTIFICATIONS_SETTINGS[\"{}\"] to send messages through {}.".format(
key, cloud_type
)
)
return self._get_application_settings(application_id, key, msg)
def get_error_timeout(self, cloud_type, application_id=None):
key = "{}_ERROR_TIMEOUT".format(cloud_type)
msg = (
"Set PUSH_NOTIFICATIONS_SETTINGS[\"{}\"] to send messages through {}.".format(
key, cloud_type
)
)
return self._get_application_settings(application_id, key, msg)
def get_max_recipients(self, cloud_type, application_id=None):
key = "{}_MAX_RECIPIENTS".format(cloud_type)
msg = (
"Set PUSH_NOTIFICATIONS_SETTINGS[\"{}\"] to send messages through {}.".format(
key, cloud_type
)
)
return self._get_application_settings(application_id, key, msg)
def get_apns_certificate(self, application_id=None):
r = self._get_application_settings(
application_id, "APNS_CERTIFICATE",
"You need to setup PUSH_NOTIFICATIONS_SETTINGS properly to send messages"
)
if not isinstance(r, string_types):
# probably the (Django) file, and file path should be got
if hasattr(r, "path"):
return r.path
elif (hasattr(r, "has_key") or hasattr(r, "__contains__")) and "path" in r:
return r["path"]
else:
msg = (
"The APNS certificate settings value should be a string, or "
"should have a 'path' attribute or key"
)
raise ImproperlyConfigured(msg)
return r
def get_apns_use_sandbox(self, application_id=None):
msg = "Setup PUSH_NOTIFICATIONS_SETTINGS properly to send messages"
return self._get_application_settings(application_id, "APNS_USE_SANDBOX", msg)
def get_apns_use_alternative_port(self, application_id=None):
msg = "Setup PUSH_NOTIFICATIONS_SETTINGS properly to send messages"
return self._get_application_settings(application_id, "APNS_USE_ALTERNATIVE_PORT", msg)
def get_apns_topic(self, application_id=None):
msg = "Setup PUSH_NOTIFICATIONS_SETTINGS properly to send messages"
return self._get_application_settings(application_id, "APNS_TOPIC", msg)
def get_apns_host(self, application_id=None):
msg = "Setup PUSH_NOTIFICATIONS_SETTINGS properly to send messages"
return self._get_application_settings(application_id, "APNS_HOST", msg)
def get_apns_port(self, application_id=None):
msg = "Setup PUSH_NOTIFICATIONS_SETTINGS properly to send messages"
return self._get_application_settings(application_id, "APNS_PORT", msg)
def get_apns_feedback_host(self, application_id=None):
msg = "Setup PUSH_NOTIFICATIONS_SETTINGS properly to send messages"
return self._get_application_settings(application_id, "APNS_FEEDBACK_HOST", msg)
def get_apns_feedback_port(self, application_id=None):
msg = "Setup PUSH_NOTIFICATIONS_SETTINGS properly to send messages"
return self._get_application_settings(application_id, "APNS_FEEDBACK_PORT", msg)
def get_wns_package_security_id(self, application_id=None):
msg = "Setup PUSH_NOTIFICATIONS_SETTINGS properly to send messages"
return self._get_application_settings(application_id, "WNS_PACKAGE_SECURITY_ID", msg)
def get_wns_secret_key(self, application_id=None):
msg = "Setup PUSH_NOTIFICATIONS_SETTINGS properly to send messages"
return self._get_application_settings(application_id, "WNS_SECRET_KEY", msg)
def get_wp_post_url(self, application_id, browser):
msg = "Setup PUSH_NOTIFICATIONS_SETTINGS properly to send messages"
return self._get_application_settings(application_id, "WP_POST_URL", msg)[browser]
def get_wp_private_key(self, application_id=None):
msg = "Setup PUSH_NOTIFICATIONS_SETTINGS properly to send messages"
return self._get_application_settings(application_id, "WP_PRIVATE_KEY", msg)
def get_wp_claims(self, application_id=None):
msg = "Setup PUSH_NOTIFICATIONS_SETTINGS properly to send messages"
return self._get_application_settings(application_id, "WP_CLAIMS", msg)
|