def view_parent(parent_id): """ View a single parent. """ # Select the parent. parent = select_parents(parent_id=parent_id, single=True) # Check the parent exists. if parent is not None: return render_template( 'staff/view_parent.html', parent=parent ) else: # If the parent isn't found, return a 404. abort(404)
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 )