def edit_meeting_form1(request, meeting):
    
    form = MeetingFormStepOne({
                                'name':meeting.name,
                                'description':meeting.description,
                                'duedate':meeting.duedate,
                                'startdate':meeting.startdate,
                                'starttime':meeting.starttime,
                            }).as_table()


    modal_content = form_modal(request,
                                #Add the meeting form.
                                'editmeetingform_%s'%meeting.publicid,
                                #Get the actual form from the form model.
                                form,
                                #Name the modal_form.
                                table_class='modal_form',
                                #Add the topics.
                                submit_text='Update',
                                #Add a modal title.
                                modal_title='Edit \'%s\'' % meeting.name,
                                #Add a modal_id.
                                modal_id='editmeetingform1_%s' % meeting.publicid,
                                #Add an extra field html.
                                extra_fields='<input type="hidden" name="update_meeting_information" value="%s"/>' % meeting.publicid,
                                #Add a special form action
                                action="%s#%s"% (request.get_full_path(),meeting.publicid)
                            )

    edit_meeting_form1 = mark_safe(modal_content)

    return edit_meeting_form1
def viewmeetings(request):

	"""
	" Generate the handlers for all of the data.
	"""

	if request.user.groups.filter(Q(name='Supervisor')).count() != 0:

		"""
		" Handle the deletion of a meeting.
		"""
		#Update the meeting information, this updates just this information:
		#		-The name.
		#		-The description.
		#		-The start time.
		if 'delete_meeting' in request.POST:
			#Update this publicid
			publicid = request.POST['delete_meeting']
			#Get the meeting to edit.
			meeting_to_delete = Meeting.objects.get(publicid=publicid)
			#Get the name of the meeting.
			name = meeting_to_delete.name
			#Get the topics associated with the meeting.
			meeting_topics =	meeting_to_delete.topics
			#Loop through all of the meeting topics
			for t in meeting_topics.all():
				#Set the meeting to None.
				t.meeting = None
				#Save the meeting.
				t.save()
			#Clear the meeting topics.
			meeting_topics.clear()
			
			redirect_url_string = meeting_url_string(meeting_to_delete.publicid,(('deleted',meeting_to_delete.name),))

			#Save the meeting.
			meeting_to_delete.delete()

			#Redirect to the meetings 
			return redirect(redirect_url_string)
			#return redirect('/viewmeetings/?deleted=%s'% name)

		"""
		" End the handle of updating meeting information.
		"""

		"""
		" Handle the update of the meeting information.
		"""
		#Update the meeting information, this updates just this information:
		#		-The name.
		#		-The description.
		#		-The start time.
		if 'update_meeting_information' in request.POST:
			#Update this publicid
			publicid = request.POST['update_meeting_information']
			#Get the meeting to edit.
			meeting_to_edit = Meeting.objects.get(publicid=publicid)
			#Update the meeting name.
			meeting_to_edit.name = request.POST['name']
			#Update the meeting description.
			meeting_to_edit.description = request.POST['description']
			#Update the meeting start time.
			meeting_to_edit.starttime =format_time(request.POST['starttime'])

			#Save the meeting.
			meeting_to_edit.save()

			#Redirect to the meetings 
			return redirect(meeting_url_string(meeting_to_edit.publicid,(('updated',meeting_to_edit.name),)))

			#return redirect('/viewmeetings/?updated=%s#%s'%(meeting_to_edit.name,publicid))

		"""
		" End the handle of updating meeting information.
		"""

		"""
		" Handle the update of the schedule for each meeting.
		"""

		#Update the meeting schedule order, the order is the right way.
		if 'update_meeting_schedule_publicid' in request.POST:
			
			#Update this publicid
			publicid = request.POST['update_meeting_schedule_publicid']

			#Get the meeting to edit.
			meeting_to_edit = Meeting.objects.get(publicid=publicid)

			#Get the schedule_items.
			schedule_items = request.POST['schedule_items'].split(',')
			#Update the meeting schedule.
			update_meeting_schedule(meeting_to_edit,schedule_items,new=False)
			#Update the items on the schedule.
			meeting_to_edit.maxscheduleitems = len(schedule_items)
			#Save the meeting information.
			meeting_to_edit.save()

			#Redirect to the meetings 
			return redirect(meeting_url_string(meeting_to_edit.publicid,(('updated',meeting_to_edit.name),)))

			#return redirect('/viewmeetings/?updated=%s#%s'%(meeting_to_edit.name,publicid))

		"""
		" End the handle of the update of the schedule for this meeting.
		"""

		"""
		" Handle the add meeting form data.
		"""
		#This handles the information for the add meeting form.
		if 'schedule_items' in request.POST and 'addmeetingform' in request.session:
			#Add the meeting form a session variable.
			form = request.session['addmeetingform']
			#Get the publicid for all of the topics.
			schedule_items = request.POST['schedule_items'].split(',')
			#Format the duedate.
			duedate = format_date(form['duedate'])
			#Format the startdate.
			startdate =  format_date(form['startdate'])
			#Get the starttime
			starttime = format_time(form['starttime'])
			#Create a new meeting.
			newmeeting = Meeting(
												name = form['name'],
												description=form['description'],
												duedate=duedate,
												startdate=startdate,
												maxscheduleitems=len(schedule_items),
												starttime=starttime,
												user=request.user,
												duration=0
			)
			#Save the new meeting.
			newmeeting.save()
			#Add Schedule
			update_meeting_schedule(newmeeting,schedule_items);

			#Redirect to the meetings 
			return redirect(meeting_url_string(newmeeting.publicid,(('added',newmeeting.name),)))

		"""
		" End the handle of the add meeting form.
		"""

	"""
	" End the handlers of the data.
	"""

	"""
	" Generate the dates needed for the calendar interface.
	"""
	#Get the date of this month.
	today = date.today() + relativedelta(day=1)
	#Get the year of the current month.
	year = int(request.GET['year']) if 'year' in request.GET else today.year
	#Get the month.
	month = int(request.GET['month']) if 'month' in request.GET else today.month
	#The date that will be displayed.
	displaydate = date(day=1,month=month,year=year)
	#Get the previous month.
	prev_month = displaydate+relativedelta(months=-1)
	#Get the next month.
	next_month = displaydate+relativedelta(months=+1)
	"""
	" End of calendar dates needed.
	"""


	"""
	" Get the meetings that will be on the calendar.
	"""
	#Load the meeting objects into a list
	meetings = Meeting.objects.filter(
										  deleted=False,
										  startdate__year=displaydate.year,
										  startdate__month=displaydate.month,
										  ).order_by('startdate','starttime')
	"""
	" End of the meetings that will be on the calendar.
	"""


	"""
	" For each meeting get the views asociated.
	"""
	#load the topics available, for making the schedule.
	topics = Topic.objects.filter(meeting=None,
																readyforreview=True,
																supervisor_released=False,
																deleted=False)

	#Create a list with meetings in it.
	meetings_list = []

	"""
	" Get the next meeting.
	"""
	nextm = get_next_meeting()


	if nextm and (nextm.startdate.month != month or nextm.startdate.year != year):

		print str(nextm.startdate.month)+":"+str(nextm.startdate.year)
		print str(month)+":"+str(year)

		nextmeeting = {
			'next_view_meeting':view_meeting(request,nextm),
			'next_edit_meeting_form1':edit_meeting_form1(request,nextm),
			'next_edit_meeting_form2':edit_meeting_form2(request,topics,nextm),
		}

	else:

		nextmeeting = None

	#Loop through each meeting on the calendar.
	for m in meetings:

		meeting_dict = {}

		"""
		" This loads the meeting view, when you click on a calendar
		"		item this is the modal that gets loaded.
		"""
		view_meeting_var = view_meeting(request,m)
		"""
		" Load the edit meeting information form.
		"""
		edit_meeting_form1_var = edit_meeting_form1(request, m)
		"""
		" Load the meeting schedule editor.
		"""
		edit_meeting_form2_var = edit_meeting_form2(request,topics,m)

		#Merge to the meeting context variable.
		meeting_dict['view_meeting'] = view_meeting_var
		#Merge to the meeting context variable.
		meeting_dict['edit_meeting_form1'] = edit_meeting_form1_var
		#Load the edit meeting dict.
		meeting_dict['edit_meeting_form2'] = edit_meeting_form2_var


		#Add the meetings to the list.
		meetings_list.append(meeting_dict)

	"""
	" End of getting the views for each meeting.
	"""


	"""
	" Get the form for adding a meeting to the form.
	"""

	#Load the addmeeting form.
	if 'loadprevious' not in request.GET and 'loadnext' in request.GET and (
			#Check for meeting information in a form
			('addmeetingform' in request.session) 
				or
			#Check for the meeting in the add form.
			('addmeetingform' in request.POST)
		):
		
		#Save the post data in to a session variable
		request.session['addmeetingform'] = request.POST

		#Add a meeting form.
		addmeetingform2 = mark_safe(render(request,
														'meeting_management/addmeetingform2.html',
														{'topics':topics}).content
											)
		#Check the meeting form.
		meetingform = mark_safe(
				#Load a modal template 
				modal(request,
						#This is the meetingform.
						addmeetingform2,
						#This is the modal title.
						modal_title='Create a Schedule',
						#This is the add meeting form.
						modal_id='addmeetingform',
						#Add a class to the modal.
						modal_class='addmeetingform'
				).content
			)
		#Load the form.
		loadform = True
	else:
		#Load the form.
		loadform = True if 'loadprevious' in request.GET else False

		#If the form is the meeting form.
		if not loadform and 'addmeetingform' in request.session:
			#Delete the meeting.
			del request.session['addmeetingform']

		#Get the first meeting form
		meetingform = form_modal(request,
										#Add the meeting form.
										'addmeetingform',
										#Get the actual form from the form model.
										AddMeetingForm(
												#If there is request POST information,
												#			populate the form with it.
												request.POST if 'addmeetingform' in request.POST else 
													#If there is session from the previous form populate the form with it.
													#		otherwise the form can be empty.
													request.session['addmeetingform'] if 'addmeetingform' in request.session else None
										 ).as_table(),
										#Name the modal_form.
										table_class='modal_form',
										#Add the topics.
										submit_text='Add Topics',
										#Add a get string
										get_string='loadnext=1',
										#Add a modal title.
										modal_title='Add a Meeting',
										#Add a modal_id.
										modal_id='addmeetingform1'
									)
	"""
	" End of getting the form for adding a meeting.
	"""



	"""
	" Create the calendar object.
	"""
	#Get the calendar.
	calendar = mark_safe(MeetingCalendar(meetings).formatmonth(year, month))
	"""
	" End of calendar object.
	"""

	context = {
		
		'title':'Meetings',
		'meetings_list':meetings_list,
		'meetingform':meetingform,
		'calendar': calendar,
		'nextmeeting':nextmeeting,
		
		###
		# These are the month variables.
		###
			
			#The previous month in the year.
			'prev_month':prev_month,
			#The next month in the year.
			'next_month':next_month,
			#This is a textual version of the previous month.
			'prev_month_textual':prev_month.strftime("%b, %Y"),
			#This is a textual version of the next month.
			'next_month_textual':next_month.strftime("%b, %Y"),
		
		###
		# End of the month variables.
		###

		#If the modal needs to be loaded
		'loadform':loadform

	}



	#Render the request information.
	return render(request,
 			'meeting_management/viewmeetings.html',
			context)
