def contact(): """ Contact student or staff member. """ # Create an empty error. error = None # Create a form object. contact_form = ContactForm() # Select all the staff and tutors. contact_form.user.choices = [ (user.user_id, user.get_full_name() + " (" + user.get_role(pretty=True) + ")") for user in select_users_by_roles( ('TUT', 'STA', 'STU') ) ] if request.method == 'POST' and contact_form.validate_on_submit(): # Form is valid. # Check the staff members is not the default if contact_form.user.data == '0': error = 'A user must be chosen.' else: # Find the user. user = User.query.filter(User.user_id == contact_form.user.data).first() # Create a new email message. message = Message(contact_form.subject.data, recipients=[user.get_email_address()]) message.html = render_template( 'email/message.html', user=user, subject=contact_form.subject.data, message=contact_form.message.data ) # Send the message. mail.send(message) # Flash a success message. flash('Successfully sent message.') # Redirect to the dashboard. return redirect(url_for('staff.dashboard')) return render_template( 'staff/contact.html', contact_form=contact_form, error=error )
def contact_parent(): """ Contact parent. """ # Create an empty error. error = None # Create a form object. contact_form = ContactForm() # Select all the staff and tutors. contact_form.user.choices = [ (parent.parent_id, parent.get_full_name()) for parent in select_parents() ] if request.method == 'POST' and contact_form.validate_on_submit(): # Form is valid. # Check the staff members is not the default if contact_form.user.data == '0': error = 'A parent must be chosen.' else: # Find the user. parent = Parent.query.filter(Parent.parent_id == contact_form.user.data).first() # Create a new email message. message = Message(contact_form.subject.data, recipients=[parent.get_email_address()]) message.html = render_template( 'email/message.html', user=parent, subject=contact_form.subject.data, message=contact_form.message.data, parent=True ) # Send the message. mail.send(message) # Flash a success message. flash('Successfully sent message.') # Redirect to the dashboard. return redirect(url_for('staff.dashboard')) return render_template( 'staff/contactparent.html', contact_form=contact_form, error=error )
def send_lesson_update(user_obj, update_html, view_lesson_link, **kwargs): """ Sends a lesson update to the user/their parent. """ recipients = [user_obj.get_email_address()] if 'parent' in kwargs and kwargs['parent']: recipients.append(user_obj.parent.get_email_address()) message = Message('Something has been updated.', recipients=recipients) # Render the html. message.html = render_template( 'email/update.html', message=update_html, view_lesson_link=view_lesson_link ) # Send the mail. mail.send(message)