예제 #1
0
def thread(messageforum,
           template,
           subjects,
           responseprompt,
           num_backups,
           start_date,
           bcastname=None):
    line = messageforum.forum.line_set.all()[0]
    language = OUTBOUND_SOUNDS_SUBDIR + line.language
    if line.outbound_number:
        num = line.outbound_number
    else:
        num = line.number

    # find the hole in the survery_template
    # job interview questions come in handy after all
    prompts = Prompt.objects.filter(survey=template).order_by('order')
    summation = 0
    order_tot = 0
    for i in range(prompts.count()):
        order_tot += prompts[i].order
        summation += i + 1

    thread_start = summation + i + 2 - order_tot
    if (thread_start == 0):
        thread_start = i + 1
    responses = Message_forum.objects.filter(
        status=Message_forum.STATUS_APPROVED,
        message__thread=messageforum.message,
        message__lft__gt=1).order_by('message__lft')

    # create a clone from the template
    newname = bcastname
    if not newname or newname == '':
        newname = template.name.replace(Survey.TEMPLATE_DESIGNATOR,
                                        '') + '_' + str(messageforum)
    newname = newname[:128]
    bcast = clone_template(template, newname, num_backups, start_date)
    for su in subjects:
        bcast.subjects.add(su)
    for d in line.dialers.all():
        bcast.dialers.add(d)

    # shift the old prompts before we add new ones to override the order
    toshift = Prompt.objects.filter(survey=bcast, order__gt=thread_start)
    # the gap left already keeps one index open
    # so only need to make room for any responses
    ntoshift = 2 * responses.count()
    if responseprompt:
        # one more space for record message prompt
        ntoshift += 1
    for prompt in toshift:
        prompt.order += ntoshift
        for option in Option.objects.filter(prompt=prompt):
            if option.action == Option.RECORD:
                oncancel = Param.objects.filter(option=option,
                                                name=Param.ONCANCEL)
                if bool(oncancel):
                    for p in oncancel:
                        p.value = int(p.value) + ntoshift
                        p.save()
            if option.action == Option.GOTO:
                goto = Param.objects.get(option=option, name=Param.IDX)
                goto.value = int(goto.value) + ntoshift
                goto.save()
        prompt.save()

    #fill in the missing prompt with the given thread
    order = thread_start
    origpost = Prompt(file=messageforum.message.file.name,
                      order=order,
                      bargein=True,
                      survey=bcast)
    origpost.save()
    origpost_opt = Option(number="1", action=Option.NEXT, prompt=origpost)
    origpost_opt.save()
    origpost_opt2 = Option(number="", action=Option.NEXT, prompt=origpost)
    origpost_opt2.save()
    order += 1

    for i in range(responses.count()):
        response = responses[i]
        if i == 0:
            responseintro = Prompt(file=language + '/firstresponse' +
                                   SOUND_EXT,
                                   order=order,
                                   bargein=True,
                                   survey=bcast)
        else:
            responseintro = Prompt(file=language + '/nextresponse' + SOUND_EXT,
                                   order=order,
                                   bargein=True,
                                   survey=bcast)
        responseintro.save()
        responseintro_opt = Option(number="1",
                                   action=Option.NEXT,
                                   prompt=responseintro)
        responseintro_opt.save()
        responseintro_opt2 = Option(number="",
                                    action=Option.NEXT,
                                    prompt=responseintro)
        responseintro_opt2.save()
        order += 1

        responsecontent = Prompt(file=response.message.file.name,
                                 order=order,
                                 bargein=True,
                                 survey=bcast)
        responsecontent.save()
        responsecontent_opt = Option(number="1",
                                     action=Option.NEXT,
                                     prompt=responsecontent)
        responsecontent_opt.save()
        responsecontent_opt2 = Option(number="",
                                      action=Option.NEXT,
                                      prompt=responsecontent)
        responsecontent_opt2.save()
        order += 1

    if responseprompt:
        # record
        record = Prompt(file=language + "/recordmessage" + SOUND_EXT,
                        order=order,
                        bargein=True,
                        survey=bcast,
                        name='Response')
        record.save()
        record_opt = Option(number="", action=Option.RECORD, prompt=record)
        record_opt.save()
        param = Param(option=record_opt,
                      name=Param.MFID,
                      value=messageforum.id)
        param.save()
        maxlen = messageforum.forum.max_user_resp_len or Forum.MAX_USER_RESP_LEN_DEF
        param2 = Param(option=record_opt,
                       name=Param.MAXLENGTH,
                       value=str(maxlen))
        param2.save()
        if not messageforum.forum.confirm_recordings:
            param3 = Param(option=record_opt,
                           name=Param.CONFIRM_REC,
                           value="0")
            param3.save()
        record_opt2 = Option(number="1", action=Option.RECORD, prompt=record)
        record_opt2.save()
        param4 = Param(option=record_opt2,
                       name=Param.MFID,
                       value=messageforum.id)
        param4.save()
        param5 = Param(option=record_opt2,
                       name=Param.MAXLENGTH,
                       value=str(messageforum.forum.maxlength))
        param5.save()
        if not messageforum.forum.confirm_recordings:
            param6 = Param(option=record_opt2,
                           name=Param.CONFIRM_REC,
                           value="0")
            param6.save()

    return bcast
