Beispiel #1
0
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)
Beispiel #2
0
 def get_context_data(self, *args, **kwargs):
     data = super(Diff, self).get_context_data(*args, **kwargs)
     if kwargs.has_key('extra_context_data'):
         data.update(kwargs['extra_context_data'])
     else:
         data['svn_diff_form'] = forms.DiffForm()
     return data
Beispiel #3
0
def diff(request, passed_data=None):
    state = SvnMissionPageState(request, passed_data)
    state.this_mission_page_short_name = 'Diffing your changes'
    state.mission_step_prerequisite = 'svn_checkout'
    data = state.as_dict_for_template_context()
    data['svn_diff_form'] = forms.DiffForm()
    return (request, 'missions/svn/diff.html', data)
Beispiel #4
0
def diff_submit(request):
    # Initialize data array and some default values.
    data = {}
    data['svn_diff_form'] = forms.DiffForm()
    data['svn_diff_error_message'] = ''
    if request.method == 'POST':
        form = forms.DiffForm(request.POST)
        if form.is_valid():
            try:
                controllers.SvnDiffMission.validate_diff_and_commit_if_ok(
                    request.user.username, form.cleaned_data['diff'])
                controllers.set_mission_completed(request.user.get_profile(),
                                                  'svn_diff')
                return HttpResponseRedirect(reverse(diff))
            except controllers.IncorrectPatch, e:
                data['svn_diff_error_message'] = str(e)
        data['svn_diff_form'] = form
Beispiel #5
0
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)
Beispiel #6
0
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)