Пример #1
0
def new_interview(request):
    ip_address = request.remote_addr
    try:
        Interview.clear_and_reset()
        rules_fired = Interview.next()
    except KnowledgeBaseError, instance:
        return Response(instance.args[0], content_type='text/plain', status_int=500)
Пример #2
0
def put_interview(id):
    content = request.get_json()
    delete_interview(id)
    interviewObj = Interview(content, id)
    db_session.add(interviewObj)
    db_session.commit()
    return {"id": interviewObj.id, "status": "Updated"}
Пример #3
0
def update_interview(id):
   content = request.get_json()
   interviewUpdatedObj = Interview(content)
   # interviewObj.id = id
   # db_session.add(interviewObj)
   interviewObj = db_session.query(Interview).get(id)
   interviewObj = interviewUpdatedObj
   db_session.commit()
   return {"id": interviewObj.id,"status": "OK"}
Пример #4
0
def interviewRetailer(request):
    """
      Handles retailer interview form
    """
    #get student team
    team = MembershipService.findStudentForId(request.user.entityId).team.name
    if request.method == "POST":
        #Bound form
        form = forms.RetailerInterviewForm(request.POST, request.FILES)
        if form.is_valid():
            #Save interview related information
            #Get student
            student = MembershipService.findStudentForId(request.user.entityId)
            #Create location
            location = Location(latitude=form.cleaned_data['latitude'], longitude=form.cleaned_data["longitude"],
                                address=form.cleaned_data["location"])
            location.save()
            #Create retailer profile
            entity = None
            entity = InterviewRetailer(storeName=form.cleaned_data["storeName"],
                                     do_you_sell_lottery_tickets=form.cleaned_data["sellLotteryTickets"],
                                     why_or_why_not_audio=request.FILES['whyOrWhyNot'] if 'whyOrWhyNot' in request.FILES else None,
                                     customers_in_a_day=form.cleaned_data["customersPerDay"],
                                     percentage_buy_lottery_tickets=float(form.cleaned_data["percentageCustomers"] if form.cleaned_data["percentageCustomers"]!="" else 0),
                                     amount_tickets_bought_per_visit=form.cleaned_data["amountPerVisit"],
                                     why_or_why_not_lottery_neighborhood_audio=request.FILES["goodForNeighborhoodQuestion"] if 'goodForNeighborhoodQuestion' in request.FILES else None,
                                     photo=request.FILES["photo"] if "photo" in request.FILES else None)
            entity.save()
            #Create interview
            interview = Interview(student=student, location=location, interviewType="RETAILER", entityId=entity.id)
            interview.save()
            #return response
            json_data = json.dumps({"HTTPRESPONSE": 200})
            return HttpResponse(json_data, mimetype="application/json")
        else:
            print("FORM ERRORS")
            for e in form.errors:
                print e
            return render_to_response('retailer_interview.html', {'form': form,'team':team}, context_instance=RequestContext(request))

    elif request.method == "GET":
        #Load interview form
        form = forms.RetailerInterviewForm()
        return render_to_response('retailer_interview.html', {'form': form,'team':team}, context_instance=RequestContext(request))
