示例#1
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))
示例#2
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))
示例#3
0
def login(request):
    """
      Handles user login
    """
    if request.method == 'POST':
        #get bound form
        form = forms.LoginForm(request.POST)
        if form.is_valid():
            #attempt to find user username and password
            role = form.cleaned_data["role"]
            username = form.cleaned_data["username"]
            password = form.cleaned_data["password"]
            user = MembershipService.authenticate(role, username, password)

            #check for authenticated user
            if user is not None:
                if user.is_active:
                    auth_login(request, user)
                    return HttpResponse(200)
                else:
                    #setup errors to display back to user
                    errors = django.forms.util.ErrorList()
                    errors = form._errors.setdefault(
                        django.forms.forms.NON_FIELD_ERRORS, errors)
                    errors.append('Sorry, this user account is disabled.')
                    return render_to_response(
                        'login.html', {'form': form},
                        context_instance=RequestContext(request))
            else:
                #setup errors
                errors = django.forms.util.ErrorList()
                errors = form._errors.setdefault(
                    django.forms.forms.NON_FIELD_ERRORS, errors)
                errors.append('Username/Password Not Found.')
                return render_to_response(
                    'login.html', {'form': form},
                    context_instance=RequestContext(request))
        else:
            return render_to_response('login.html', {'form': form},
                                      context_instance=RequestContext(request))

    elif request.method == 'GET':
        #Load login form
        form = forms.LoginForm()
        return render_to_response('login.html', {'form': form},
                                  context_instance=RequestContext(request))
示例#4
0
def login(request):
    """
      Handles user login
    """
    if request.method == 'POST':
        #get bound form
        form = forms.LoginForm(request.POST)
        if form.is_valid():
            #attempt to find user username and password
            role = form.cleaned_data["role"]
            username = form.cleaned_data["username"]
            password = form.cleaned_data["password"]
            user = MembershipService.authenticate(role, username, password)

            #check for authenticated user
            if user is not None:
                if user.is_active:
                    auth_login(request, user)
                    return HttpResponse(200)
                else:
                    #setup errors to display back to user
                    errors = django.forms.util.ErrorList()
                    errors = form._errors.setdefault(
                        django.forms.forms.NON_FIELD_ERRORS, errors)
                    errors.append('Sorry, this user account is disabled.')
                    return render_to_response('login.html', {'form': form}, context_instance=RequestContext(request))
            else:
                #setup errors
                errors = django.forms.util.ErrorList()
                errors = form._errors.setdefault(
                    django.forms.forms.NON_FIELD_ERRORS, errors)
                errors.append('Username/Password Not Found.')
                return render_to_response('login.html', {'form': form}, context_instance=RequestContext(request))
        else:
            return render_to_response('login.html', {'form': form}, context_instance=RequestContext(request))


    elif request.method == 'GET':
        #Load login form
        form = forms.LoginForm()
        return render_to_response('login.html', {'form': form}, context_instance=RequestContext(request))