def viewusers(request):
	
	context= {
			'title':'View Users',
	}

	existingusernotification = False

	#Check to see if a user has been edited
	if request.method == 'POST' and ('edit_user' in request.POST or 'add_user' in request.POST):
		"""
		" Get the form data.
		"""
		#Get the username.
		newusername = request.POST['username']
		#Get the first name.
		newfirst_name = request.POST['first_name']
		#Get the last name.
		newlast_name = request.POST['last_name']
		#Get the email.
		newemail = request.POST['email']
		#Get the phone number.
		newphonenumber = request.POST['phonenumber']
		#Get the password.
		newpassword = request.POST['password']
		#Get wether or not they are active.
		is_active = False
		if 'is_active' in request.POST:
			is_active = True

		is_program_manager = False
		if 'is_program_manager' in request.POST:
			is_program_manager = True

		if 'edit_user' in request.POST:
			#Get the public id
			publicid = request.POST['edit_user']
			#Get the extended user
			extendeduser = ExtendedUser.objects.get(publicid=publicid)
		else:
			extendeduser = False

		"""
		" End the form data.
		"""

		"""
		" Check if is existing user.
		"""
		if not check_existing_user(newusername) or extendeduser and extendeduser.user.username == newusername:

			"""
			" Save the user information.

			"""
			#We are making a new user
			if extendeduser:
				#Get the username.
				extendeduser.user.username = newusername
				#Get the first name.
				extendeduser.user.first_name= newfirst_name
				#Get the last name.
				extendeduser.user.last_name = newlast_name
				#Get the email.
				extendeduser.user.email = newemail
				#Add the phonenumber
				extendeduser.phonenumber = newphonenumber
			else:
				#Create a new user
				user = User.objects.create_user(
					username=newusername,
					password=newpassword,
					first_name=newfirst_name,
					last_name=newlast_name,
					email=newemail,
				)

				extendeduser = ExtendedUser(user=user,phonenumber=newphonenumber)
			
			#Get the active boolean.
			extendeduser.user.is_active= is_active

			#Save the user.
			extendeduser.user.save()
			extendeduser.save()

			if is_program_manager:
				program_manager = Group.objects.get(name='Program Manager')
				extendeduser.user.groups.add(program_manager)
			elif check_user_groups(extendeduser.user,'Program Manager'):
				program_manager = extendeduser.user.groups.get(name='Program Manager')
				extendeduser.user.groups.remove(program_manager)

			if len(newpassword) > 0:
				extendeduser.user.set_password(newpassword)

			"""
			" End of saving the user information.
			"""
		else:
			try:
				existingusernotification = publicid
			except:
				existingusernotification = True

		"""
		" End check of existing users.
		"""
	"""
	" Filter the topics.
	"""
	#Check to see if the user has filtered 
	#	the topics.
	if request.method == 'GET' and 'search' in request.GET:
		#Get the user defined search filter
		search = request.GET['search']
		#Filter the topic list based on the users filtered information.
		users_list = ExtendedUser.objects.filter(
			~Q(user__is_superuser=True) & 
				(Q(user__username__icontains=search) | 
				 Q(user__first_name__icontains=search) |
				 Q(user__last_name__icontains=search) 
			 	)
			)
	else:
		#Load the topic objects into a list
		users_list = ExtendedUser.objects.exclude(user__is_superuser=True)


	users_object = paginate(request,users_list)

	"""
	" End filter of the topics.
	"""

	#Get a user 
	def returnfunc(request,u):

		if request.POST and 'edit_user' in request.POST and request.POST['edit_user'] == u.publicid:
			return request.POST
		else:
			return {
				'first_name':u.user.first_name,
				'last_name':u.user.last_name,
				'email':u.user.email,
				'phonenumber':u.phonenumber,
				'username':u.user.username,
				'is_active':u.user.is_active,
				'is_program_manager' : check_user_groups(u.user,'Program Manager'),
			}

	users = [{
		'publicid':u.publicid,
		'extendeduser':u,
		'user':u.user,
		'user_form':form_modal(request,
													'edit_user',
													UserManagementForm(returnfunc(request, u)).as_table(),
													modal_title = 'Edit %s'% u.user.get_full_name(),
													modal_id = 'edit_user_%s'% u.publicid,
													table_class = 'edit_user_form ',
													formname_value=u.publicid),
		'is_program_manager' : check_user_groups(u.user,'Program Manager'),
	}
	for u in users_object
	]

	#Create a user modal
	add_user_form = form_modal(request,
														'add_user',
														UserManagementForm(request.POST if 'edit_user' in request.POST else None).as_table(),
														modal_title='Add a User',
														modal_id='add_user')

	#Pass in the users.
	context['users'] = users
	context['paginated_users'] = users_object
	context['add_user_form'] = add_user_form
	context['existingusernotification'] = existingusernotification
	context['queries'] = users_object.qstring

	return render(request,
		'user_management/viewusers.html',
		context)
