Ejemplo n.º 1
0
 def __init__(self, **kwargs):
     super().__init__(**kwargs)
     self.team.choices = [(0, '')] + \
                         [(t.team_id, t) for t in Team.query.filter(Team.name == TEAM_ORGANIZATION).all()] + \
                         [(t.team_id, t) for t in Team.query.filter(Team.name == TEAM_SUPER_VOLUNTEER).all()] + \
                         [(t.team_id, t) for t in Team.query.filter(Team.name != TEAM_SUPER_VOLUNTEER).all()
                          if t.is_active()]
     self.volunteer.choices = [
         (0, 'Please select a volunteer to assign to this shift.')
     ]
     if current_user.is_organizer():
         super_volunteers = User.query.filter(
             User.volunteer_id.isnot(None)).all()
         contestants = Contestant.query.join(StatusInfo).filter(
             StatusInfo.status == CONFIRMED).all()
         volunteers = sorted(super_volunteers +
                             [c.user for c in contestants],
                             key=lambda x: x.get_full_name())
         self.volunteer.choices.extend([(u.user_id, f"{u.get_full_name()}")
                                        for u in volunteers])
     elif current_user.is_tc():
         volunteers = Contestant.query.join(StatusInfo, ContestantInfo)\
             .filter(ContestantInfo.team == current_user.team, StatusInfo.status == CONFIRMED)\
             .order_by(Contestant.first_name).all()
         self.volunteer.choices.extend([
             (v.user.user_id, v.user.get_full_name()) for v in volunteers
         ])
Ejemplo n.º 2
0
def contestants_all_payment(contestant_id, all_paid):
    dancer = Contestant.query.get_or_404(contestant_id)
    if current_user.is_cia() or (
        (current_user.is_tc() or current_user.is_treasurer())
            and dancer.contestant_info.team == current_user.team):
        if request.method == "PATCH":
            dancer.payment_info.all_is_paid(all_paid)
            db.session.commit()
        return jsonify(dancer.json())
    return jsonify(None)
Ejemplo n.º 3
0
def contestants_merchandise_payment(contestant_id, merchandise_purchased_id,
                                    merchandise_paid):
    dancer = Contestant.query.get_or_404(contestant_id)
    purchase = MerchandisePurchase.query.get_or_404(merchandise_purchased_id)
    if current_user.is_cia() or (
        (current_user.is_tc() or current_user.is_treasurer())
            and dancer.contestant_info.team == current_user.team):
        if request.method == "PATCH":
            purchase.paid = merchandise_paid
            db.session.commit()
        return jsonify(dancer.json())
    return jsonify(None)
Ejemplo n.º 4
0
def profile():
    form = ChangePasswordForm()
    send_email_form = SendEmailForNotificationsForm()
    if request.method == 'GET':
        send_email_form.send_email.data = current_user.send_new_messages_email
    if send_email_form.email_submit.data:
        if send_email_form.validate_on_submit():
            current_user.send_new_messages_email = send_email_form.send_email.data
            db.session.commit()
            flash('E-mail notification preference changed.', 'alert-success')
            return redirect(url_for('main.profile'))
    if form.submit.data:
        if form.validate_on_submit():
            user = User.query.filter_by(username=current_user.username).first()
            if not user.check_password(form.current_password.data):
                flash('Invalid username or password', 'alert-danger')
                return redirect(url_for('main.profile'))
            current_user.set_password(form.password.data)
            db.session.commit()
            flash('Your password has been changed.', 'alert-success')
            return redirect(url_for('main.profile'))
    if current_user.is_tc():
        treasurer_form = TreasurerForm()
        treasurer = db.session.query(User).filter_by(
            team=current_user.team, access=ACCESS[TREASURER]).first()
        if treasurer_form.tr_submit.data:
            if treasurer_form.validate_on_submit():
                tr_pass = random_password()
                treasurer.set_password(tr_pass)
                treasurer.email = treasurer_form.email.data
                treasurer.is_active = True
                db.session.commit()
                send_treasurer_activation_email(treasurer_form.email.data,
                                                treasurer.username, tr_pass,
                                                treasurer_form.message.data)
                flash(
                    'Your treasurer now has access to the xTDS WebPortal. '
                    'Login credentials have been sent to the e-mail provided.',
                    'alert-info')
                return redirect(url_for('main.profile'))
        return render_template('profile.html',
                               form=form,
                               treasurer_form=treasurer_form,
                               treasurer_active=treasurer.is_active,
                               send_email_form=send_email_form)
    else:
        return render_template('profile.html',
                               form=form,
                               send_email_form=send_email_form)