示例#5
0
def signUp(request):
    """
      Sign up
    """
    #Process Registration information
    if request.method == 'POST':
        #bound the form
        form = forms.SignUpForm(request.POST)
        if form.is_valid():
            #place form data into query dict for easier access
            formData = QueryDict(request.body)

            #check for teacher email unqiueness
            if CityDigitsUser.doesUsernameExist(formData.get('email')):
                #add error and return
                errors = form._errors.setdefault("email", ErrorList())
                errors.append(u"Email already Exists")
                return render_to_response('signup.html', {'form': form},
                                      context_instance=RequestContext(request))

            #create entities
            school = School.objects.create(name=formData.get('schoolName'), address=formData.get('schoolAddress'),
                                           city=formData.get('schoolCity'), state=formData.get('schoolState'))
            teacher = Teacher.objects.create(firstName=formData.get('firstName'), lastName=formData.get('lastName'),
                                             email=formData.get('email'), className=formData.get('className'),
                                             school=school)
            school.save()
            teacher.save()
            #create auth user for teacher
            cityUser = CityDigitsUser(role="TEACHER", username=teacher.email,
                                      password=MembershipService.encryptPassword(teacher.email,
                                                                                 formData.get('password')),
                                      entityId=teacher.id)
            cityUser.save()

            #create teams and students entities
            teamIdx = 0
            print(formData)
            for teamName in formData.getlist('team_name[]'):
                teamIdx = teamName.split('_')[1]
                teamName = teamName.split('_')[0]
                team = Team.objects.create(name=teamName, teacher=teacher)
                team.save()
                #add students to team
                studentIdx = 0
                for studentName in formData.getlist("student_name[%s][]" % teamIdx):
                    #get password
                    password = MembershipService.encryptPassword(studentName,
                                                                 formData.getlist("student_password[%s][]" % teamIdx)[
                                                                     studentIdx])
                    #get name
                    student = Student.objects.create(firstName=studentName, team=team)
                    student.save()
                    #create auth user for student
                    print "student password: "******"STUDENT", username=student.firstName, password=password,
                                              entityId=student.id)
                    authUser.save()
                    #update index
                    studentIdx = studentIdx + 1

                #updated team index
                # teamIdx = teamIdx + 1

            #return response
            json_data = json.dumps({"HTTPRESPONSE": 200})
            return HttpResponse(json_data, mimetype="application/json")
        else:
            #form invalid
            #return and display errors
            return render_to_response('signup.html', {'form': form},
                                      context_instance=RequestContext(request))
        pass
    elif request.method == 'GET':
        #Load Sign up form
        form = forms.SignUpForm()
        return render_to_response('signup.html', {'form': form},
                                  context_instance=RequestContext(request))
示例#6
0
def signUp(request):
    """
      Sign up
    """
    #Process Registration information
    if request.method == 'POST':
        #bound the form
        form = forms.SignUpForm(request.POST)
        if form.is_valid():
            #place form data into query dict for easier access
            formData = QueryDict(request.body)

            #check for teacher email unqiueness
            if CityDigitsUser.doesUsernameExist(formData.get('email')):
                #add error and return
                errors = form._errors.setdefault("email", ErrorList())
                errors.append(u"Email already Exists")
                return render_to_response(
                    'signup.html', {'form': form},
                    context_instance=RequestContext(request))

            #create entities
            school = School.objects.create(
                name=formData.get('schoolName'),
                address=formData.get('schoolAddress'),
                city=formData.get('schoolCity'),
                state=formData.get('schoolState'))
            teacher = Teacher.objects.create(
                firstName=formData.get('firstName'),
                lastName=formData.get('lastName'),
                email=formData.get('email'),
                className=formData.get('className'),
                school=school)
            school.save()
            teacher.save()
            #create auth user for teacher
            cityUser = CityDigitsUser(
                role="TEACHER",
                username=teacher.email,
                password=MembershipService.encryptPassword(
                    teacher.email, formData.get('password')),
                entityId=teacher.id)
            cityUser.save()

            #create teams and students entities
            teamIdx = 0
            print(formData)
            for teamName in formData.getlist('team_name[]'):
                teamIdx = teamName.split('_')[1]
                teamName = teamName.split('_')[0]
                team = Team.objects.create(name=teamName, teacher=teacher)
                team.save()
                #add students to team
                studentIdx = 0
                for studentName in formData.getlist("student_name[%s][]" %
                                                    teamIdx):
                    #get password
                    password = MembershipService.encryptPassword(
                        studentName,
                        formData.getlist("student_password[%s][]" %
                                         teamIdx)[studentIdx])
                    #get name
                    student = Student.objects.create(firstName=studentName,
                                                     team=team)
                    student.save()
                    #create auth user for student
                    print "student password: "******"STUDENT",
                                              username=student.firstName,
                                              password=password,
                                              entityId=student.id)
                    authUser.save()
                    #update index
                    studentIdx = studentIdx + 1

                #updated team index
                # teamIdx = teamIdx + 1

            #return response
            json_data = json.dumps({"HTTPRESPONSE": 200})
            return HttpResponse(json_data, mimetype="application/json")
        else:
            #form invalid
            #return and display errors
            return render_to_response('signup.html', {'form': form},
                                      context_instance=RequestContext(request))
        pass
    elif request.method == 'GET':
        #Load Sign up form
        form = forms.SignUpForm()
        return render_to_response('signup.html', {'form': form},
                                  context_instance=RequestContext(request))
示例#7
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))
示例#8
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))