def diff_submit(request): """ Handle submitting the results of an svn diff to the mission 1. Creates a data dictionary 2. If POST method try to commit the diff 3. Else GET method returns the view to be displayed """ # Initialize the data dictionary data = { 'svn_diff_form': forms.DiffForm(request.user.username), 'svn_diff_error_message': '' } if request.method == 'POST': # mkdtemp() returns the absolute path of the directory temp_svn_directory = tempfile.mkdtemp() form = forms.DiffForm(request.user.username, temp_svn_directory, request.POST) if form.is_valid(): form.commit_diff() view_helpers.set_mission_completed(request.user.get_profile(), 'svn_diff') return HttpResponseRedirect(reverse('svn_diff')) data['svn_diff_form'] = form shutil.rmtree(temp_svn_directory) # If we get here, just hack up the request object to pretend it is a GET # so the dispatch system in the class-based view can use the GET handler. request.method = 'GET' return Diff.as_view()(request, extra_context_data=data)
def checkout_submit(request): # Initialize data array and some default values. data = {} data['svn_checkout_form'] = forms.CheckoutForm(request.user.username) data['svn_checkout_error_message'] = '' if request.method == 'POST': form = forms.CheckoutForm(request.user.username, request.POST) if form.is_valid(): view_helpers.set_mission_completed(request.user.get_profile(), 'svn_checkout') return HttpResponseRedirect(reverse('svn_checkout')) data['svn_checkout_form'] = form # If we get here, just hack up the request object to pretend it is a GET # so the dispatch system in the class-based view can use the GET handler. request.method = 'GET' return Checkout.as_view()(request, extra_context_data=data)
def diff_submit(request): # Initialize data array and some default values. data = {} data['svn_diff_form'] = forms.DiffForm(request.user.username) data['svn_diff_error_message'] = '' if request.method == 'POST': wcdir = tempfile.mkdtemp() try: form = forms.DiffForm(request.user.username, wcdir, request.POST) if form.is_valid(): form.commit_diff() view_helpers.set_mission_completed(request.user.get_profile(), 'svn_diff') return HttpResponseRedirect(reverse('svn_diff')) finally: shutil.rmtree(wcdir) data['svn_diff_form'] = form request.method = 'GET' return Diff.as_view()(request, extra_context_data=data)
def diff_submit(request): """ Handle submitting the results of an svn diff to the mission """ data = {} data['svn_diff_form'] = forms.DiffForm(request.user.username) data['svn_diff_error_message'] = '' if request.method == 'POST': temp_svn_directory = tempfile.mkdtemp() form = forms.DiffForm(request.user.username, temp_svn_directory, request.POST) if form.is_valid(): try: form.commit_diff() view_helpers.set_mission_completed(request.user.get_profile(), 'svn_diff') return HttpResponseRedirect(reverse('svn_diff')) finally: shutil.rmtree(temp_svn_directory) shutil.rmtree(temp_svn_directory) data['svn_diff_form'] = form # If we get here, just hack up the request object to pretend it is a GET # so the dispatch system in the class-based view can use the GET handler. request.method = 'GET' return Diff.as_view()(request, extra_context_data=data)
def setUp(self): # We fully mock the svnlook output, so the hook doesn't try to inspect # a repository at all during the tests. view_helpers.set_mission_completed( Person.objects.get(user__username='******'), 'svn_diff')