# Path: sendinel/backend/authhelper.py
# def format_and_validate_phonenumber(number):
#     """
#     Replaces all number specific characters like
#     "+", "-" and "/" and checks that there are no
#     letters included. Checks also if the number is 
#     the number of a mobile phone.
#     
#     @param  number:     The phone number that will be checked
#     @type   number:     string
#     
#     @raise  ValueError
#     """
#    
#     if number.startswith('+'):
#         number = number.replace('+', '00', 1)
#     
#     regex = re.compile('(\/|\+|-| )')
#     number = regex.sub('', number)
#     
#     if number.startswith(COUNTRY_CODE_PHONE):
#         number = number.replace(COUNTRY_CODE_PHONE, '0', 1)
# 
#     # if the conversion to int does not fail then
#     # there are only numbers included in the string
#     try:
#         int(number)
#     except ValueError:
#         raise ValidationError(_('Please enter numbers only.'))
#     
#     if number.startswith(START_MOBILE_PHONE):
#         return number
#     else:
#         raise ValidationError(_('Please enter a cell phone number.'))
# 
# Path: sendinel/backend/models.py
# class Sendable(models.Model):
#     """
#     Define an interface for a Sendable object.
#     """
# 
#     class Meta:
#         abstract = True
#         
#     way_of_communication = models.ForeignKey(WayOfCommunication)
# 
#     recipient = models.ForeignKey(Patient)
#     
#     def __unicode__(self):
#         return "%s %s" % (unicode(self.recipient), self.way_of_communication.verbose_name)
#     
#     def get_data_for_sending(self):
#         """
#         Prepare OutputData for selected way_of_communication.
#         Return an object of a subclass of OutputData.
#         """
#         
#         call = "self.get_data_for_%s()" % self.way_of_communication.name      
#         logger.info("sendable.get_data_for_sending() calling method: " + call)        
#         return eval(call)
#         
#     def create_scheduled_event(self, send_time):
#         """
#         Create a scheduled event for a specific send_time
#         @param send_time: Datetime object with the time of the reminder 
#         """        
#         scheduled_event = ScheduledEvent(sendable = self,
#                                          send_time = send_time)
#         scheduled_event.save()
# 
# class WayOfCommunication(models.Model):
#     """
#     Represent a possible Way of Communication like SMS
#     """
#     
#     name = models.CharField(max_length = 255, blank = False, null = False)
#     verbose_name = models.CharField(max_length = 255)
#     enabled = models.BooleanField()
#     can_send_immediately = models.BooleanField()
#     
#     def __unicode__(self):
#         return self.verbose_name
# 
# def get_enabled_wocs():
#     """
#     Return all Ways of Communication that are enabled
#     """
#     return WayOfCommunication.objects.all().filter(enabled = True)


from django.forms import CharField, ModelChoiceField, DateTimeField, Form
from django.utils.translation import ugettext as _
from sendinel.backend.authhelper import format_and_validate_phonenumber
from sendinel.backend.models import Sendable, \
                                    WayOfCommunication, \
                                    get_enabled_wocs



class NotificationValidationForm(Form):
    phone_number = CharField(validators = [format_and_validate_phonenumber],
            error_messages={'required':_('Please enter a phone number')})

    
    way_of_communication = ModelChoiceField(
                                queryset = get_enabled_wocs(),
                                error_messages={'required': \
                                _('Please choose a way of communication')})
    date = DateTimeField(error_messages={ \
                            'required': _('Please choose a date'), \
                            'invalid': _('Please choose a date')})              

class NotificationValidationFormBluetooth(Form):
    
    way_of_communication = ModelChoiceField(

# Path: sendinel/backend/authhelper.py
# def format_and_validate_phonenumber(number):
#     """
#     Replaces all number specific characters like
#     "+", "-" and "/" and checks that there are no
#     letters included. Checks also if the number is 
#     the number of a mobile phone.
#     
#     @param  number:     The phone number that will be checked
#     @type   number:     string
#     
#     @raise  ValueError
#     """
#    
#     if number.startswith('+'):
#         number = number.replace('+', '00', 1)
#     
#     regex = re.compile('(\/|\+|-| )')
#     number = regex.sub('', number)
#     
#     if number.startswith(COUNTRY_CODE_PHONE):
#         number = number.replace(COUNTRY_CODE_PHONE, '0', 1)
# 
#     # if the conversion to int does not fail then
#     # there are only numbers included in the string
#     try:
#         int(number)
#     except ValueError:
#         raise ValidationError(_('Please enter numbers only.'))
#     
#     if number.startswith(START_MOBILE_PHONE):
#         return number
#     else:
#         raise ValidationError(_('Please enter a cell phone number.'))
# 
# Path: sendinel/backend/models.py
# class Sendable(models.Model):
#     """
#     Define an interface for a Sendable object.
#     """
# 
#     class Meta:
#         abstract = True
#         
#     way_of_communication = models.ForeignKey(WayOfCommunication)
# 
#     recipient = models.ForeignKey(Patient)
#     
#     def __unicode__(self):
#         return "%s %s" % (unicode(self.recipient), self.way_of_communication.verbose_name)
#     
#     def get_data_for_sending(self):
#         """
#         Prepare OutputData for selected way_of_communication.
#         Return an object of a subclass of OutputData.
#         """
#         
#         call = "self.get_data_for_%s()" % self.way_of_communication.name      
#         logger.info("sendable.get_data_for_sending() calling method: " + call)        
#         return eval(call)
#         
#     def create_scheduled_event(self, send_time):
#         """
#         Create a scheduled event for a specific send_time
#         @param send_time: Datetime object with the time of the reminder 
#         """        
#         scheduled_event = ScheduledEvent(sendable = self,
#                                          send_time = send_time)
#         scheduled_event.save()
# 
# class WayOfCommunication(models.Model):
#     """
#     Represent a possible Way of Communication like SMS
#     """
#     
#     name = models.CharField(max_length = 255, blank = False, null = False)
#     verbose_name = models.CharField(max_length = 255)
#     enabled = models.BooleanField()
#     can_send_immediately = models.BooleanField()
#     
#     def __unicode__(self):
#         return self.verbose_name
# 
# def get_enabled_wocs():
#     """
#     Return all Ways of Communication that are enabled
#     """
#     return WayOfCommunication.objects.all().filter(enabled = True)


# Path: sendinel/notifications/forms.py
from django.forms import CharField, ModelChoiceField, DateTimeField, Form
from django.utils.translation import ugettext as _
from sendinel.backend.authhelper import format_and_validate_phonenumber
from sendinel.backend.models import Sendable, \
                                    WayOfCommunication, \
                                    get_enabled_wocs




class NotificationValidationForm(Form):
    phone_number = CharField(validators = [format_and_validate_phonenumber],
            error_messages={'required':_('Please enter a phone number')})

    
    way_of_communication = ModelChoiceField(
                                queryset = get_enabled_wocs(),
                                error_messages={'required': \
                                _('Please choose a way of communication')})
    date = DateTimeField(error_messages={ \
                            'required': _('Please choose a date'), \
                            'invalid': _('Please choose a date')})              

class NotificationValidationFormBluetooth(Form):
    
    way_of_communication = ModelChoiceField(

                        queryset = get_enabled_wocs(),