def patch(request, patch_id): context = PatchworkRequestContext(request) patch = get_object_or_404(Patch, id=patch_id) context.project = patch.project editable = patch.is_editable(request.user) form = None createbundleform = None if editable: form = PatchForm(instance=patch) if request.user.is_authenticated(): createbundleform = CreateBundleForm() if request.method == 'POST': action = request.POST.get('action', None) if action: action = action.lower() if action == 'createbundle': bundle = Bundle(owner=request.user, project=patch.project) createbundleform = CreateBundleForm(instance=bundle, data=request.POST) if createbundleform.is_valid(): createbundleform.save() bundle.append_patch(patch) bundle.save() createbundleform = CreateBundleForm() context.add_message('Bundle %s created' % bundle.name) elif action == 'addtobundle': bundle = get_object_or_404( Bundle, id=request.POST.get('bundle_id')) try: bundle.append_patch(patch) bundle.save() context.add_message('Patch added to bundle "%s"' % bundle.name) except Exception as ex: context.add_message("Couldn't add patch '%s' to bundle %s: %s" % (patch.name, bundle.name, ex.message)) # all other actions require edit privs elif not editable: return HttpResponseForbidden() elif action is None: form = PatchForm(data=request.POST, instance=patch) if form.is_valid(): form.save() context.add_message('Patch updated') context['patch'] = patch context['patchform'] = form context['createbundleform'] = createbundleform context['project'] = patch.project context['test_results'] = TestResult.objects \ .filter(revision=None, patch=patch) \ .order_by('test__name').select_related('test') return render_to_response('patchwork/patch.html', context)
def patch(request, patch_id): context = PatchworkRequestContext(request) patch = get_object_or_404(Patch, id=patch_id) context.project = patch.project editable = patch.is_editable(request.user) form = None createbundleform = None if editable: form = PatchForm(instance = patch) if request.user.is_authenticated(): createbundleform = CreateBundleForm() if request.method == 'POST': action = request.POST.get('action', None) if action: action = action.lower() if action == 'createbundle': bundle = Bundle(owner = request.user, project = patch.project) createbundleform = CreateBundleForm(instance = bundle, data = request.POST) if createbundleform.is_valid(): createbundleform.save() bundle.append_patch(patch) bundle.save() createbundleform = CreateBundleForm() context.add_message('Bundle %s created' % bundle.name) elif action == 'addtobundle': bundle = get_object_or_404(Bundle, id = \ request.POST.get('bundle_id')) try: bundle.append_patch(patch) bundle.save() context.add_message('Patch added to bundle "%s"' % bundle.name) except Exception, ex: context.add_message("Couldn't add patch '%s' to bundle %s: %s" \ % (patch.name, bundle.name, ex.message)) # all other actions require edit privs elif not editable: return HttpResponseForbidden() elif action is None: form = PatchForm(data = request.POST, instance = patch) if form.is_valid(): form.save() context.add_message('Patch updated')
def patch(request, patch_id): context = PatchworkRequestContext(request) patch = get_object_or_404(Patch, id=patch_id) context.project = patch.project editable = patch.is_editable(request.user) form = None createbundleform = None if editable: form = PatchForm(instance=patch) if request.user.is_authenticated(): createbundleform = CreateBundleForm() if request.method == 'POST': action = request.POST.get('action', None) if action: action = action.lower() if action == 'createbundle': bundle = Bundle(owner=request.user, project=patch.project) createbundleform = CreateBundleForm(instance=bundle, data=request.POST) if createbundleform.is_valid(): createbundleform.save() bundle.append_patch(patch) bundle.save() createbundleform = CreateBundleForm() context.add_message('Bundle %s created' % bundle.name) elif action == 'addtobundle': bundle = get_object_or_404(Bundle, id = \ request.POST.get('bundle_id')) try: bundle.append_patch(patch) bundle.save() context.add_message('Patch added to bundle "%s"' % bundle.name) except Exception, ex: context.add_message("Couldn't add patch '%s' to bundle %s: %s" \ % (patch.name, bundle.name, ex.message)) # all other actions require edit privs elif not editable: return HttpResponseForbidden() elif action is None: form = PatchForm(data=request.POST, instance=patch) if form.is_valid(): form.save() context.add_message('Patch updated')
def post(self, request, *args, **kwargs): init_data = request.POST patches=json.loads(init_data.get('patches')) series =get_object_or_404(Series, pk=kwargs['series']) revisions = get_list_or_404(SeriesRevision, series=series) context = PatchworkRequestContext(request) context.project = series.project form = None createbundleform = None for revision in revisions: revision.patch_list = revision.ordered_patches().\ select_related('state', 'submitter') revision.test_results = TestResult.objects \ .filter(revision=revision, patch=None) \ .order_by('test__name').select_related('test') if request.user.is_authenticated(): createbundleform = CreateBundleForm() if request.method == 'POST': action = request.POST.get('action', None) if action: action = action.lower() if action == 'createbundle': bundle = Bundle(owner=request.user, project=series.project) createbundleform = CreateBundleForm(instance=bundle, data=request.POST) if createbundleform.is_valid(): createbundleform.save() elif action == 'addtobundle': bundle = get_object_or_404( Bundle, id=request.POST.get('bundle_id')) for pa_id in patches: patch = get_object_or_404(Patch, id=pa_id) editable = patch.is_editable(request.user) if editable: form = PatchForm(instance=patch) if action == 'createbundle': if createbundleform.is_valid(): bundle.append_patch(patch) bundle.save() elif action == 'addtobundle': try: bundle.append_patch(patch) bundle.save() context.add_message('Patch %s added to bundle "%s"' % (patch.pk, bundle.name)) except Exception as ex: context.add_message('Couldn\'t add patch %s to bundle\ "%s": %s' % (patch.pk, bundle.name, ex.message)) # all other actions require edit privs elif not editable: return HttpResponseForbidden() elif action is None: form = PatchForm(data=request.POST, instance=patch) if form.is_valid(): form.save() context.add_message('Patch ID: %s updated' % patch.pk) if action == 'createbundle': createbundleform.save() createbundleform = CreateBundleForm() context.add_message('Bundle %s created' % bundle.name) context['series'] = series context['patchform'] = form context['createbundleform'] = createbundleform context['project'] = series.project context['revisions'] = revisions context['test_results'] = TestResult.objects \ .filter(revision=None, patch=patch) \ .order_by('test__name').select_related('test') return render_to_response('patchwork/series.html', context)
def post(self, request, *args, **kwargs): init_data = request.POST patches = json.loads(init_data.get('patches')) series = get_object_or_404(Series, pk=kwargs['series']) revisions = get_list_or_404(SeriesRevision, series=series) context = PatchworkRequestContext(request) context.project = series.project form = None createbundleform = None for revision in revisions: revision.patch_list = revision.ordered_patches().\ select_related('state', 'submitter') revision.test_results = TestResult.objects \ .filter(revision=revision, patch=None) \ .order_by('test__name').select_related('test') if request.user.is_authenticated(): createbundleform = CreateBundleForm() if request.method == 'POST': action = request.POST.get('action', None) if action: action = action.lower() if action == 'createbundle': bundle = Bundle(owner=request.user, project=series.project) createbundleform = CreateBundleForm(instance=bundle, data=request.POST) if createbundleform.is_valid(): createbundleform.save() elif action == 'addtobundle': bundle = get_object_or_404(Bundle, id=request.POST.get('bundle_id')) for pa_id in patches: patch = get_object_or_404(Patch, id=pa_id) editable = patch.is_editable(request.user) if editable: form = PatchForm(instance=patch) if action == 'createbundle': if createbundleform.is_valid(): bundle.append_patch(patch) bundle.save() elif action == 'addtobundle': try: bundle.append_patch(patch) bundle.save() context.add_message('Patch %s added to bundle "%s"' % (patch.pk, bundle.name)) except Exception as ex: context.add_message('Couldn\'t add patch %s to bundle\ "%s": %s' % (patch.pk, bundle.name, ex.message)) # all other actions require edit privs elif not editable: return HttpResponseForbidden() elif action is None: form = PatchForm(data=request.POST, instance=patch) if form.is_valid(): form.save() context.add_message('Patch ID: %s updated' % patch.pk) if action == 'createbundle': createbundleform.save() createbundleform = CreateBundleForm() context.add_message('Bundle %s created' % bundle.name) context['series'] = series context['patchform'] = form context['createbundleform'] = createbundleform context['project'] = series.project context['revisions'] = revisions context['test_results'] = TestResult.objects \ .filter(revision=None, patch=patch) \ .order_by('test__name').select_related('test') return render_to_response('patchwork/series.html', context)