def invite(): """ for host to invite people :return: the rendered form """ form = InviteForm() if form.validate_on_submit(): # add the new group group = Group(groupname=form.group.data, rsvp_close_date=form.rsvp_close_date.data, reveal_date=form.reveal_date.data, host=current_user, budget=form.budget.data) db.session.add(group) db.session.commit() # add group members members = form.members.data.split(';') invited_member_size = len(members) if form.host_join.data: members.append(current_user.email) for member in members: group_member = GroupMember(group=group, member_email=member) db.session.add(group_member) db.session.commit() # send emails host_name = current_user.get_full_name() send_invite_email(members, host_name, form.group.data, form.rsvp_close_date.data) print('Sent invitation email to {} of {}'.format( form.members.data, form.group.data)) flash('You have invited {} member(s) to join group {}'.format( invited_member_size, form.group.data)) return redirect(url_for('main.confirm')) return render_template('invite.html', title='Invite', form=form)
def profile(): # show user profile username = current_user.username name = current_user.get_full_name() ongoing_courses = get_ongoing_courses(username) for course in ongoing_courses: total_count = get_course_articles_count(course['course_name']) if course['finished_articles_count'] == total_count: completed_course(username, course['course_name']) ongoing_courses.remove(course) else: course['finished_articles_count'] = int( course['finished_articles_count'] / total_count * 100) completed_courses = get_completed_courses(username) return render_template('profile/index.html', username=username, name=name, ongoing_courses=ongoing_courses, completed_courses=completed_courses)
def add_member(group_name): """ for host to invite people :return: the rendered form """ form = AddMember() current_group = Group.query.filter_by(groupname=group_name).first() # check if requested by the host host = current_group.host if host.id != current_user.id: flash('Only the host is allowed to invite people to join group.') return redirect(url_for('main.index')) # cannot add after rsvp close date if datetime.date.today() >= current_group.rsvp_close_date: flash('We are sorry but the sign up for group {} has already closed.'. format(group_name)) return redirect(url_for('main.index')) if form.validate_on_submit(): # check if user already in group members = current_group.get_all_member_emails() if form.email.data in members: flash('{} has already been invited to group {}'.format( form.email.data, group_name)) return redirect(url_for('main.index')) # add group members group_member = GroupMember(group=current_group, member_email=form.email.data) db.session.add(group_member) db.session.commit() # send emails host_name = current_user.get_full_name() send_invite_email([form.email.data], host_name, group_name, current_group.rsvp_close_date) print('Sent invitation email to {} of {}'.format( form.email.data, group_name)) flash('You have invited {} to join group {}'.format( form.email.data, group_name)) return redirect(url_for('main.confirm')) return render_template('add_member.html', title='Invite', group=group_name, form=form)
def article(course_name, subject, article_name): # show article for a given course, subject, and name and submit a comment about it if request.method == 'POST': comment = request.form['comment'] if current_user.is_authenticated: ack = add_comment(course_name, subject, article_name, current_user.get_id(), current_user.get_full_name(), comment) if not ack: flash("Could not add your comment", category='error') course_info = get_course_info(course_name) course_content = course_info['content'] article = get_article(course_name, subject, article_name) comments = get_comments(course_name, subject, article_name) return render_template('course/index.html', course_name=course_name, subject=subject, course_content=course_content, article_name=article_name, article=article, comments=comments)
def user_page(id): user_values = user_db.query_user(id) if user_values != None: if 'current_custom_workout' not in user_values['content']: custom_workouts = dict() else: custom_workouts = user_values['content']['current_custom_workout'] current_user_values = user_db.query_user(current_user.get_id()) uploads = content_db.query_content_by_user(id) progress = progress_db.query_user(user_values['email']) calories = "" if progress: calories = progress['content']['weekly_cals'] subscribed_to = [] subscriber_count = 0 if current_user_values['content'] and current_user.role != roles[2]: if 'subscribed_accounts' in current_user_values['content']: subscribed_to = current_user_values['content'][ 'subscribed_accounts'] if 'subscribers' in user_values['content']: if user_values['role'] == roles[1] and user_values[ 'content'] and user_values['content']['subscribers']: subscriber_count = user_values['content']['subscribers'] subscribed = False if id in subscribed_to: subscribed = True if request.method == "POST": action = request.form.get("action") if action == "subscribe": user_db.subscribe(current_user.email, user_values['email']) notification_message = Markup( "<a href='/user/{}' target='_blank'>{}</a> just subscribed to you." .format(current_user.email, current_user.get_full_name())) add_notification(id, notification_message) return redirect(url_for("users.user_page", id=id)) elif action == "unsubscribe": user_db.unsubscribe(current_user.email, user_values['email']) return redirect(url_for("users.user_page", id=id)) elif action == "new_message": message = request.form.get("message") messages_db.insert_conversation(str(uuid.uuid4()), current_user.email, user_values['email'], message) flash("Chat successfully created", category="success") return redirect(url_for("users.user_page", id=id)) if id == current_user.get_id(): return redirect(url_for("users.profile")) user_image = user_values['image'] specialty = "" flag_src = "" bio = user_values['bio'] gender = user_values['gender'] profile_user = User(user_values['email'], user_values['password'], user_values['first_name'], user_values['last_name'], user_values['role']) if user_values and user_values['role'] == roles[1]: if 'country' in user_values: country_info = user_values['country'] if 'flag' in country_info: flag_src = country_info['flag'] if 'specialty' in user_values: specialty = user_values['specialty'] else: flash("That user does not exist!", category="error") return redirect(url_for("views.home")) return render_template("profile.html", user=profile_user, user_image=user_image, uploads=uploads, specialty=specialty, gender=gender, bio=bio, flag_src=flag_src, countries=dict(), country_codes=list(), length=0, subscribed=subscribed, subscriber_count=subscriber_count, custom_workouts=custom_workouts, calories=calories)