示例#1
0
    def test_game_progress(self):
        email = '*****@*****.**'
        user = users.User(email)

        hasVoted, hasAddedQuote = models.get_progress(user)
        self.assertFalse(hasVoted)
        self.assertFalse(hasAddedQuote)

        quoteid0 = models.add_quote('This is a test.', user, _created=1)

        hasVoted, hasAddedQuote = models.get_progress(user)
        self.assertFalse(hasVoted)
        self.assertTrue(hasAddedQuote)

        models.set_vote(quoteid0, user, 1)

        hasVoted, hasAddedQuote = models.get_progress(user)
        self.assertTrue(hasVoted)
        self.assertTrue(hasAddedQuote)
  def test_game_progress(self):
    email = '*****@*****.**'
    user = users.User(email)

    hasVoted, hasAddedQuote = models.get_progress(user)
    self.assertFalse(hasVoted)
    self.assertFalse(hasAddedQuote)

    quoteid0 = models.add_quote('This is a test.', user, _created=1)
    
    hasVoted, hasAddedQuote = models.get_progress(user)
    self.assertFalse(hasVoted)
    self.assertTrue(hasAddedQuote)
    
    models.set_vote(quoteid0, user, 1)
    
    hasVoted, hasAddedQuote = models.get_progress(user)
    self.assertTrue(hasVoted)
    self.assertTrue(hasAddedQuote)
示例#3
0
def reload_refresh():
    netid = session['netid']
    netid = search_users(netid)
    if netid:
        info = get_student_info(netid)

        ret = get_progress(netid)
        ret_certs = get_progress_certificates(netid)

        majors_completed,doublecountcom = get_major_by_courses(ret)
        majors_gpa,doublecountgpa = get_major_by_gpa(ret)
        certificates_completed,doublecountcerts = get_major_by_courses(ret_certs)

        major_interests,certificate_interests = get_major_certificate_interests(netid)

        # get info of courses for interested majors/certificates
        majors_of_interest = []
        certificates_of_interest = []
        major_names = []
        certificate_names = []
        for maj in majors_completed:
            major_names.append(maj[0])
            if maj[0] in major_interests:
                majors_of_interest.append(maj)
        for cert in certificates_completed:
            certificate_names.append(cert[0])
            if cert[0] in certificate_interests:
                certificates_of_interest.append(cert)

        requirements_dictionary = get_major_cert_requirements(major_names,certificate_names)

        simple_dc = []
        for dc in doublecountcom:
            simple_dc.append(dc[0])
        for dc in doublecountgpa:
            simple_dc.append(dc[0])
        for dc in doublecountcerts:
            simple_dc.append(dc[0])

        d = {
            'netid': netid,
            'majors_completed': majors_completed,
            'majors_gpa': majors_gpa,
            'certificates_completed': certificates_completed,
            'interested_majors': majors_of_interest,
            'interested_certificates': certificates_of_interest,
            'int_majors': major_interests,
            'int_certificates': certificate_interests,
            'doublecount': simple_dc,
            'info': info,
            'reqs_dict':requirements_dictionary
        }
        return render_template('success_bs.html',d=d)
示例#4
0
def get_greeting():
  """
  Generate HTML for the user to either logout or login,
  depending on their current state. Also returns progress_id and 
  progress_msg.
  
  progress_id - The number of the image to display
    that shows how many stars the user has earned
    for participating with the site. This is actually 
    a bit field with the first four bits being:
    
    Bit - Value - Description
    0   -   1   - Showing up
    1   -   2   - Logging in
    2   -   4   - Voting on at least one quote
    3   -   8   - Contributing at least one quote
  
  return: (greeting, progress_id, progress_msg)
  """
  user = users.get_current_user()
  progress_id = 1
  progress_msg = 'You get one star just for showing up.'
  if user:
    greeting = ('%s (<a class="loggedin" href="%s">sign out</a>)' % 
        (user.nickname(), cgi.escape(users.create_logout_url('/'))))
    progress_id = 3
    progress_msg = 'One more star for logging in.'
    has_voted, has_added_quote = models.get_progress(user)    
    if has_voted:
      progress_id |= 4
      progress_msg = ""
    if has_added_quote:
      progress_id |= 8
      progress_msg = ""      
  else:
    greeting = ("""<a  href=\"%s\">Sign in to vote or add 
        your own quote</a>.""" % cgi.escape(users.create_login_url("/")))
  return (progress_id, progress_msg, greeting)
示例#5
0
def get_greeting():
  """
  Generate HTML for the user to either logout or login,
  depending on their current state. Also returns progress_id and 
  progress_msg.
  
  progress_id - The number of the image to display
    that shows how many stars the user has earned
    for participating with the site. This is actually 
    a bit field with the first four bits being:
    
    Bit - Value - Description
    0   -   1   - Showing up
    1   -   2   - Logging in
    2   -   4   - Voting on at least one quote
    3   -   8   - Contributing at least one quote
  
  return: (greeting, progress_id, progress_msg)
  """
  user = users.get_current_user()
  progress_id = 1
  progress_msg = 'You get one star just for showing up.'
  if user:
    greeting = ('%s (<a class="loggedin" href="%s">sign out</a>)' % 
        (user.nickname(), cgi.escape(users.create_logout_url('/'))))
    progress_id = 3
    progress_msg = 'One more star for logging in.'
    has_voted, has_added_quote = models.get_progress(user)    
    if has_voted:
      progress_id |= 4
      progress_msg = ""
    if has_added_quote:
      progress_id |= 8
      progress_msg = ""      
  else:
    greeting = ("""<a  href=\"%s\">Sign in to vote or add 
        your own quote</a>.""" % cgi.escape(users.create_login_url("/")))
  return (progress_id, progress_msg, greeting)
