Ejemplo n.º 1
0
    def handle(self, text):
        if self.handle_preconditions(text):
            return

        # default to HSA
        role = ContactRole.objects.get(code=config.Roles.HSA)

        try:
            hsa_id = format_id(self.supply_point.code, self.extra)
        except IdFormatException, e:
            self.respond(str(e))
            return
Ejemplo n.º 2
0
    def handle(self, text):
        if self.handle_preconditions(text):
            return
        
        # default to HSA
        role = ContactRole.objects.get(code=config.Roles.HSA)
        

        try:
            hsa_id = format_id(self.supply_point.code, self.extra)
        except IdFormatException, e:
            self.respond(str(e))
            return
Ejemplo n.º 3
0
def register_user(request, template="malawi/register-user.html"):
    context = dict()
    context['facilities'] = SupplyPoint.objects.filter(type__code="hf").order_by('code')
    context['backends'] = Backend.objects.all()
    context['dialing_code'] = settings.COUNTRY_DIALLING_CODE # [sic]
    if request.method != 'POST':
        return render_to_response(template, context, context_instance=RequestContext(request))

    id = request.POST.get("id", None)
    facility = request.POST.get("facility", None)
    name = request.POST.get("name", None)
    number = request.POST.get("number", None)
    backend = request.POST.get("backend", None)

    if not (id and facility and name and number and backend):
        messages.error(request, "All fields must be filled in.")
        return render_to_response(template, context, context_instance=RequestContext(request))
    hsa_id = None
    try:
        hsa_id = format_id(facility, id)
    except IdFormatException:
        messages.error(request, "HSA ID must be a number between 0 and 99.")
        return render_to_response(template, context, context_instance=RequestContext(request))

    try:
        parent = SupplyPoint.objects.get(code=facility)
    except SupplyPoint.DoesNotExist:
        messages.error(request, "No facility with that ID.")
        return render_to_response(template, context, context_instance=RequestContext(request))

    if Location.objects.filter(code=hsa_id).exists():
        messages.error(request, "HSA with that code already exists.")
        return render_to_response(template, context, context_instance=RequestContext(request))

    try:
        number = int(number)
    except ValueError:
        messages.error(request, "Phone number must contain only numbers.")
        return render_to_response(template, context, context_instance=RequestContext(request))

    hsa_loc = Location.objects.create(name=name, type=config.hsa_location_type(),
                                          code=hsa_id, parent=parent.location)
    sp = SupplyPoint.objects.create(name=name, code=hsa_id, type=config.hsa_supply_point_type(),
                                        location=hsa_loc, supplied_by=parent, active=True)
    sp.save()
    contact = Contact()
    contact.name = name
    contact.supply_point = sp
    contact.role = ContactRole.objects.get(code=config.Roles.HSA)
    contact.is_active = True
    contact.save()

    connection = Connection()
    connection.backend = Backend.objects.get(pk=int(backend))
    connection.identity = "+%s%s" % (settings.COUNTRY_DIALLING_CODE, number) #TODO: Check validity of numbers
    connection.contact = contact
    connection.save()

    messages.success(request, "HSA added!")

    return render_to_response(template, context, context_instance=RequestContext(request))