예제 #2
0
def prompts():
    count = 0
    for survey in Survey.objects.all():
        # do this instead of prompt check in case there is a change
        # in the order or contents of prompts
        survey.prompt_set.all().delete()
        surveyname = survey.name

        # welcome
        welcome = Prompt(file="en/welcome.wav",
                         order=1,
                         bargein=False,
                         survey=survey)
        welcome.save()
        welcome_opt = Option(number="", action=OPTION_NEXT, prompt=welcome)
        welcome_opt.save()
        count = count + 1

        # tip
        tfilename = "en/" + surveyname[:surveyname.index("_B")] + "_tip.wav"
        tip = Prompt(file=tfilename, order=2, bargein=False, survey=survey)
        tip.save()
        tip_opt = Option(number="", action=OPTION_NEXT, prompt=tip)
        tip_opt.save()
        count = count + 1

        # confirm
        confirm = Prompt(file="en/confirm.wav",
                         order=3,
                         bargein=True,
                         survey=survey)
        confirm.save()
        confirm_opt1 = Option(number="1", action=OPTION_NEXT, prompt=confirm)
        confirm_opt1.save()
        confirm_opt2 = Option(number="2", action=OPTION_PREV, prompt=confirm)
        confirm_opt2.save()
        confirm_opt3 = Option(number="", action=OPTION_REPLAY, prompt=confirm)
        confirm_opt3.save()
        count = count + 1

        # behavior
        tidx = surveyname.index('T')
        tid = surveyname[tidx + 1:tidx + 2]
        bfilename = "en/behavior" + tid[0]
        btypeidx = surveyname.index('B')
        btype = surveyname[btypeidx + 1:btypeidx + 2]
        bfilename += btype + ".wav"

        behavior = Prompt(file=bfilename, order=4, bargein=True, survey=survey)
        behavior.save()
        # special behavior for the press button for more info behavior
        if btype == 'P':
            behavior_opt1 = Option(number="1",
                                   action=OPTION_NEXT,
                                   prompt=behavior)
            behavior_opt1.save()
            behavior_opt2 = Option(number="2",
                                   action=OPTION_GOTO,
                                   action_param1=2,
                                   prompt=behavior)
            behavior_opt2.save()

            followup = Prompt(file="en/followup.wav",
                              order=5,
                              bargein=True,
                              survey=survey)
            followup.save()
            followup_opt = Option(number="",
                                  action=OPTION_NEXT,
                                  prompt=followup)
            followup_opt.save()
            count = count + 1
        else:
            behavior_opt1 = Option(number="1",
                                   action=OPTION_GOTO,
                                   action_param1=2,
                                   prompt=behavior)
            behavior_opt1.save()

        count = count + 1

    print(str(count) + " new prompts added")