def viewtopic(request):
	#If there is no topic.
	notopic = True
	#If true a Toastr notification for comments will be shown.
	commentnotification = False
	#If a topic has been approved.
	releasednotification = False
	#If a document has been updated.
	updatednotification = False
	#If a document has been added.
	addednotification = False
	#If a document has been deleted.
	deleteddocumentdnotification = False
	#Add a variable to check if the user owns the topic
	user_is_owner = False
	#Get the public id of the topic.
	if 'publicid' in request.GET:
		#This is the publicid.
		publicid = request.GET['publicid']

		#The directory of the location of the documents
		topicdirectory = "%s/%s"% (settings.UPLOADED_TOPIC_DIR, publicid)

		try:
			#Check for a topic.
			topic_object = Topic.objects.get(publicid=publicid,deleted=False)
			notopic = False
		except ObjectDoesNotExist:
			#If the topic does not exist.
			notopic = True

	#If there is no topic.
	if notopic:
		#Redirect if the topic is not found
		#		to the list of topics.
		return redirect('/viewtopics/')


	#Check for POST data
	if request.method == 'POST':

		"""
		" These can only be accessed if a user is the owner or a Supervisor
		"""			
		if topic_object.user == request.user or request.user.groups.filter(Q(name='Supervisor')).count() != 0:

			#Update the description of the topic.
			if 'update_topic_description' in request.POST and topic_object.publicid == request.POST['update_topic_description']:
				#Update the description.
				topic_object.description = request.POST['description']
				#Save the topic_object.
				topic_object.save()
			
			#Ready the topic for review
			topic_ready_for_review_index = 'topic_ready_for_review_id'

			#Check if the topic is ready for review.
			if (
				topic_ready_for_review_index in request.POST and
				request.POST[topic_ready_for_review_index] == topic_object.publicid
				):

				#Update the topic presentation length.
				if 'topic_presentationlength' in request.POST:
					#Set the topic ready for review.
					readyforreview = True
					#Set the presentation length to the length entered.
					presentationlength = int(request.POST['topic_presentationlength'])
					#Add a datetime for the time it was set.
					topic_object.datesetforreview = datetime.now()
				else:
					#The topic is not ready for review.
					readyforreview = False
					#Update the presentationlength.
					presentationlength = 15

				#Set the fields in the database.
				topic_object.readyforreview = readyforreview
				topic_object.presentationlength = presentationlength

				#Save the topic object.
				topic_object.save()

				#Reset the meeting duration.
				if topic_object.meeting:
					#This is the topic_meeting.
					topic_meeting = topic_object.meeting;
					#Set the duration to 0.
					duration = 0
					#Loop through each of the topic in the meeting.
					for t in topic_meeting.topics.all():
						#Increment the duration.
						duration += t.presentationlength

					#Set the meeting duration.
					topic_meeting.duration = duration
					#Save the topic meeting.
					topic_meeting.save()

			#We deleted the topic.
			if 'deleted_topicid' in request.POST and request.POST['deleted_topicid'] == topic_object.publicid:
				#Delete the topic object
				topic_object.deleted = True
				topic_object.save()

				#Move the files to a 'deleted' directory.
				delete_topic(topic_object)

				#Redirect to the list of topics, there is a hash
				#		for a notification.
				return redirect('/viewtopics/?deleted=%s' % topic_object.name)

			#We approved the document.
			if 'released_topicid' in request.POST and request.POST['released_topicid'] == topic_object.publicid:
				#In the topic_object set the supervisor_released true.
				topic_object.supervisor_released = True
				#Save the topic.
				topic_object.save()

				directory = create_directory(topic_object,settings.APPROVED_TOPIC_DIR)

				#Loop throught the document and copy
				#		them to the right directory.
				for document in topic_object.documents.all():

					#Get the approved file.
					approved_file = "%s/%s" % (directory,document.fileName)

					#Make a copy of the file.
					copyfile(document.location, approved_file)

			#We have an updated document.
			if 'updated_documentid' in request.POST:

				#Get the updated document
				updated_document = topic_object.documents.filter(publicid=request.POST['updated_documentid'])
				#Get the document
				if updated_document.exists():

					#Get the old file and delete.
					old_file_path = updated_document.values()[0]['location']

					try:
						#Delete the old file.
						os.remove(old_file_path)
					except OSError:
						print "deleted file not found, but it doesn't really matter"

					#Get the uploaded file.
					f = request.FILES['file']

					#Single file upload
					#Get the file
					name = f.name
					fileName = "%s-%s" % (uuid4(),name)
					#The uploaded_topic_dir is in PDTtool.settings.
					location = '%s/%s' % (topicdirectory, fileName)
					#Get the file size.
					fileSize = f.size
					#Get the updated document
					updated_document.update(location=location,name=name,fileName=fileName,size=fileSize)
	 				#handle the uploaded file.
					handle_uploaded_file(f,location)

					#Updated notification
					updatednotification = True

			#We have an updated document.
			if 'deleted_documentid' in request.POST:

				#Get the updated document
				deleted_document = topic_object.documents.filter(publicid=request.POST['deleted_documentid'])
				#Get the document
				if deleted_document.exists():

					#Get the old file and delete.
					file_path = deleted_document.values()[0]['location']

					try:
						#Delete the file
						os.remove(file_path)
					except OSError:
						print "deleted file not found, but it doesn't really matter"

					#Remove the m2m relationship.
					topic_object.documents.remove(deleted_document.values()[0]['id'])
					#Delete the document.
					deleted_document.delete()
					#Delete the document notification.
					deleteddocumentdnotification = True


			#We have added a document.
			if 'add_document' in request.POST:

				#Get the uploaded file.
				f = request.FILES['file']

				#Single file upload
				#Get the file
				name = f.name
				fileName = "%s-%s" % (uuid4(),name)

				#The uploaded_topic_dir is in PDTtool.settings.
				location = '%s/%s' % (topicdirectory, fileName)
				fileSize = f.size
				#This is the newdocument.
				newdocument = Document(topic=topic_object,location=location,name=name,fileName=fileName,size=fileSize)
				newdocument.save()
				#Add the document to the topic.
				topic_object.documents.add(newdocument)
				#Upload the file
				handle_uploaded_file(f,location)
				#Updated notification
				addednotification = True

		"""
		" The following adds comments to the specified object
		"""
		#Add a comment to the topic
		if 'topicid' in request.POST and request.POST['topicid'] == topic_object.publicid:
			#This is the content of a topic
			content = request.POST['content']
			#Create a new comment.
			newcomment = Comment(user=request.user,content=content)
			#Save the comment.
			newcomment.save()
			#Add the comment to the topic.
			topic_object.comments.add(newcomment)
			#Create a variable to notify the user of success.
			commentnotification = True

		#Assumes the document exists.
		#Add a comment to the document
		if 'documentid' in request.POST:
			#This is the publicid of the commented document.
			documentid = request.POST['documentid']
			#Get the document.
			document_object = Document.objects.get(publicid=documentid)
			#Get the content of the comment.
			content = request.POST['content']
			#Create a new comment object.
			newcomment = Comment(user=request.user,content=content)
			#Save the comment.
			newcomment.save()
			#Add the comment to the document.
			document_object.comments.add(newcomment)
			#Create a variable to notify the user of success.
			commentnotification = True

		#Assumes the comment exists.
		#Add a reply to the comment.
		if 'commentid' in request.POST:
			#Get the publicid of the comment being replied to..
			commentid = request.POST['commentid']
			#Get the comment being replied to by publicid.
			comment_object = Comment.objects.get(publicid=commentid)
			#Get the content of the reply.
			content = request.POST['content']
			#Create a new comment object.
			newcomment = Comment(user=request.user,content=content)
			newcomment.save()
			#Add the comment to the collection of comments.
			comment_object.comments.add(newcomment)
			#Add a variable to notify the user of success.
			commentnotification = True

		"""
		" End the logic to add comments.
		"""

	#Get the topic
	topic = {
		#Store the topic_object
		'topic_object':topic_object,
		#Get the comments
		'comments':[
			#Get the comments for the topic
			{'html':str(recursive_comments(request, comment.publicid))}
			#Run a loop on the comments.
			for comment in topic_object.comments.all() 
		],
		#Get the comment form for the topic.
		'comment_form':comment_form(request,'topic',topic_object.publicid),
		#Add this document.
	  'add_document':form_modal(request,
														'add_document',
														upload_document_form().as_table(),
														'Add a document to the topic',
														multipart=True,
														modal_id="add_document",
														formname_value='add a document',
														action=request.get_full_path(),
														submit_text='upload'
														),
	}

	#Get all of the documents with their comments. 
	documents = [
		#Get all of the documents.
		{'document_object':document,
			#Get the form for updating a document, this just replaces 
			#		the file with a new one in the topics collection of documents.
			#	There is no revision control.
		 'update_document_form':form_modal(request,
		 																	#The name of the variable to identify
		 																	#		an update document variable.
																			'updated_documentid',
																			#Get the form html as a table.
																			upload_document_form().as_table(),
																			#This is the title of the bootstrap modal.
																			'Upload a Revised Document',
																			#Create a text/multipart type for the form
																			multipart=True,
																			#Add a special identifier to the form.
																			modal_id="update_document_"+document.publicid,
																			#Add a custom value to the form name, it is
																			#		used to identify the topic.
																			formname_value=document.publicid,
																			#Create a special action for the form to submit to.
																			action=request.get_full_path()
																			),
		 #Create a modal to check if the user wants to delete the 
		 #		document from a collection of topics.
		 'deleted_document_form':form_modal(request,
		 																	#This is the name of the form.
																			'deleted_documentid',
																			#This is the message for the document name.
																			"You will delete '%s'"%document.name,
																			#This is the content of the modal.
																			'Are you sure?',
																			#Add a special identifier to the form.
																			modal_id="deleted_document_"+document.publicid,
																			#Add a custom value to the form name, it is 
																			#			used to identify the topic.
																			formname_value=document.publicid,
																			#Specify a custom request string.
																			action=request.get_full_path(),
																			#Custom submit button text.
																			submit_text="Yes",
																			#A custom button class.
																			submit_button_class="btn-danger",
																			#Custom cancel button text.
																			close_button_text='Cancel',
																			#Custom close button classes.
																			close_button_class='pull-right margin-left-10'
																			),
		 #Get the comments for the topic.
		 'comments':[
		 	#Get the comments for each document.
			{'html':str(recursive_comments(request, comment.publicid))}
			#Run a loop on the comments.
			for comment in document.comments.all()
		],
		#Add a comment to the form.
		'comment_form':comment_form(request,'document',document.publicid),
		}
		#Run a loop on the documents
		for document in topic_object.documents.all()
	]

	#Check to see if the user owns the topic
	if topic_object.user.id == request.user.id:
		#Add a user to the owner of the form.
		user_is_owner = True

	#Load in some context variables.
	context= {
		#The textual title of the page.
		'title':'View Topic',
		#Add a topic to the template.
		'topic': topic,
		#Add documents to the template.
		'documents': documents,
		#A flag for whether or not a success notification
		#		for the comments should go up.
		'commentnotification': commentnotification,
		#A flag for whether or not a success notification
		#		for the release of topic should go up.
		'releasednotification' : releasednotification,
		#A flag for whether or not a success notification
		#		for the updating of a document should go up.
		'updatednotification' : updatednotification,
		#A flag for whether or not an notification for
		#		the updating of a document should go up.
		'deleteddocumentdnotification' : deleteddocumentdnotification,
		#A flag for whether or not a success notification
		#		for the adding of a document to the
		#		collection of topics.
		'addednotification' : addednotification,
		#A flag to indicate if the currently logged  in user
		#		owns the document.
		'user_is_owner' : user_is_owner,
	}

	#Render the template and return it for the user.
	return render(request,
		'topic_management/viewtopic.html',
		context)