Ejemplo n.º 5
0
def shifts():
    if current_user.is_tc() and not g.ts.volunteering_system_open:
        flash("This page is not accessible yet.")
        return redirect(url_for('main.dashboard'))
    all_tasks = ShiftInfo.query.order_by(ShiftInfo.name).all()
    if current_user.is_organizer():
        shift_list = Shift.query.order_by(Shift.start_time).all()
    else:
        shift_list = Shift.query.join(ShiftSlot)\
            .filter(or_(ShiftSlot.team == current_user.team,
                        and_(ShiftSlot.team_id.is_(None), ShiftSlot.mandatory.is_(False)),
                        and_(ShiftSlot.user_id.isnot(None), ShiftSlot.mandatory.is_(True))),
                    Shift.published.is_(True))\
            .order_by(Shift.start_time).all()
        shift_list = [s for s in shift_list if s.has_slots_available(current_user.team)]
    task_list = {task: [shift for shift in shift_list if shift.info == task] for task in all_tasks}
    if current_user.is_organizer():
        filled_list = {task: sum([shift.filled_slots() for shift in shift_list if shift.info == task])
                       for task in all_tasks}
        slots_list = {task: sum([len(shift.slots) for shift in shift_list if shift.info == task])
                      for task in all_tasks}
        return render_template('volunteering/shifts.html', shifts=shift_list, task_list=task_list,
                               filled_list=filled_list, slots_list=slots_list)
    else:
        task_list = {task: task_list[task] for task in task_list if len(task_list[task]) > 0}
        all_volunteers = Contestant.query.join(ContestantInfo, StatusInfo)\
            .filter(ContestantInfo.team == current_user.team, StatusInfo.status == CONFIRMED)\
            .order_by(Contestant.first_name).all()
        days = sorted(set([s.start_time.date() for s in shift_list]))
        sorted_shifts = {day: [s for s in shift_list if s.start_time.date() == day] for day in days}
        team_slots = ShiftSlot.query.filter(ShiftSlot.team == current_user.team).all()
        team_slots = [s for s in team_slots if s.shift.published]
        organization_slots = ShiftSlot.query.filter(ShiftSlot.mandatory.is_(True), ShiftSlot.user_id.isnot(None),
                                                    ShiftSlot.team_id.is_(None)).all()
        organization_slots = [s for s in organization_slots if s.user.team == current_user.team and s.shift.published]
        hours = {'total': hours_delta(sum([s.duration() for s in team_slots], timedelta(0, 0))),
                 'filled': hours_delta(sum([s.duration() for s in team_slots if s.user is not None], timedelta(0, 0))),
                 'freelance': hours_delta(sum([s.duration() for s in organization_slots], timedelta(0, 0)))
                 }
        return render_template('volunteering/shifts.html', shifts=shift_list, task_list=task_list,
                               all_volunteers=all_volunteers, sorted_shifts=sorted_shifts, hours=hours)