示例#6
0
def upload_file():
    mistake = False
    if request.method == 'GET' or request.method == 'HEAD':
        if LOCALHOST: 
            nid = '' # fill in your netid
        else:
            ticket_from_cas = request.args.get('ticket')
            nid = C.Authenticate2(ticket_from_cas)
            if nid == "" or None:
               nid = session['netid'] if 'netid' in session else None
            if nid == "" or None:
               loginpage = C.Authenticate1()
               return redirect(loginpage)
        session['netid'] = nid
        netid = search_users(nid)
        if netid:
            info = get_student_info(netid)

            ret = get_progress(netid)
            ret_certs = get_progress_certificates(netid)

            majors_completed,doublecountcom = get_major_by_courses(ret)
            majors_gpa,doublecountgpa = get_major_by_gpa(ret)
            certificates_completed,doublecountcerts = get_major_by_courses(ret_certs)

            major_interests,certificate_interests = get_major_certificate_interests(netid)

            # get info of courses for interested majors/certificates
            majors_of_interest = []
            certificates_of_interest = []
            major_names = []
            certificate_names = []
            for maj in majors_completed:
                major_names.append(maj[0])
                if maj[0] in major_interests:
                    majors_of_interest.append(maj)
            for cert in certificates_completed:
                certificate_names.append(cert[0])
                if cert[0] in certificate_interests:
                    certificates_of_interest.append(cert)

            requirements_dictionary = get_major_cert_requirements(major_names,certificate_names)

            simple_dc = []
            for dc in doublecountcom:
                simple_dc.append(dc[0])
            for dc in doublecountgpa:
                simple_dc.append(dc[0])
            for dc in doublecountcerts:
                simple_dc.append(dc[0])

            d = {
                'netid': netid,
                'majors_completed': majors_completed,
                'majors_gpa': majors_gpa,
                'certificates_completed': certificates_completed,
                'interested_majors': majors_of_interest,
                'interested_certificates': certificates_of_interest,
                'int_majors': major_interests,
                'int_certificates': certificate_interests,
                'doublecount': simple_dc,
                'info': info,
                'reqs_dict':requirements_dictionary
            }
            return render_template('success_bs.html',d=d)
    if request.method == 'POST':
        file = request.files['transcript']
        studentname = request.form['Name']
        degree = request.form['Degree']
        major = request.form['Major']
        manualcourses = request.form['manual_courses']
        netid = session['netid'] if 'netid' in session else None
        if netid is None:
            loginpage = C.Authenticate1()
            return redirect(loginpage)
        if file:
            studentinfo = parse_transcript(file)
            if studentinfo == None:
                mistake = True          
        if not mistake and (file or manualcourses):
            if not file and manualcourses:
                if studentname == "":
                    studentname == "Anonymous Tiger"
                course_manual_parsed = parse_manual_courses(manualcourses)
                # since we do not know how many pdfs, set to -1
                studentinfo = [studentname,degree,major,course_manual_parsed,-1]
            if add_user(studentinfo,netid,False) != None:

                info = [studentinfo[0],studentinfo[1],studentinfo[2],studentinfo[4]]

                ret = get_progress(netid)
                ret_certs = get_progress_certificates(netid)

                majors_completed,doublecountcom = get_major_by_courses(ret)
                majors_gpa,doublecountgpa = get_major_by_gpa(ret)
                certificates_completed,doublecountcerts = get_major_by_courses(ret_certs)

                major_interests,certificate_interests = get_major_certificate_interests(netid)
                
                majors_of_interest = []
                certificates_of_interest = []
                major_names = []
                certificate_names = []
                for maj in majors_completed:
                    major_names.append(maj[0])
                    if maj[0] in major_interests:
                        majors_of_interest.append(maj)
                for cert in certificates_completed:
                    certificate_names.append(cert[0])
                    if cert[0] in certificate_interests:
                        certificates_of_interest.append(cert)

                requirements_dictionary = get_major_cert_requirements(major_names,certificate_names)

                simple_dc = []
                for dc in doublecountcom:
                    simple_dc.append(dc[0])
                for dc in doublecountgpa:
                    simple_dc.append(dc[0])
                for dc in doublecountcerts:
                    simple_dc.append(dc[0])

                d = {
                    'netid': netid,
                    'majors_completed': majors_completed,
                    'majors_gpa': majors_gpa,
                    'certificates_completed': certificates_completed,
                    'interested_majors': majors_of_interest,
                    'interested_certificates': certificates_of_interest,
                    'int_majors': major_interests,
                    'int_certificates': certificate_interests,
                    'doublecount': simple_dc,
                    'info': info,
                    'reqs_dict':requirements_dictionary
                }
                return render_template('success_bs.html',d=d)
    d = { 
        'mistake':mistake
    }
    return render_template('index_bs.html',d=d)