
from django.apps import apps
from django.template.loader import render_to_string

from turbosms.settings import IS_SMS_ENABLED, SMS_RECIPIENTS
from turbosms.models import SMS


def get_recipients():

    if apps.is_installed('site_config'):

        from site_config import config

        if hasattr(config, 'SMS_RECIPIENTS'):
            return config.SMS_RECIPIENTS

    return SMS_RECIPIENTS


def send_sms(message):

    if IS_SMS_ENABLED:
        for number in get_recipients():
            SMS.objects.create(number=number, message=message)


def send_sms_from_template(template_name, context=None):
    message = render_to_string(template_name, context)
    send_sms(message)


from django.apps import apps
from django.template.loader import render_to_string

from turbosms.settings import IS_SMS_ENABLED, SMS_RECIPIENTS
from turbosms.models import SMS


def get_default_sms_recipients():

    if apps.is_installed('site_config'):

        from site_config import config

        if hasattr(config, 'SMS_RECIPIENTS'):
            return config.SMS_RECIPIENTS

    return SMS_RECIPIENTS


def send_sms(message, recipients=None):

    if not IS_SMS_ENABLED:
        return

    if recipients is None:
        recipients = get_default_sms_recipients()

    for number in recipients:
        SMS.objects.create(number=number, message=message)


def send_sms_from_template(template_name, context=None):
    message = render_to_string(template_name, context)
    send_sms(message)

Add recipients param to send_sms method.
Add recipients param to send_sms method.

  
  from django.apps import apps
  from django.template.loader import render_to_string
  
  from turbosms.settings import IS_SMS_ENABLED, SMS_RECIPIENTS
  from turbosms.models import SMS
  
  
- def get_recipients():
+ def get_default_sms_recipients():
  
      if apps.is_installed('site_config'):
  
          from site_config import config
  
          if hasattr(config, 'SMS_RECIPIENTS'):
              return config.SMS_RECIPIENTS
  
      return SMS_RECIPIENTS
  
  
- def send_sms(message):
+ def send_sms(message, recipients=None):
  
-     if IS_SMS_ENABLED:
+     if not IS_SMS_ENABLED:
+         return
+ 
+     if recipients is None:
+         recipients = get_default_sms_recipients()
+ 
-         for number in get_recipients():
+     for number in recipients:
-             SMS.objects.create(number=number, message=message)
+         SMS.objects.create(number=number, message=message)
  
  
  def send_sms_from_template(template_name, context=None):
      message = render_to_string(template_name, context)
      send_sms(message)
  
Add recipients param to send_sms method.
## Code Before:

from django.apps import apps
from django.template.loader import render_to_string

from turbosms.settings import IS_SMS_ENABLED, SMS_RECIPIENTS
from turbosms.models import SMS


def get_recipients():

    if apps.is_installed('site_config'):

        from site_config import config

        if hasattr(config, 'SMS_RECIPIENTS'):
            return config.SMS_RECIPIENTS

    return SMS_RECIPIENTS


def send_sms(message):

    if IS_SMS_ENABLED:
        for number in get_recipients():
            SMS.objects.create(number=number, message=message)


def send_sms_from_template(template_name, context=None):
    message = render_to_string(template_name, context)
    send_sms(message)

## Instruction:
Add recipients param to send_sms method.
## Code After:

from django.apps import apps
from django.template.loader import render_to_string

from turbosms.settings import IS_SMS_ENABLED, SMS_RECIPIENTS
from turbosms.models import SMS


def get_default_sms_recipients():

    if apps.is_installed('site_config'):

        from site_config import config

        if hasattr(config, 'SMS_RECIPIENTS'):
            return config.SMS_RECIPIENTS

    return SMS_RECIPIENTS


def send_sms(message, recipients=None):

    if not IS_SMS_ENABLED:
        return

    if recipients is None:
        recipients = get_default_sms_recipients()

    for number in recipients:
        SMS.objects.create(number=number, message=message)


def send_sms_from_template(template_name, context=None):
    message = render_to_string(template_name, context)
    send_sms(message)