Пример #5
0
def interviewPlayer(request):
    """
      Handles player interview form
    """
    #get student team
    team = MembershipService.findStudentForId(request.user.entityId).team.name
    if request.method == "POST":
        #Bound form
        form = forms.PlayerInterviewForm(request.POST, request.FILES)
        if form.is_valid():
            #Save interview related information
            #Get student
            student = MembershipService.findStudentForId(request.user.entityId)
            #Create location
            location = Location(latitude=form.cleaned_data['latitude'], longitude=form.cleaned_data["longitude"],
                                address=form.cleaned_data["location"])
            location.save()
            #Create player profile
            entity = None
            entity = InterviewPlayer(firstName=form.cleaned_data["firstName"],
                                     do_you_ever_buy_lottery_tickets=form.cleaned_data["buyLotteryTickets"],
                                     why_or_why_not_audio=request.FILES['whyOrWhyNot'] if 'whyOrWhyNot' in request.FILES else None,
                                     have_you_ever_won_the_lottery=form.cleaned_data["wonLottery"],
                                     most_won=float(form.cleaned_data["mostWonAmount"] if form.cleaned_data["mostWonAmount"]!="" else 0),
                                     money_spent_on_lottery_in_average_week=float(form.cleaned_data["averageSpentOnLotteryPerWeek"] if form.cleaned_data["averageSpentOnLotteryPerWeek"]!="" else 0 ),
                                     jackpot_audio=request.FILES["wonJackpotQuestion"] if 'wonJackpotQuestion' in request.FILES else None,
                                     photo=request.FILES["photo"] if "photo" in request.FILES else None)
            entity.save()
            #Create interview
            interview = Interview(student=student, location=location, interviewType="PLAYER", entityId=entity.id)
            interview.save()
            #return response
            json_data = json.dumps({"HTTPRESPONSE": 200})
            return HttpResponse(json_data, mimetype="application/json")
        else:
            print("FORM ERRORS")
            for e in form.errors:
                print e
            return render_to_response('player_interview.html', {'form': form,'team':team}, context_instance=RequestContext(request))

    elif request.method == "GET":
        #Load interview form
        form = forms.PlayerInterviewForm()
        return render_to_response('player_interview.html', {'form': form,'team':team}, context_instance=RequestContext(request))
Пример #6
0
@view_config(route_name='wizconfig', renderer='templates/wizconfig.mako')
def wizconfig(request):
    return {'ok': 200, 'test_path': os.path.abspath("test")}

# config.add_route('wizconfig', '/wizconfig/start/{id}')
@view_config(route_name='wizconfig_start', renderer='templates/wizconfig_prompt.mako')
def new_interview(request):
    ip_address = request.remote_addr
    try:
        Interview.clear_and_reset()
        rules_fired = Interview.next()
    except KnowledgeBaseError, instance:
        return Response(instance.args[0], content_type='text/plain', status_int=500)
    except DBAPIError:
        return Response(conn_err_msg, content_type='text/plain', status_int=500)
    return {'interview': Interview.get_current()}

# config.add_route('kbhook_setprompt', '/kbhook/setprompt')
# @view_config(route_name='kbhook_setprompt', renderer='templates/kbhook_setprompt.mako')
# def kbhook_setprompt(request):
#     ip_address = request.remote_addr
#     try:
#         goalname = request.params["goalname"]
#         choices_str = request.params["choices"]
#         log.debug("kbhook setting prompt")
#         i = Interview.setprompt(goalname, choices_str)
#         log.debug("kbhook comitting prompt")
#         # DBSession.add(prompt_state)
#     except KnowledgeBaseError, instance:
#         return Response(instance.args[0], content_type='text/plain', status_int=500)
#     except DBAPIError:
Пример #7
0
def post_interview():
   content = request.get_json()
   interviewObj = Interview(content)
   db_session.add(interviewObj)
   db_session.commit()
   return {"id": interviewObj.id,"status": "OK"}