Ejemplo n.º 6
0
def shift_slot(slot_id):
    slot = ShiftSlot.query.get(slot_id)
    form = ShiftSlotForm()
    task_id = request.args.get("task_id", default=None)
    if current_user.is_tc():
        if not slot.is_editable(current_user.team):
            flash("You cannot edit this shift, it is not part of your team!", "alert-warning")
            return redirect(url_for('volunteering.shifts',
                                    task_id=task_id if task_id is not None else slot.shift.info.shift_info_id))
        form.submit.label.text = 'Assign dancer'
        form.volunteer.description = 'Assigning a dancer to this shift wil automatically claim the shift for your team.'
        form.mandatory.validators = []
        form.mandatory.data = str(False)
    if request.method == 'POST':
        if form.submit.name in request.form:
            if form.validate_on_submit():
                volunteer = User.query.get(form.volunteer.data) if form.volunteer.data > 0 else None
                team = Team.query.get(form.team.data) if form.team.data > 0 else None
                if current_user.is_organizer():
                    if not slot.user_assigned_to_shift(volunteer):
                        if volunteer is not None:
                            test_shifts = Shift.query.join(ShiftSlot).filter(ShiftSlot.user == volunteer).all()
                            test_shifts = [s for s in test_shifts if not (slot.shift.stop_time <= s.start_time or
                                                                          slot.shift.start_time >= s.stop_time)]
                            if len(test_shifts) > 0:
                                flash(f"Added {volunteer} to {slot.shift}.<br/>{volunteer} is already assigned "
                                      f"to {test_shifts[0]} at the same time, so make sure that this is is "
                                      f"possible!", "alert-warning")
                        slot.user = volunteer
                        slot.team = team
                        if volunteer is not None and team is not None:
                            if team != volunteer.team:
                                slot.user = None
                                flash(f'Did not add {volunteer} to slot, he/she is not part of team {team}',
                                      'alert-warning')
                        slot.mandatory = str2bool(form.mandatory.data)
                        db.session.commit()
                        flash('Changes saved.')
                        return redirect(url_for('volunteering.single_shift', shift_id=slot.shift.shift_id))
                    else:
                        flash(f'Cannot assign {volunteer}, he/she is already assigned to a slot in this shift.',
                              'alert-warning')
                else:
                    slot.team = current_user.team
                    if volunteer is not None:
                        test_shifts = Shift.query.join(ShiftSlot).filter(ShiftSlot.user == volunteer).all()
                        test_shifts = [s for s in test_shifts if not (slot.shift.stop_time <= s.start_time or
                                                                      slot.shift.start_time >= s.stop_time)]
                        if len(test_shifts) > 0:
                            flash(f"Cannot add {volunteer} to {slot.shift}.<br/>{volunteer} is already assigned "
                                  f"to {test_shifts[0]}.", "alert-danger")
                            return redirect(url_for('volunteering.shift_slot', slot_id=slot.slot_id))
                        if not slot.user_assigned_to_shift(volunteer):
                            slot.user = volunteer
                            db.session.commit()
                            flash(f'Assigned {volunteer} to shift {slot.shift}.')
                            return redirect(url_for('volunteering.shifts',
                                                    task_id=task_id if task_id is not None
                                                    else slot.shift.info.shift_info_id))
                        else:
                            flash(f'Cannot assign {volunteer}, he/she is already assigned to a slot in this shift.',
                                  'alert-warning')
                    else:
                        flash(f'Cleared slot of shift {slot.shift}.')
                        slot.user = None
                        db.session.commit()
                        return redirect(url_for('volunteering.shifts',
                                                task_id=task_id if task_id is not None
                                                else slot.shift.info.shift_info_id))
        if current_user.is_tc():
            if 'claim' in request.form:
                slot.team = current_user.team
                db.session.commit()
                flash(f'Claimed slot in shift {slot.shift}.')
                return redirect(url_for('volunteering.shifts',
                                        task_id=task_id if task_id is not None else slot.shift.info.shift_info_id))
            if 'release' in request.form:
                slot.user = None
                slot.team = None
                db.session.commit()
                flash(f'Released slot in shift {slot.shift}.')
                return redirect(url_for('volunteering.shifts',
                                        task_id=task_id if task_id is not None else slot.shift.info.shift_info_id))
    form.populate(slot)
    return render_template('volunteering/slot.html', slot=slot, form=form)