# Path: sendinel/backend/bluetooth.py
# def set_connection_to_bluetooth(server_address):
# def get_discovered_devices(server_address):
# def send_vcal(server_address, mac, data):
# 
# Path: sendinel/backend/authhelper.py
# def check_and_delete_authentication_call(number):
#     """
#     Try to find an AuthenticationCall for the given phone numner.
#     The last seven digits are compared to identify the call.
#     """
#     
#     number = format_and_validate_phonenumber(number)
#     
#     last_seven_digits = number[-7:]
#     calls = AuthenticationCall.objects.filter( \
#                                     number__endswith = last_seven_digits)
#     
#     if calls.count() == 1:
#         calls.delete()
#         return True
#     
#     return False
# 
# def delete_timed_out_authentication_calls():
#     """
#     Find and delete all timed out authentication calls.
#     This can be configured through settings.
#     """
#     
#     timeout = datetime.now() - AUTHENTICATION_CALL_TIMEOUT
#     AuthenticationCall.objects.filter(time__lt = timeout).delete()
# 
# Path: sendinel/infoservices/models.py
# class InfoService(models.Model):
#     """
#     Represent a user group.
#     Existing types are 'information' and 'medicine' 
#     whereas information-groups send regular messages to their 
#     subscribers, medicine deletes the group after sending a message
#     """
#     
#     TYPES = (
#         ('information', ugettext_lazy("Information Group")),
#         ('medicine', ugettext_lazy('Waiting List for Medicine'))
#     )
#     TYPE_TEXTS = {
#         'information': {
#             'title': ugettext_lazy('Information Groups'),
#             'name': ugettext_lazy('information group'),
#             'members_button': ugettext_lazy('Group members'),
#             'remove_button': ugettext_lazy('Remove group'),
#             'remove_patient_button': ugettext_lazy('Remove patient from group'),
#             'form_field_description': ugettext_lazy('Inform patients about:'),
#             'table_head': ugettext_lazy('Information')
#         },
#         'medicine': {
#             'title': ugettext_lazy('Waiting Lists for Medicine'),
#             'name': ugettext_lazy('waiting list for medicine'),
#             'members_button': ugettext_lazy('List members'),
#             'remove_button': ugettext_lazy('Remove list'),
#             'remove_patient_button': ugettext_lazy('Remove patient from list'),
#             'form_field_description':
#             ugettext_lazy('The patients are waiting for the following medicine:'),
#             'table_head': ugettext_lazy('Medicine')
#         },
#     }
#     
#     
#     members = models.ManyToManyField(Patient, through = "Subscription")
#     name = models.CharField(max_length = 255,
#                             default = None,
#                             unique = True,
#                             blank = False,
#                             null = False,
#                             verbose_name = ugettext_lazy("name"))
#     type = models.CharField(max_length = 255, 
#                             choices = TYPES,
#                             default = None,
#                             blank = False, 
#                             null = False)
#     
#     class Meta:
#         verbose_name = ugettext_lazy("Information service")
#                             
#     def __unicode__(self):
#         return self.name
#     
#     def member_count(self):
#         return self.members.all().count()
#     
#     def texts(self):
#         """
#         Returns the text blocks associated with the group's type.
#         """
#         return self.TYPE_TEXTS[self.type]
# 
# Path: sendinel/notifications/models.py
# class NotificationType(models.Model):
#     """
#     Represent an notification type like follow-up consultation.
#     """
#     
#     name = models.CharField(max_length = 255)
#     verbose_name = models.CharField(max_length = 255)
#     template = models.CharField(max_length = 255)
#     notify_immediately = models.BooleanField()
# 
#     def __unicode__(self):
#         return self.verbose_name
#     
#     @classmethod
#     def get_notification_type(cls, type_name):
#         """
#         Return the given NotificationType
#         """
#         
#         notification_type = NotificationType.objects.get(name = type_name)
#         
#         return notification_type
# 
# Path: sendinel/logger.py
# LOG_MSG_FORMAT = '%(asctime)s %(levelname)s %(filename)s#%(lineno)d %(message)s'
# def log_request(viewfunc):
#     def do_log_request(*args, **kwargs):
# 
# Path: sendinel/settings.py
# AUTH_NUMBER = "CHANGE ME"
# 
# AUTHENTICATION_CALL_TIMEOUT = timedelta(minutes = 3)
# 
# Path: sendinel/web/utils.py
# def fill_authentication_session_variable(request):
#     number = request.session["patient"].phone_number
#     number = format_and_validate_phonenumber(number)
#     request.session['authenticate_phonenumber'] = \
#                             { 'number': number,
#                               'start_time': datetime.now() }
#     return number


﻿from datetime import datetime
from django.core.urlresolvers import reverse
from django.http import HttpResponse
from django.shortcuts import render_to_response
from django.template import RequestContext
from django.utils import simplejson
from django.views.i18n import javascript_catalog
from django.utils.translation import ugettext as _
from sendinel.backend import bluetooth
from sendinel.backend.authhelper import check_and_delete_authentication_call, \
                                    delete_timed_out_authentication_calls
from sendinel.infoservices.models import InfoService
from sendinel.notifications.models import NotificationType
from sendinel.logger import logger, log_request
from sendinel.settings import   AUTH_NUMBER, \
                                AUTHENTICATION_CALL_TIMEOUT
from sendinel.web.utils import fill_authentication_session_variable




@log_request
def index(request):
    groups = InfoService.objects.all().filter(type="information")
    medicine_empty = True

