<commit_before>from django.core.urlresolvers import reverse
from django.http import HttpResponseRedirect, HttpResponse
from django.shortcuts import render_to_response
from django.template import RequestContext
from django.utils import simplejson

from sendinel.backend.models import Patient, ScheduledEvent
from sendinel.backend.authhelper import AuthHelper
from sendinel.web.forms import *

def index(request):
    return render_to_response('start.html',
                              context_instance=RequestContext(request))

def create_appointment(request):
    form = HospitalAppointmentForm(request.POST)
    
    if request.method == "POST" and form.is_valid():
        appointment = form.save(commit=False)
        
        patient = Patient(name = form.cleaned_data['recipient_name'])
        patient.save()
        
        appointment.recipient = patient
        appointment.save()
        
        if appointment.way_of_communication != 'bluetooth':
            appointment.create_scheduled_event()

        return HttpResponseRedirect(reverse('index'))
    else:
        return render_to_response('create_appointment.html',
                                locals(),
                                context_instance=RequestContext(request))

def authenticate_phonenumber(request):
    
    if request.method == "POST":
        authHelper = AuthHelper()
        
        number = request.REQUEST["number"]
        name = request.REQUEST["name"]
        
        number = authHelper.authenticate(number, name)
        if number:
            return render_to_response('authenticate_phonenumber_call.html', 
                                      locals(),
                                      context_instance = RequestContext(request))
        else:
            # there should happen something if the number was not valid
            pass
    
    return render_to_response('authenticate_phonenumber.html', 
                              locals(),
                              context_instance = RequestContext(request))
<commit_msg>Save name and number in session. Work in Progress.<commit_after>from django.core.urlresolvers import reverse
from django.http import HttpResponseRedirect, HttpResponse
from django.shortcuts import render_to_response
from django.template import RequestContext
from django.utils import simplejson

from sendinel.backend.models import Patient, ScheduledEvent
from sendinel.backend.authhelper import AuthHelper
from sendinel.web.forms import *

def index(request):
    return render_to_response('start.html',
                              context_instance=RequestContext(request))

def create_appointment(request):
    form = HospitalAppointmentForm(request.POST)
    
    if request.method == "POST" and form.is_valid():
        appointment = form.save(commit=False)
        
        patient = Patient(name = form.cleaned_data['recipient_name'])
        patient.save()
        
        appointment.recipient = patient
        appointment.save()
        
        if appointment.way_of_communication != 'bluetooth':
            appointment.create_scheduled_event()

        return HttpResponseRedirect(reverse('index'))
    else:
        return render_to_response('create_appointment.html',
                                locals(),
                                context_instance=RequestContext(request))

def authenticate_phonenumber(request):
    
    if request.method == "POST":
        number = request.REQUEST["number"].strip()
        name = request.REQUEST["name"].strip()
        
        request.session['authenticate_phonenumber'] =
                                { 'name': name, 'number': number }
        
        number = authHelper.authenticate(number, name)
        if number:
            return render_to_response('authenticate_phonenumber_call.html', 
                                      locals(),
                                      context_instance = RequestContext(request))
        else:
            # there should happen something if the number was not valid
            pass
    
    return render_to_response('authenticate_phonenumber.html', 
                              locals(),
                              context_instance = RequestContext(request))

{'fraction_non_alphanumeric': 0.07663197729422895, 'fraction_numerical': 0.0, 'mean_word_length': 2.2159695817490492, 'pattern_counts': {'":': 2, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 5, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1033045', 'n_tokens_mistral': 1022, 'n_tokens_neox': 993, 'n_words': 221}