# Path: sendinel/infoservices/forms.py
# class InfoServiceValidationForm(ModelForm):
#     class Meta:
#         model = InfoService
#         exclude = ['members']
# 
#     name = CharField(error_messages={ \
#                         'required': _('Please enter a name'), \
#                         'invalid': _('The name contains invalid characters')})
# 
# 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]
# 
# class Subscription(models.Model):
#     """
#     Represents a patient's subscription to an infoservice
#     """
# 
#     patient = models.ForeignKey(Patient)
#     infoservice = models.ForeignKey(InfoService)
# 
#     way_of_communication = models.ForeignKey(WayOfCommunication)
# 
#     def __unicode__(self):
#         return "%s %s" % (unicode(self.infoservice), \
#                           unicode(self.patient.phone_number))
# 
# 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):


from django.shortcuts import render_to_response, get_object_or_404
from django.template import RequestContext
from django.http import HttpResponseRedirect
from django.core.urlresolvers import reverse
from django.utils.translation import ugettext as _
from sendinel.infoservices.forms import InfoServiceValidationForm
from sendinel.infoservices.models import InfoService, Subscription
from sendinel.logger import logger, log_request
        data = {'name': request.POST['name'],
                'type': infoservice_type}
        form = InfoServiceValidationForm(data)
    
        if form.is_valid():
            form.save()
            infoservice = form.instance
            
            logger.info("Created InfoService: %s", str(infoservice))
            
            nexturl = reverse('infoservices_index', 
                              kwargs={'infoservice_type': infoservice_type})
            backurl = reverse('infoservices_create', 
                              kwargs={'infoservice_type': infoservice_type})
            title = _("Creation successful")
            message = _("The \"%(infoservice_name)s\" "
                        "%(infoservice_type)s has been created.") \
                        % {'infoservice_name': infoservice.name,
                           'infoservice_type': infoservice_textblocks["name"]}
            new_button_label = _("Create another %(infoservice_type)s") \
                            % {'infoservice_type': infoservice_textblocks['name']}
            success = True
            
            return render_to_response('web/status_message.html', 
                          locals(),
                          context_instance = RequestContext(request))
    return render_to_response("infoservices/create.html",
                                locals(),
                                context_instance = RequestContext(request))
                                

# Path: sendinel/infoservices/forms.py
# class InfoServiceValidationForm(ModelForm):
#     class Meta:
#         model = InfoService
#         exclude = ['members']
# 
#     name = CharField(error_messages={ \
#                         'required': _('Please enter a name'), \
#                         'invalid': _('The name contains invalid characters')})
# 
# 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]
# 
# class Subscription(models.Model):
#     """
#     Represents a patient's subscription to an infoservice
#     """
# 
#     patient = models.ForeignKey(Patient)
#     infoservice = models.ForeignKey(InfoService)
# 
#     way_of_communication = models.ForeignKey(WayOfCommunication)
# 
#     def __unicode__(self):
#         return "%s %s" % (unicode(self.infoservice), \
#                           unicode(self.patient.phone_number))
# 
# 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/infoservices/views.py
from django.shortcuts import render_to_response, get_object_or_404
from django.template import RequestContext
from django.http import HttpResponseRedirect
from django.core.urlresolvers import reverse
from django.utils.translation import ugettext as _
from sendinel.infoservices.forms import InfoServiceValidationForm
from sendinel.infoservices.models import InfoService, Subscription
from sendinel.logger import logger, log_request

        data = {'name': request.POST['name'],
                'type': infoservice_type}
        form = InfoServiceValidationForm(data)
    
        if form.is_valid():
            form.save()
            infoservice = form.instance
            
            logger.info("Created InfoService: %s", str(infoservice))
            
            nexturl = reverse('infoservices_index', 
                              kwargs={'infoservice_type': infoservice_type})
            backurl = reverse('infoservices_create', 
                              kwargs={'infoservice_type': infoservice_type})
            title = _("Creation successful")
            message = _("The \"%(infoservice_name)s\" "
                        "%(infoservice_type)s has been created.") \
                        % {'infoservice_name': infoservice.name,
                           'infoservice_type': infoservice_textblocks["name"]}
            new_button_label = _("Create another %(infoservice_type)s") \
                            % {'infoservice_type': infoservice_textblocks['name']}
            success = True
            
            return render_to_response('web/status_message.html', 
                          locals(),
                          context_instance = RequestContext(request))
    return render_to_response("infoservices/create.html",
                                locals(),
                                context_instance = RequestContext(request))
                                

@log_request