Пример #1
0
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)
Пример #2
0
  def test_viewtopic(self):
    
    url = '/viewtopic/'
    redirect_url = '/login/?next=/viewtopic/'
    template = 'topic_management/viewtopic.html'

    #Check the redirect when a user is not logged in.
    resp = self.client.get(url)
    self.checkRedirects(resp, redirect_url)

    del resp

    #Check the redirect to viewing topics when there 
    #   we go to a topic that doesn't exist.
    C = Client()
    C.login(username='******',password='******')
    resp = C.get(url)
    self.checkRedirects(resp,'/viewtopics/')
    #self.checkTemplateUsed(resp, template)

    del resp

    #Logout the user.
    C.logout()

   #self.create_topics(extuser=ExtendedUser.objects.get(user__username='******'))

    #Get a topic to test with
    topic = Topic.objects.get(name='Topic1')
    topic_publicid = topic.publicid
    document = topic.documents.get(name__icontains='Document1')
    document_publicid = document.publicid
    document_text = 'A Document Name XCVF'

    #Check the mytopics variable is working.
    C = Client()

    comment_content = 'COMMENT TEXT'

    #Create postData for the url.
    postData = {
      'topicid':topic_publicid,
      'content':comment_content
    }
    #Get the url for the topic.
    topic_url = "%s?publicid=%s" % (url,topic_publicid)
    
    #We should not be able to edit the topic being
    #   logged in as a user that doesn't own it.
    #We should be able to see a comment that we add
    #   with a POST.
    #It should also contain at least on document.
    C.login(username='******',password='******')
    resp = C.post(topic_url,postData)
    #self.checkRedirects(resp,'/viewtopics/')
    self.checkTemplateUsed(resp, template)
    #The string below will only show up if we own the topic
    #   and we are a supervisor.
    self.checkRespNotContains(resp, 'Presentation Length: ')
    #The string below will only exist if the post to the 
    #   database was successful for the topic.
    self.checkRespContains(resp, comment_content)
    #The string below will only exist if the documents 
    #   loaded right.
    self.checkRespContains(resp, document_text)

    del resp

    document_comment_content = 'COMMENT ON DOCUMENT TEXT'

    #Create postData for the url.
    postData = {
      'documentid':document_publicid,
      'content':document_comment_content
    }
    #A comment on the document should post to the page
    #   the page with the content listed above.
    resp = C.post(topic_url,postData)
    #self.checkRedirects(resp,'/viewtopics/')
    self.checkTemplateUsed(resp, template)
    #The string below will only exist if the post to the 
    #   database was successful for the topic.
    self.checkRespContains(resp, document_comment_content)

    del resp

    #Get the comment we just posted and test a comment reply.
    comment = document.comments.get(content=document_comment_content)
    comment_publicid = comment.publicid

    comment_reply_content = 'COMMENT REPLY TEXT'

    #Create postData for the url.
    postData = {
      'commentid':comment_publicid,
      'content':comment_reply_content,
    }
    #A reply to the comment should post to the page below.
    resp = C.post(topic_url,postData)
    #self.checkRedirects(resp,'/viewtopics/')
    self.checkTemplateUsed(resp, template)
    #The string below will only exist if the post to the 
    #   database was successful for the topic.
    self.checkRespContains(resp, comment_reply_content)

    del resp

    C.logout()

    C.login(username='******',password='******')

    topic_description = 'update DESCRIPTION TEST'

    #Create postData for the url.
    postData = {
      'update_topic_description':topic_publicid,
      'description':topic_description,

    }
    #A reply to the comment should post to the page below.
    resp = C.post(topic_url,postData)
    #self.checkRedirects(resp,'/viewtopics/')
    self.checkTemplateUsed(resp, template)
    #The string below will only exist if the post to the 
    #   database was successful for the topic.
    self.checkRespContains(resp, topic_description)

    del resp

    #A reply to the comment should post to the page below.
    resp = C.get(url,{'publicid':'nopublicid'})
    #Check the redirect
    self.checkRedirects(resp,urlstring='/viewtopics/')

    del resp

    presentation_length = '30'
    release_update_value = "%s minute presentation" % presentation_length

    #Create postData for the url.
    postData = {
      'topic_ready_for_review_id':topic_publicid,
      'topic_presentationlength':presentation_length,

    }
    #A test to release the topic to being able to be
    #   dragged into the meeting schedule.
    resp = C.post(topic_url,postData)
    #self.checkRedirects(resp,'/viewtopics/')
    self.checkTemplateUsed(resp, template)
    #The string below will only exist if the post to the 
    #   database was successful for the topic.
    self.checkRespContains(resp, release_update_value)

    del resp

    extuser = self.create_user('user.name')

    #Create a meeting to test the update of a topic release.
    meeting = Meeting(
                      name='Meeting Name',
                      description='Meeting Description',
                      duedate='2013-05-05',
                      startdate='2013-05-05',
                      starttime='13:00:00',
                      user=extuser.user,
                      maxscheduleitems=8,
                      duration=0
                      )
    meeting.save()
    topic.meeting = meeting
    meeting.topics.add(topic)
    topic.save()

    #Create postData for the url.
    postData = {
      'topic_ready_for_review_id':topic_publicid,

    }
    #A test to unrelease the topic.
    resp = C.post(topic_url,postData)
    #self.checkRedirects(resp,'/viewtopics/')
    self.checkTemplateUsed(resp, template)
    #The string below will only exist if the post to the 
    #   database was successful for the topic.
    self.checkRespNotContains(resp, release_update_value)

    del resp

    #Create postData for the url.
    postData = {
      'deleted_documentid':document_publicid,
    }
    #A test to unrelease the topic.
    resp = C.post(topic_url,postData)
    #self.checkRedirects(resp,'/viewtopics/')
    self.checkTemplateUsed(resp, template)
    #The string below will only exist if the post to the 
    #   database was successful for the topic.
    self.checkRespNotContains(resp, 'Document1 %s' % document_text)

    del resp

    #Upload a new document.
    newtopic = self.add_topic_form(C)
    newtopic_publicid = newtopic.publicid
    newdocument = newtopic.documents.all()[0]
    newdocument_publicid = newdocument.publicid

    newtopic_url = "/viewtopic/?publicid=%s" % newtopic_publicid

    #Test the update of a document
    file = "%s/www/css/style.css" % settings.BASE_DIR
    with open(file) as fp:

      #Create postData for the url.
      postData = {
        'updated_documentid':newdocument_publicid,
        'file':fp,
      }
      resp = C.post(newtopic_url,postData)
      #self.checkRedirects(resp,'/viewtopics/')
      self.checkTemplateUsed(resp, template)
      #The string below will only exist if the post to the 
      #   database was successful for the topic.
      self.checkRespContains(resp, 'style.css')

      del resp


    ###
    # Test the download.
    ###

    downloaddocument = newtopic.documents.all()[0]

    document_filename = downloaddocument.fileName

    download_url = '/download/%s/%s' % (newtopic_publicid,document_filename)

    resp = C.get(download_url)

    self.assertIn(document_filename, resp['Content-Disposition'])

    del resp

    #Test the adding of a document.
    file = "%s/www/js/jquery.min.js" % settings.BASE_DIR
    with open(file) as fp:

      #Create postData for the url.
      postData = {
        'add_document':'1',
        'file':fp,
      }
      resp = C.post(newtopic_url,postData)
      #self.checkRedirects(resp,'/viewtopics/')
      self.checkTemplateUsed(resp, template)
      #The string below will only exist if the post to the 
      #   database was successful for the topic.
      self.checkRespContains(resp, 'jquery.min.js')

      del resp

    #Logout the user.
    C.logout()

    #Create a supervisor
    self.create_user(username='******',groups=('Supervisor','Program Manager',))

    #Login the supervisor
    C.login(username='******',password='******')

    #Create postData for the url.
    postData = {
      'released_topicid':newtopic_publicid,
    }
    #A test to aprove the topic.
    resp = C.post(newtopic_url,postData)
    #self.checkRedirects(resp,'/viewtopics/')
    self.checkTemplateUsed(resp, template)
    self.assertTrue(os.path.exists("%s/%s" % (settings.APPROVED_TOPIC_DIR,newtopic_publicid)))

    del resp


    #Upload a new document.
    newtopic2 = self.add_topic_form(C,description='Testing')
    newtopic2_publicid = newtopic2.publicid

    newtopic2_url = "/viewtopic/?publicid=%s" % newtopic2_publicid

    #Create postData for the url. 
    postData = {
      'deleted_topicid':newtopic2_publicid,
    }

    #A test to aprove the topic.
    resp = C.post(newtopic2_url,postData)

    #self.checkRedirects(resp,'/viewtopics/')
    self.assertIn('viewtopics/?deleted',resp['Location'])
    self.assertFalse(os.path.exists("%s/%s" % (settings.UPLOADED_TOPIC_DIR,newtopic2_publicid)))
    self.assertTrue(os.path.exists("%s/%s" % (settings.DELETED_TOPIC_DIR,newtopic2_publicid)))

    del resp

    #Logout the user.
    C.logout()