Пример #8
0
def interviewRetailer(request):
    """
      Handles retailer interview form
    """
    #get student team
    team = MembershipService.findStudentForId(request.user.entityId).team.name
    if request.method == "POST":
        #Bound form
        form = forms.RetailerInterviewForm(request.POST, request.FILES)
        if form.is_valid():
            #Save interview related information
            #Get student
            student = MembershipService.findStudentForId(request.user.entityId)
            #Create location
            location = Location(latitude=form.cleaned_data['latitude'],
                                longitude=form.cleaned_data["longitude"],
                                address=form.cleaned_data["location"])
            location.save()
            #Create retailer profile
            entity = None
            entity = InterviewRetailer(
                storeName=form.cleaned_data["storeName"],
                do_you_sell_lottery_tickets=form.
                cleaned_data["sellLotteryTickets"],
                why_or_why_not_audio=request.FILES['whyOrWhyNot']
                if 'whyOrWhyNot' in request.FILES else None,
                customers_in_a_day=form.cleaned_data["customersPerDay"],
                percentage_buy_lottery_tickets=float(
                    form.cleaned_data["percentageCustomers"]
                    if form.cleaned_data["percentageCustomers"] != "" else 0),
                amount_tickets_bought_per_visit=form.
                cleaned_data["amountPerVisit"],
                why_or_why_not_lottery_neighborhood_audio=request.
                FILES["goodForNeighborhoodQuestion"]
                if 'goodForNeighborhoodQuestion' in request.FILES else None,
                photo=request.FILES["photo"]
                if "photo" in request.FILES else None)
            entity.save()
            #Create interview
            interview = Interview(student=student,
                                  location=location,
                                  interviewType="RETAILER",
                                  entityId=entity.id)
            interview.save()
            #return response
            json_data = json.dumps({"HTTPRESPONSE": 200})
            return HttpResponse(json_data, mimetype="application/json")
        else:
            print("FORM ERRORS")
            for e in form.errors:
                print e
            return render_to_response('retailer_interview.html', {
                'form': form,
                'team': team
            },
                                      context_instance=RequestContext(request))

    elif request.method == "GET":
        #Load interview form
        form = forms.RetailerInterviewForm()
        return render_to_response('retailer_interview.html', {
            'form': form,
            'team': team
        },
                                  context_instance=RequestContext(request))
Пример #9
0
def interviewPlayer(request):
    """
      Handles player interview form
    """
    #get student team
    team = MembershipService.findStudentForId(request.user.entityId).team.name
    if request.method == "POST":
        #Bound form
        form = forms.PlayerInterviewForm(request.POST, request.FILES)
        if form.is_valid():
            #Save interview related information
            #Get student
            student = MembershipService.findStudentForId(request.user.entityId)
            #Create location
            location = Location(latitude=form.cleaned_data['latitude'],
                                longitude=form.cleaned_data["longitude"],
                                address=form.cleaned_data["location"])
            location.save()
            #Create player profile
            entity = None
            entity = InterviewPlayer(
                firstName=form.cleaned_data["firstName"],
                do_you_ever_buy_lottery_tickets=form.
                cleaned_data["buyLotteryTickets"],
                why_or_why_not_audio=request.FILES['whyOrWhyNot']
                if 'whyOrWhyNot' in request.FILES else None,
                have_you_ever_won_the_lottery=form.cleaned_data["wonLottery"],
                most_won=float(form.cleaned_data["mostWonAmount"] if form.
                               cleaned_data["mostWonAmount"] != "" else 0),
                money_spent_on_lottery_in_average_week=float(
                    form.cleaned_data["averageSpentOnLotteryPerWeek"] if form.
                    cleaned_data["averageSpentOnLotteryPerWeek"] != "" else 0),
                jackpot_audio=request.FILES["wonJackpotQuestion"]
                if 'wonJackpotQuestion' in request.FILES else None,
                photo=request.FILES["photo"]
                if "photo" in request.FILES else None)
            entity.save()
            #Create interview
            interview = Interview(student=student,
                                  location=location,
                                  interviewType="PLAYER",
                                  entityId=entity.id)
            interview.save()
            #return response
            json_data = json.dumps({"HTTPRESPONSE": 200})
            return HttpResponse(json_data, mimetype="application/json")
        else:
            print("FORM ERRORS")
            for e in form.errors:
                print e
            return render_to_response('player_interview.html', {
                'form': form,
                'team': team
            },
                                      context_instance=RequestContext(request))

    elif request.method == "GET":
        #Load interview form
        form = forms.PlayerInterviewForm()
        return render_to_response('player_interview.html', {
            'form': form,
            'team': team
        },
                                  context_instance=RequestContext(request))