示例#1
0
def withdraw(eid):
    if current_user.getProfile() == None:
        flash('You need to create your Profile Card first!', category='info')
        return redirect(url_for('profile.create_profile'))

    event = Event.query.get_or_404(eid)
    if event.status == False:
        flash("You can't withdraw now! This event is offline right now.",
              category='warning')
        return redirect(url_for('event.event_page', eid=eid))

    x = Contestant.query.filter_by(user_id=current_user.id,
                                   event_id=eid).first()

    if x != None:
        if event.eventType() != 'Solo':
            team = Team.query.get(x.team_id)
            if team == None:
                flash("Unexpected error", category='danger')
                abort(500)

            if len(team.members) == 1:
                db.session.delete(team)

        db.session.delete(x)
        db.session.commit()

        flash(f'You are removed from {event.title} event', category='info')
    else:
        flash(f'You are already not in {event.title}', category='info')

    return redirect(url_for('event.all_events'))
示例#2
0
def joinTeam(eid):
    if current_user.getProfile() == None:
        flash('You need to create your Profile Card first!', category='info')
        return redirect(url_for('profile.create_profile'))

    event = Event.query.get_or_404(eid)
    if event.eventType() == 'Solo':
        flash('No teams in 	Solo events', category='warning')
        abort(500)

    if request.args.get('team_code'):
        team = verify_team_code(request.args.get('team_code'))
        take_participation(eid, request.args.get('team_code'))
        flash(f'You are registered in team {team.name}', category='success')

    return redirect('/myevents')
示例#3
0
def add_event():
    AdminCheck()
    if current_user.getProfile() == None:
        flash('Create your profile first', category='info')
        return redirect(url_for('profile.create_profile'))

    form = EventForm()
    if form.validate_on_submit():
        user = User.query.filter_by(username=form.orguname.data).first()
        if user is not None:
            oid = user.id
        else:
            flash('Event form validate orguname filter not working',
                  category='danger')
            abort(500)

        if form.image.data:
            picture = save_picture(form.image.data)
        else:
            picture = "default.jpg"
        try:
            if form.status.data == 'T':
                form.status.data = True
            else:
                form.status.data = False

            event = Event(title=form.title.data,
                          category=form.category.data,
                          subcategory=form.subcategory.data,
                          image=picture,
                          user_id=oid,
                          team_limit=form.num_of_member.data,
                          about=form.about.data,
                          status=form.status.data)
            db.session.add(event)
            db.session.commit()
            flash('Your Event Registered Successfully!', 'success')
            return redirect('/')
        except:
            flash('Something went wrong into database', 'danger')
            abort(403)

    return render_template('addevent.html', form=form, title='Register Event')
示例#4
0
def createTeam(eid):
    if current_user.getProfile() == None:
        flash('You need to create your Profile Card first!', category='info')
        return redirect(url_for('profile.create_profile'))

    event = Event.query.get_or_404(eid)
    if event.eventType() == 'Solo':
        flash('You cannot create team in a solo event', category='info')
        abort(500)

    if request.args.get('team_name'):
        team_name = request.args.get('team_name')
        code = create_team(team_name, eid)
        flash(f'You and your team is registered for {event.title} event',
              category='success')
    else:
        flash('No team name is given by user', category='warning')
        abort(500)

    return redirect('/myevents')
示例#5
0
def joinTeam():
    if current_user.getProfile() == None:
        # Checking Profile
        flash('You need to create your Profile Card first!', category='info')
        return redirect(url_for('profile.create_profile'))

    if request.method == 'POST':
        # Checking methos is post
        tcode = request.form.get('team_code')
        eid = request.form.get('event_id')
        if tcode == None or eid == None:
            # Checking if post data exist
            flash('Wrong form data for joining team', category='danger')
            abort(500)

        event = Event.query.get_or_404(eid)

        if len(current_user.participations) > 4:
            flash(
                "Limit Reached - You are already in 5 events, can't register for more!",
                category='info')
            return redirect(url_for('event.my_events'))

        if event.eventType() == 'Solo':
            # if event is Solo
            flash('You are trying to join a team in Solo event',
                  category='danger')
            abort(500)

        user_gender = current_user.profile.gender
        if event.gender != None and event.gender != user_gender:
            if event.gender == "M":
                flash('This event is only for Boys, check your profile',
                      category="info")
            else:
                flash('This event is only for Girls, check your profile',
                      category="info")

            return redirect(url_for('event.event_page', eid=event.id))

        team = Team.query.filter_by(team_code=tcode).first()

        if team == None:
            # Team code validation check
            flash('Your Team Code is wrong check twice!', category='danger')
            return redirect(url_for('event.event_page', eid=event.id))

        if team.event_id != event.id:
            flash(
                f"Incorrect code! This code is not of {event.title} event's team.!",
                category="danger")
            return redirect(url_for('event.event_page', eid=event.id))

        if len(team.members) == event.team_limit:
            flash('This Team is full no space left for you!', category='info')
            return redirect(url_for('event.event_page', eid=event.id))

        uparty = Contestant.query.filter_by(user_id=current_user.id,
                                            event_id=eid).first()
        if uparty == None:
            try:
                p = Contestant(user_id=current_user.id,
                               event_id=eid,
                               team_id=team.id)
                db.session.add(p)
                db.session.commit()
                flash(f'You successfully join the team {team.name}',
                      category='success')

                return redirect(url_for('team.team_card', tid=team.id))
            except:
                flash('Database error something wrong try later!',
                      category='danger')
                abort(403)
        else:
            if uparty.team_id == team.id:
                flash('You are already a member of this team!',
                      category='success')
                return redirect(url_for('team.team_card', tid=team.id))
            else:
                flash(
                    f'You are already a member of team <b>{team.name}</b> of <b>{event.title}</b> event!',
                    category='info')
                return redirect(url_for('team.team_card', tid=uparty.team_id))

    else:
        flash('No data for joining team', category='warning')
        abort(500)