예제 #3
0
def prompts():
    count = 0
    for survey in Survey.objects.all():
        # do this instead of prompt check in case there is a change
        # in the order or contents of prompts
        survey.prompt_set.all().delete()
        surveyname = survey.name
        
        # welcome
        welcome = Prompt(file="en/welcome.wav", order=1, bargein=False, survey=survey)
        welcome.save()
        welcome_opt = Option(number="", action=OPTION_NEXT, prompt=welcome)
        welcome_opt.save()
        count = count + 1
        
        # tip
        tfilename = "en/" + surveyname[:surveyname.index("_B")] + "_tip.wav"
        tip = Prompt(file=tfilename, order=2, bargein=False, survey=survey)
        tip.save()
        tip_opt = Option(number="", action=OPTION_NEXT, prompt=tip)
        tip_opt.save()
        count = count + 1
        
        # confirm
        confirm = Prompt(file="en/confirm.wav", order=3, bargein=True, survey=survey)
        confirm.save()
        confirm_opt1 = Option(number="1", action=OPTION_NEXT, prompt=confirm)
        confirm_opt1.save()
        confirm_opt2 = Option(number="2", action=OPTION_PREV, prompt=confirm)
        confirm_opt2.save()
        confirm_opt3 = Option(number="", action=OPTION_REPLAY, prompt=confirm)
        confirm_opt3.save()
        count = count + 1

        # behavior
        tidx = surveyname.index('T')
        tid = surveyname[tidx+1:tidx+2]
        bfilename = "en/behavior" + tid[0]
        btypeidx = surveyname.index('B')
        btype = surveyname[btypeidx+1:btypeidx+2]
        bfilename += btype + ".wav"
        
        behavior = Prompt(file=bfilename, order=4, bargein=True, survey=survey)
        behavior.save()
        # special behavior for the press button for more info behavior
        if btype == 'P':
            behavior_opt1 = Option(number="1", action=OPTION_NEXT, prompt=behavior)
            behavior_opt1.save()
            behavior_opt2 = Option(number="2", action=OPTION_GOTO, action_param1=2, prompt=behavior)
            behavior_opt2.save()
            
            followup = Prompt(file="en/followup.wav", order=5, bargein=True, survey=survey)
            followup.save()
            followup_opt = Option(number="", action=OPTION_NEXT, prompt=followup)
            followup_opt.save()
            count = count + 1
        else:
            behavior_opt1 = Option(number="1", action=OPTION_GOTO, action_param1=2, prompt=behavior)
            behavior_opt1.save()
        
        count = count + 1
                        
    print(str(count) + " new prompts added")
