def adjustmember_submit(club): '''Input adjustment of club members''' member = User(request.form['uid']) true_or_fail(current_user != member, 'You cannot expel yourself.', 'expelled') if form_is_valid(): club.remove_member(member) parameters = {'member': member, 'club': club} contents = render_email_template('adjustmember', parameters) member.email_user('Member Adjustment - ' + club.name, contents) member.notify_user('You have been moved out of ' + club.name + '.') flash(member.nickname + ' has been expelled.', 'expelled') return redirect(url_for('.adjustmember', club=club.callsign))
def actintro_submit(activity): '''Signup for activity''' if activity.selections: selection = request.form['selection'].strip() true_or_fail(selection in activity.selections, 'Please select a valid choice.', 'signup') else: selection = '' error_or_fail(lambda: activity.signup_user_status(current_user), NoRow, 'You have already signed up for this activity.', 'signup') if form_is_valid(): activity.signup(current_user, selection=selection) flash('You have successfully signed up for ' + activity.name + '.', 'signup') return redirect(url_for('.actintro', activity=activity.callsign))
def actstatus_submit(activity): '''Change consent form status''' member = User(request.form['uid']) true_or_fail(member in activity.club.members, member.nickname + ' is not a member of this club.', 'consent_form') if form_is_valid(): status = int(request.form['status']) if status == 0: activity.signup(member, consentform=True) flash(member.nickname + ' has handed in the consent form.', 'consent_form') elif status == 1: activity.signup(member, consentform=False) flash(member.nickname + ' has not handed in the consent form.', 'consent_form') return redirect(url_for('.actstatus', activity=activity.callsign))
def registerhm_submit(club): '''Submit HongMei signup info to database''' register = request.form.getlist('register') plan = '' for reg in register: act = Activity(reg) true_or_fail(act.club == club, 'wtf? Please enter a valid activity.', 'reghm') if form_is_valid(): act.signup(current_user) plan += 'Date: ' + act.date.strftime('%b-%d-%y') + '\n\n' + \ 'Content: ' + act.name + '\n\n' if form_is_valid(): parameters = {'user': current_user, 'club': club, 'plan': plan} contents = render_email_template('registerhm', parameters) current_user.email_user('HongMei Plan - ' + club.name, contents) flash('Your application has been successfully submitted.', 'reghm') return redirect(url_for('.registerhm', club=club.callsign))
def hongmei_invite_submit(activity): '''Input invitation result into database''' invite = request.form.getlist('invite') for each in invite: member = User(each) true_or_fail(member in activity.club.members, member.nickname + ' is not a member of this club.', 'invite_hm') if form_is_valid(): activity.signup(member) parameters = {'member': member, 'activity': activity} contents = render_email_template('invitehm', parameters) member.email_user('HongMei Invitation - ' + activity.club.name, contents) member.notify_user('You have been invited to HongMei activity - ' + activity.name + ' on ' + activity.date.strftime('%b-%d-%y') + '.') flash('These members have been successfully invited.', 'invite_hm') return redirect(url_for('.hongmei_invite', activity=activity.callsign))
def clubintro_submit(club): '''Add new member''' true_or_fail(current_user.type == UserType.STUDENT, 'You may not join clubs.', 'join') true_or_fail(club.joinmode == ClubJoinMode.FREE_JOIN, 'You may not join this club.', 'join') if form_is_valid(): try: club.add_member(current_user) except AlreadyExists: fail('You are already in %s.' % club.name, 'join') return redirect(url_for('.clubintro', club=club.callsign)) parameters = {'club': club, 'current_user': current_user} contents = render_email_template('joinclubs', parameters) club.leader.email_user('New Club Member - ' + club.name, contents) club.leader.notify_user('%s has joined %s.' % (current_user.nickname, club.name)) flash('You have successfully joined ' + club.name + '.', 'join') return redirect(url_for('.clubintro', club=club.callsign))
def invitemember(club): '''Allow club leader to invite member''' true_or_fail(club.joinmode == ClubJoinMode.BY_INVITATION, 'You cannot invite members when the join mode is not ' 'by invitation.', 'invite_member') if form_is_valid(): new_member = User.find_user(request.form['gradeclass'], request.form['passportname']) if new_member is None: fail('Please input correct user info to invite.', 'invite_member') else: parameters = {'club': club, 'member': new_member} contents = render_email_template('invitemember', parameters) new_member.email_user('Invitation - ' + club.name, contents) if new_member in club.members: fail('%s is already in the club.' % new_member.nickname, 'invite_member') else: club.send_invitation(new_member) flash('The invitation has been sent to %s.' % new_member.nickname, 'invite_member') return redirect(url_for('.adjustmember', club=club.callsign))
def newclub_submit(): '''Upload excel file to create new clubs''' if not siteconfig.get_config('allow_club_creation'): abort(403) clubname = request.form['clubname'] email = request.form['email'] clubtype = int(request.form['clubtype']) location = request.form['location'] intro = request.form['intro'] description = request.form['description'].strip() true_or_fail(clubname, 'Please input club name.', 'newclub') true_or_fail(email, 'Please input teacher\'s email address.', 'newclub') true_or_fail(location, 'Please input club\'s meeting location.', 'newclub') true_or_fail(intro, 'Please input club\'s one-sentence introduction.', 'newclub') true_or_fail(len(intro) <= 90, 'Your one sentence intro is too long.', 'newclub') true_or_fail(description, 'Please input club\'s paragraph description.', 'newclub') if form_is_valid(): c = Club.new() c.name = clubname teacher = User.find_teacher(email) if teacher is not None: c.teacher = teacher else: fail('There is no teacher with this email address.', 'newclub') return redirect(url_for('.newclub')) c.leader = current_user c.description = FormattedText.emptytext() c.location = location c.is_active = False c.intro = intro c.picture = Upload(-101) c.type = ClubType(clubtype) c.joinmode = ClubJoinMode.FREE_JOIN c.reactivate = True c.create() c.add_member(current_user) c.description = FormattedText.handle(current_user, c, request.form['description']) return redirect(url_for('.clubintro', club=c.callsign)) return redirect(url_for('.newclub'))