def create_token(self, email, votes, tournament_id): tournament = self.tournaments.get_one(tournament_id) existing_token = Judge.query.filter(Judge.email == email, Judge.tournament == tournament).first() if existing_token: raise JudgeAlreadyExists() judge = Judge(email=email, votes=votes) judge.hash = self.hasher.generate() judge.tournament = tournament db.session.add(judge) db.session.commit() return judge
def all_scores_form(): scores = [] summaries = [] for team in Team.GetAll(): total_score = 0 team_judged_by = [] all_team_scores = Score.GetScoresForTeam(team.name) scores += all_team_scores judges = [j.name for j in Judge.GetAll()] for judge in judges: judge_scores = sum([ score.score for score in all_team_scores if score.judge == judge ]) total_score += judge_scores if judge_scores: team_judged_by.append(judge) judge_names = ','.join(team_judged_by) summaries.append( [team.name, team.members, team.contact, total_score, judge_names]) summaries.sort(reverse=True, key=lambda x: int(x[3])) team_count = len(summaries) return render_template('all_scores.html', summaries=summaries, team_count=team_count, scores=scores)
def scores_form(): if request.form.getlist('save'): save_scores() saved = True else: saved = False if request.form and request.form.getlist('judge'): judge = request.form.getlist('judge')[0] else: judge = '' if request.form and request.form.getlist('team'): team = request.form.getlist('team')[0] else: team = '' print("***** j '{}' t '{}'".format(judge, team)) judges = [j.name for j in Judge.GetAll()] teams = [t.name for t in Team.GetAll()] if team and judge: scores = [ score for score in Score.GetScoresForTeam(team) if score.judge == judge ] else: scores = [] return render_template('scores.html', team=team, judge=judge, teams=teams, judges=judges, scores=scores, saved=saved)
def generate_acts(request,count): count = int(count) Act.objects.all().delete() Judge.objects.all().delete() Comissioner.objects.all().delete() Debter.objects.all().delete() Court.objects.all().delete() word_base = open(os.path.join(BASE_DIR, 'Bankrupt/static/names.txt'),"r").read().split("\n") surname_base = open(os.path.join(BASE_DIR, 'Bankrupt/static/surnames.txt'),"r").read().split("\n") for i in xrange(count): judge = Judge(name = random.choice(word_base), surname = random.choice(surname_base), middlename = random.choice(word_base)) judge.save() debter = Debter(type = randint(0,1), name = random.choice(word_base), number = random.choice(word_base), kved = "ONE", statepart = random.choice(surname_base), actname = random.choice(word_base), notes = str(randint(0,100))) debter.save() court = Court(number =str(randint(0,1000)), address = "Kiev", name = random.choice(word_base)) court.save() comissioner = Comissioner(powertype=str("Type1"+str(randint(0,999))), certificatenumber = str(randint(10000,99999)), setdate = datetime.datetime.now(), notes = "Hello"*2 ) comissioner.save() act = Act(startdate = datetime.datetime.now(), finishdate = datetime.datetime.now(), notes = "judge is "+judge.name, judgeid = judge, comissionerid = comissioner, courtid = court, debterid = debter) act.save() return redirect("/index")
def get_judges(deleted_judges=False, name=None, id=None): tmp = db_select( "dmob_judge", where_condition="1 {0} {1} {2}".format( "AND deleted = 0" if not deleted_judges else "", "AND name = %s" if name is not None else "", "AND id = %s" if id is not None else "", ), values=parse_args(name, id), ) from models import Judge return [Judge(*x) for x in tmp]
def validate(self): if not Form.validate(self): return False if self.pwdcheck.data != self.password.data: self.password.errors.append( "Please retype your password - they didn't match") return False checkmember = Member.query.filter_by( email=self.email.data.lower()).first() checkjudge = Judge.query.filter_by( email=self.email.data.lower()).first() if checkmember or checkjudge: # check if email is already taken self.email.errors.append("That email is already taken") return False judge = Judge(self.name.data, self.email.data.lower(), self.password.data) db.session.commit() return True
def reset_form(): user = users.get_current_user() if user.email() != SUPERUSER_EMAIL: print("user is {}".format(user.email())) abort(403) print("request args {}".format(request.args)) if 'scores' in request.args: print("Deleting scores") Score.DeleteAll() if 'team' in request.args: print("Deleting teams") Team.DeleteAll() models.SetupStaticData() judges = Judge.GetSorted() categories = Category.GetSorted() teams = Team.GetSorted() scores = Score.GetSorted() return render_template('reset.html', judges=judges, teams=teams, categories=categories, scores=scores)
def signup(role=None): form = SignUpForm() if form.validate_on_submit(): if role == 'organizer': new_user = Organizer(username=form.username.data, first_name=form.first_name.data, last_name=form.last_name.data, password=generate_password_hash( form.password.data, method='sha256'), email=form.email.data) elif role == 'judge': new_user = Judge(username=form.username.data, first_name=form.first_name.data, last_name=form.last_name.data, password=generate_password_hash( form.password.data, method='sha256'), email=form.email.data) elif role == 'captain': team = Team(name='{} {} Team'.format(form.first_name.data, form.last_name.data)) new_user = Captain(username=form.username.data, first_name=form.first_name.data, last_name=form.last_name.data, password=generate_password_hash( form.password.data, method='sha256'), email=form.email.data, team=team) db.session.add(new_user) db.session.commit() flash('New user has been created! Try to Sign In') return redirect(url_for('index')) #return form.username.data + ' ' + form.email.data + ' ' + form.password.data + ' ' + form.first_name.data + ' ' + form.last_name.data return render_template('signup.html', form=form, role=role)
def get_models(row): """ """ judge_row = Judge( **{ slug_col: clean_data(slug_col, row[col]) for col, slug_col in column_name_maps.demographic_col_map.items() }) # A judge can have multiple appointments. There are a lot of columns associated with an appointment # and they are in the data as "<Column Description (N)>", go through and link all of these # together. There is no way of knowning how many (N) a judge may have and it's not sufficient to # just look for one column that has data, so loop through and look if _any_ of the appointment # pattern columns have data up to the MAX_DUP_COLS appointment. for i in range(1, MAX_DUP_COLS): appointment_dict = {} for col, slug_col in column_name_maps.appt_col_map.items(): appt_row_val = row.get(_get_column_pattern(col, i)) if appt_row_val: appointment_dict[slug_col] = clean_data(slug_col, appt_row_val) if len(appointment_dict) == 0: continue # In case there are multiple start dates due to bad data, assume the earliest appointment_dict['start_date'] = min( appointment_dict[date_col] for date_col in column_name_maps.START_DATE_COLUMNS_TO_PARSE if appointment_dict.get(date_col)) appointment_dict['start_year'] = datetime.strptime( appointment_dict['start_date'], DATE_FORMAT).year # Multiple columns indicate a judgeship ending, take the min of them if duplicates. potential_end_dates = [ appointment_dict[date_col] for date_col in column_name_maps.END_DATE_COLUMNS_TO_PARSE if appointment_dict.get(date_col) ] # Empty list means still in job if not potential_end_dates: appointment_dict['end_date'] = None else: appointment_dict['end_date'] = min(potential_end_dates) if appointment_dict['end_date']: appointment_dict['end_year'] = datetime.strptime( appointment_dict['end_date'], DATE_FORMAT).year else: appointment_dict['end_year'] = None if appointment_dict.get('confirmation_date') and appointment_dict.get( 'nomination_date'): timedelta_to_confirm = ( datetime.strptime(appointment_dict['confirmation_date'], DATE_FORMAT) - datetime.strptime(appointment_dict['nomination_date'], DATE_FORMAT)) appointment_dict['days_to_confirm'] = timedelta_to_confirm.days else: appointment_dict['days_to_confirm'] = None judge_row.appointments.append(Appointment(**appointment_dict)) education_dict = defaultdict(dict) for i in range(1, MAX_DUP_COLS): for col, slug_col in column_name_maps.edu_col_map.items(): edu_row_val = row.get(_get_column_pattern(col, i)) if edu_row_val: education_dict[i][slug_col] = clean_data(slug_col, edu_row_val) if len(education_dict[i]) == 0: education_dict.pop(i) continue judge_row.educations.append(Education(**education_dict[i])) return judge_row
def mutate(parent, info, tournament_id, judge_id, school): SQLJudge.add_conflict(tournament_id, judge_id, school) return Judge(id=judge_id, tournament_id=tournament_id)
def mutate(parent, info, tournament_id, name): new_id = SQLJudge.add_judge(tournament_id, name) return Judge(id=new_id, name=name)
def resolve_judge(parent, info, id): judge = SQLJudge.get_judge(parent.id, id) return Judge(id=judge["id"], name=judge["name"], tournament_id=parent.id)