예제 #4
0
def thread(messageforum, template, subjects, responseprompt, num_backups, start_date, bcastname=None):
    line = messageforum.forum.line_set.all()[0]
    language = OUTBOUND_SOUNDS_SUBDIR + line.language
    if line.outbound_number:
        num = line.outbound_number
    else:
        num = line.number
    
    # find the hole in the survery_template
    # job interview questions come in handy after all
    prompts = Prompt.objects.filter(survey=template).order_by('order')
    summation = 0
    order_tot = 0
    for i in range(prompts.count()):
        order_tot += prompts[i].order
        summation += i+1
        
    thread_start = summation + i + 2 - order_tot
    if (thread_start == 0):
        thread_start = i+1
    responses = Message_forum.objects.filter(status = Message_forum.STATUS_APPROVED, message__thread=messageforum.message, message__lft__gt=1).order_by('message__lft')
    
    # create a clone from the template
    newname = bcastname
    if not newname or newname == '':
        newname = template.name.replace(Survey.TEMPLATE_DESIGNATOR, '') + '_' + str(messageforum)
    newname = newname[:128]
    bcast = clone_template(template, newname, num_backups, start_date)
    for su in subjects:
        bcast.subjects.add(su)
    for d in line.dialers.all():
        bcast.dialers.add(d)
    
    # shift the old prompts before we add new ones to override the order
    toshift = Prompt.objects.filter(survey=bcast, order__gt=thread_start)
    # the gap left already keeps one index open
    # so only need to make room for any responses
    ntoshift = 2 * responses.count()
    if responseprompt:
        # one more space for record message prompt
        ntoshift += 1
    for prompt in toshift:
        prompt.order += ntoshift
        for option in Option.objects.filter(prompt=prompt):
            if option.action == Option.RECORD:
                oncancel = Param.objects.filter(option=option, name=Param.ONCANCEL)
                if bool(oncancel):
                    for p in oncancel:
                        p.value = int(p.value) + ntoshift
                        p.save()
            if option.action == Option.GOTO:
                goto = Param.objects.get(option=option, name=Param.IDX)
                goto.value = int(goto.value) + ntoshift
                goto.save()
        prompt.save()
    
    #fill in the missing prompt with the given thread
    order = thread_start
    origpost = Prompt(file=messageforum.message.file.name, order=order, bargein=True, survey=bcast)
    origpost.save()
    origpost_opt = Option(number="1", action=Option.NEXT, prompt=origpost)
    origpost_opt.save()
    origpost_opt2 = Option(number="", action=Option.NEXT, prompt=origpost)
    origpost_opt2.save()
    order += 1
    
    for i in range(responses.count()):
        response = responses[i]
        if i == 0:
            responseintro = Prompt(file=language+'/firstresponse'+SOUND_EXT, order=order, bargein=True, survey=bcast)
        else:
            responseintro = Prompt(file=language+'/nextresponse'+SOUND_EXT, order=order, bargein=True, survey=bcast)
        responseintro.save()
        responseintro_opt = Option(number="1", action=Option.NEXT, prompt=responseintro)
        responseintro_opt.save()
        responseintro_opt2 = Option(number="", action=Option.NEXT, prompt=responseintro)
        responseintro_opt2.save()
        order += 1
        
        responsecontent = Prompt(file=response.message.file.name, order=order, bargein=True, survey=bcast)
        responsecontent.save()
        responsecontent_opt = Option(number="1", action=Option.NEXT, prompt=responsecontent)
        responsecontent_opt.save()
        responsecontent_opt2 = Option(number="", action=Option.NEXT, prompt=responsecontent)
        responsecontent_opt2.save()
        order += 1
    
    if responseprompt:
         # record
        record = Prompt(file=language+"/recordmessage"+SOUND_EXT, order=order, bargein=True, survey=bcast, name='Response' )
        record.save()
        record_opt = Option(number="", action=Option.RECORD, prompt=record)
        record_opt.save()
        param = Param(option=record_opt, name=Param.MFID, value=messageforum.id)
        param.save()
        maxlen = messageforum.forum.max_user_resp_len or Forum.MAX_USER_RESP_LEN_DEF
        param2 = Param(option=record_opt, name=Param.MAXLENGTH, value=str(maxlen))
        param2.save()
        if not messageforum.forum.confirm_recordings:
            param3 = Param(option=record_opt, name=Param.CONFIRM_REC, value="0")
            param3.save()
        record_opt2 = Option(number="1", action=Option.RECORD, prompt=record)
        record_opt2.save()
        param4 = Param(option=record_opt2, name=Param.MFID, value=messageforum.id)
        param4.save()
        param5 = Param(option=record_opt2, name=Param.MAXLENGTH, value=str(messageforum.forum.maxlength))
        param5.save()
        if not messageforum.forum.confirm_recordings:
            param6 = Param(option=record_opt2, name=Param.CONFIRM_REC, value="0")
            param6.save()
    
    return bcast