def authenticate(user_id, pass1, newpass1, newpass2,path_to_data=PATH_TO_DATA):
    CONSTANT_DATA = get_constant_data(path_to_data)
    roster_name = CONSTANT_DATA['roster_name']
    R = SheetObject(path_to_data + roster_name,'roster')
    students = R.get({'netid':user_id})
    n = len(students)
    authenticated = 0
    #print(students)
    if n==0:
        message = "invalid user_id and password. <br>"
        authenticated = 0
        #print('n=0')
    if n==1:
        old_entry = students[0]
        password = old_entry['password']
        if password == pass1:
            authenticated = 1
            if newpass1 == newpass2 and len(newpass1) >0:
                new_entry = copyd(old_entry)
                new_entry['password'] = newpass1
                R.remove([old_entry])
                R.append(new_entry)
                R.save()
                message = "new password has been set. <br>"
                
                
            else:
                message = "<i> %s upload report </i> <br>" % user_id
        else:
            #print('In the "else" case')
            authenticated = 0
            message = "invalid user_id and password. <br>"
                
    if n>2:
        authenticated = 0
        message = """
        invalid user_id and password. (multiple users! please copy-paste this entire upload report in an email to [email protected].) <br>
        """
        
    return message, authenticated
def submit_problem(user_id,assignment,problem,timestamp,path_to_data=PATH_TO_DATA,check_due_date=False):
    """
    
    """
    CONSTANT_DATA = get_constant_data(path_to_data)
    roster_name = CONSTANT_DATA['roster_name']
    S = SheetObject(path_to_data + roster_name,'submissions')
    query = {'netid':user_id, 'assignment':assignment,'problem':problem}
    if is_valid_assignment(assignment,problem,timestamp,path_to_data):
        old_entries = S.get(query)
        n = len(old_entries)
        write_file = 1
        new_submission_number = get_submission_count(path_to_data)
        
        if n==0:
            new_entry = {}
            new_entry['netid'] = user_id
            new_entry['assignment'] = assignment
            new_entry['problem'] = problem
            new_entry['submission_number'] = new_submission_number
            new_entry['submission_time'] = timestamp
            new_entry['new_submission']=1
            new_entry['submission_locked']=0
            new_entry['closed']=0
            new_entry['total_score1']=0
            new_entry['total_score2']=0
            new_entry['reviewer1_assignment_time']=-1
            new_entry['reviewer1']=''
            new_entry['reviewer1_score']=-1
            new_entry['review1']=''
            new_entry['review1_timestamp']=-1
            new_entry['review1_locked']=0
            new_entry['reviewer2_assignment_time']=-1
            new_entry['reviewer2']=''
            new_entry['reviewer2_score']=-1
            new_entry['review2']=''
            new_entry['review2_timestamp']=-1
            new_entry['review2_locked']=0
            new_entry['new_submission']=1
            new_entry['new_match']=0
            new_entry['new_review1']=0
            new_entry['new_review2']=0
            new_entry['new_completion']=0
            new_entry['w1']=1
            new_entry['w2']=1
            S.append(new_entry)
            S.save()
            message = """
            *submission %s, assignment %s, problem %s created. new. <br>
            """ % (new_submission_number, assignment, problem)
            write_file = 1
            
        elif n==1:
            old_entry = old_entries[0]
            
            #The trickiest f*****g bug in the world:
            #new_entry = old_entry
            
            #you need to make a new blank dictionary...
            #...otherwise it just points to the old one
            new_entry = {}
            for key in S.set_of_keys:
                new_entry[key] = old_entry[key]
            
            #new_entry['netid'] = user_id
            #new_entry['assignment'] = assignment
            #new_entry['problem'] = problem
            new_entry['submission_number'] = new_submission_number
            new_entry['submission_time'] = timestamp
            #new_entry['new_submission']=1
            #new_entry['submission_locked']=0
            
            is_locked = old_entry['submission_locked'] #bug: entries -> entry
            
            if is_locked ==1:
                message = """
                *assignment %s, problem %s rejected. locked. <br>
                """ % (assignment,problem)
                write_file =0
                
            if is_locked ==0:
                S.replace(old_entry,new_entry)
                S.save()
                message = """
                *submission %s, assignment %s, problem %s created. <br>
                submission %s overwritten. <br>
                """ % (new_submission_number,assignment,problem,old_entry['submission_number'])
                write_file = 1
                
        else:
            message = """
            *assigment %s, problem %s rejected. multiple entries in database. contact instructor with this message and copy-paste this message. <br> """
            write_file =0
            
        if write_file ==1:
            increment_submission_number(path_to_data)
    
    else:
        message = """
        *assignment %s, problem %s rejected. not a valid submission. <br>
        """ % (assignment,problem)
        write_file = 0
        
    dataentry = {}
    dataentry["uploadOk"] = write_file
    if write_file ==1:
        dataentry["submission_number"]=new_submission_number
    else:
        dataentry["submission_number"]=-1
    return message,dataentry
示例#3
0
            snew['new_review1'] = 0

        if time_difference(tnow, trev2) > 2:
            snew['new_review2'] = 0

        cleaned.append(snew)

        f = open(PATH_TO_DATA + 'late_reviews.json', 'w')
        json.dump(late_reviews, f)
        f.close()

update(S, cleaned)
S.save()

#############
#Now we update the participation scores
#############

matched = S.get({'submission_locked': 1})
for m in matched:
    matched_dict[m['netid']].append(m['submission_number'])

for user in users:
    usernew = copyd(user)
    total = 14 + 2 * len(matched_dict[user['netid']])
    num = total - len(late_reviews[user['netid']])
    usernew['participation'] = num / total
    U.remove([user])
    U.append(usernew)
    U.save()