예제 #1
0
def index():
    reg_form = RegistrationForm(prefix='registerteam')
    contact_form = ContactForm(prefix='contactus')

    teams = Team.all()

    free_places = 24 - len(teams)

    if free_places < 0:
        free_places = 0
    if free_places > 0:
        if reg_form.submit.data:
            if reg_form.validate_on_submit():
                team = Team.create_from_registration(reg_form, store=True)
                session['scroll_to'] = 'reg_success'
                send_registration_mail(team)
                return redirect(url_for('frontend.index'))
            else:
                session['scroll_to'] = 'reg_error'

    if contact_form.submit.data:
        if contact_form.validate_on_submit():
            session['scroll_to'] = 'contact_success'
            send_contact_admin_mail(contact_form)
            return redirect(url_for('frontend.index'))
        else:
            session['scroll_to'] = 'contact_error'

    allow_new = free_places > 0
    scroll_to = session.get('scroll_to')
    try:
        del session['scroll_to']
    except KeyError, e:
        pass
예제 #2
0
def edit_team(team):

    team = Team.by_id(team)

    if team is None:
        flash('Team does not exists')
        return redirect(url_for('frontend.admin'))

    person_one = team.persons[0]
    person_two = team.persons[1]

    team_data = {
        'team': team.name,
        'person_one': person_one.raw_name,
        'person_two': person_two.raw_name,
        'email_one': person_one.email_address,
        'email_two': person_two.email_address,
        'payed': team.payed
    }
    form = EditForm(request.form, data=team_data)

    if form.validate_on_submit():
        err = team.update_from_from(form)
        if err:
            form._errors = err
            form.team.errors = err['team']
            return render_template('edit_team.html', team=team, edit_form=form)

        return redirect(url_for('frontend.admin'))

    return render_template('edit_team.html', team=team, edit_form=form)
예제 #3
0
def admin():
    message_form = MessageForm()
    teams = Team.all()
    free_places = 24 - len(teams)

    if message_form.submit.data:
        if message_form.validate_on_submit():
            send_all_teams_mail(message_form, teams)
            session['scroll_to'] = 'contact_success'
            return redirect(url_for('frontend.admin'))
        else:
            session['scroll_to'] = 'contact_error'
    scroll_to = session.get('scroll_to')
    try:
        del session['scroll_to']
    except KeyError, e:
        pass
예제 #4
0
 def validate_team(self, field):
     if Team.by_name(field.data):
         raise ValidationError('Teamname bereits vergeben.')
예제 #5
0
def delete_team(team_id):
    team = Team.by_id(team_id)
    if team:
        db.session.delete(team)
        db.session.commit()
    return redirect(url_for('frontend.admin'))