# Path: sendinel/backend/bluetooth.py
# def set_connection_to_bluetooth(server_address):
# def get_discovered_devices(server_address):
# def send_vcal(server_address, mac, data):
# 
# Path: sendinel/backend/authhelper.py
# def check_and_delete_authentication_call(number):
#     """
#     Try to find an AuthenticationCall for the given phone numner.
#     The last seven digits are compared to identify the call.
#     """
#     
#     number = format_and_validate_phonenumber(number)
#     
#     last_seven_digits = number[-7:]
#     calls = AuthenticationCall.objects.filter( \
#                                     number__endswith = last_seven_digits)
#     
#     if calls.count() == 1:
#         calls.delete()
#         return True
#     
#     return False
# 
# def delete_timed_out_authentication_calls():
#     """
#     Find and delete all timed out authentication calls.
#     This can be configured through settings.
#     """
#     
#     timeout = datetime.now() - AUTHENTICATION_CALL_TIMEOUT
#     AuthenticationCall.objects.filter(time__lt = timeout).delete()
# 
# Path: sendinel/infoservices/models.py
# class InfoService(models.Model):
#     """
#     Represent a user group.
#     Existing types are 'information' and 'medicine' 
#     whereas information-groups send regular messages to their 
#     subscribers, medicine deletes the group after sending a message
#     """
#     
#     TYPES = (
#         ('information', ugettext_lazy("Information Group")),
#         ('medicine', ugettext_lazy('Waiting List for Medicine'))
#     )
#     TYPE_TEXTS = {
#         'information': {
#             'title': ugettext_lazy('Information Groups'),
#             'name': ugettext_lazy('information group'),
#             'members_button': ugettext_lazy('Group members'),
#             'remove_button': ugettext_lazy('Remove group'),
#             'remove_patient_button': ugettext_lazy('Remove patient from group'),
#             'form_field_description': ugettext_lazy('Inform patients about:'),
#             'table_head': ugettext_lazy('Information')
#         },
#         'medicine': {
#             'title': ugettext_lazy('Waiting Lists for Medicine'),
#             'name': ugettext_lazy('waiting list for medicine'),
#             'members_button': ugettext_lazy('List members'),
#             'remove_button': ugettext_lazy('Remove list'),
#             'remove_patient_button': ugettext_lazy('Remove patient from list'),
#             'form_field_description':
#             ugettext_lazy('The patients are waiting for the following medicine:'),
#             'table_head': ugettext_lazy('Medicine')
#         },
#     }
#     
#     
#     members = models.ManyToManyField(Patient, through = "Subscription")
#     name = models.CharField(max_length = 255,
#                             default = None,
#                             unique = True,
#                             blank = False,
#                             null = False,
#                             verbose_name = ugettext_lazy("name"))
#     type = models.CharField(max_length = 255, 
#                             choices = TYPES,
#                             default = None,
#                             blank = False, 
#                             null = False)
#     
#     class Meta:
#         verbose_name = ugettext_lazy("Information service")
#                             
#     def __unicode__(self):
#         return self.name
#     
#     def member_count(self):
#         return self.members.all().count()
#     
#     def texts(self):
#         """
#         Returns the text blocks associated with the group's type.
#         """
#         return self.TYPE_TEXTS[self.type]
# 
# Path: sendinel/notifications/models.py
# class NotificationType(models.Model):
#     """
#     Represent an notification type like follow-up consultation.
#     """
#     
#     name = models.CharField(max_length = 255)
#     verbose_name = models.CharField(max_length = 255)
#     template = models.CharField(max_length = 255)
#     notify_immediately = models.BooleanField()
# 
#     def __unicode__(self):
#         return self.verbose_name
#     
#     @classmethod
#     def get_notification_type(cls, type_name):
#         """
#         Return the given NotificationType
#         """
#         
#         notification_type = NotificationType.objects.get(name = type_name)
#         
#         return notification_type
# 
# Path: sendinel/logger.py
# LOG_MSG_FORMAT = '%(asctime)s %(levelname)s %(filename)s#%(lineno)d %(message)s'
# def log_request(viewfunc):
#     def do_log_request(*args, **kwargs):
# 
# Path: sendinel/settings.py
# AUTH_NUMBER = "CHANGE ME"
# 
# AUTHENTICATION_CALL_TIMEOUT = timedelta(minutes = 3)
# 
# Path: sendinel/web/utils.py
# def fill_authentication_session_variable(request):
#     number = request.session["patient"].phone_number
#     number = format_and_validate_phonenumber(number)
#     request.session['authenticate_phonenumber'] = \
#                             { 'number': number,
#                               'start_time': datetime.now() }
#     return number


# Path: sendinel/web/views.py
﻿from datetime import datetime
from django.core.urlresolvers import reverse
from django.http import HttpResponse
from django.shortcuts import render_to_response
from django.template import RequestContext
from django.utils import simplejson
from django.views.i18n import javascript_catalog
from django.utils.translation import ugettext as _
from sendinel.backend import bluetooth
from sendinel.backend.authhelper import check_and_delete_authentication_call, \
                                    delete_timed_out_authentication_calls
from sendinel.infoservices.models import InfoService
from sendinel.notifications.models import NotificationType
from sendinel.logger import logger, log_request
from sendinel.settings import   AUTH_NUMBER, \
                                AUTHENTICATION_CALL_TIMEOUT
from sendinel.web.utils import fill_authentication_session_variable





@log_request
def index(request):
    groups = InfoService.objects.all().filter(type="information")
    medicine_empty = True

    for medicine in InfoService.objects.all().filter(type="medicine"):