Exemple #1
0
 def testSingleBundle(self):
     defaults.project.save()
     bundle = Bundle(owner=self.user, project=defaults.project)
     bundle.save()
     response = self.client.get('/user/bundles/')
     self.assertEqual(response.status_code, 200)
     self.assertEqual(len(find_in_context(response.context, 'bundles')), 1)
Exemple #2
0
class BundleTestBase(TestCase):
    fixtures = ['default_states', 'default_events']
    def setUp(self, patch_count=3):
        patch_names = ['testpatch%d' % (i) for i in range(1, patch_count+1)]
        self.user = create_user()
        self.client.login(username = self.user.username,
                password = self.user.username)
        defaults.project.save()
        self.bundle = Bundle(owner = self.user, project = defaults.project,
                name = 'testbundle')
        self.bundle.save()
        self.patches = []

        for patch_name in patch_names:
            patch = Patch(project = defaults.project,
                               msgid = patch_name, name = patch_name,
                               submitter = Person.objects.get(user = self.user),
                               content = '')
            patch.save()
            self.patches.append(patch)

    def tearDown(self):
        for patch in self.patches:
            patch.delete()
        self.bundle.delete()
        self.user.delete()
Exemple #3
0
 def testSingleBundle(self):
     defaults.project.save()
     bundle = Bundle(owner=self.user, project=defaults.project)
     bundle.save()
     response = self.client.get("/user/bundles/")
     self.failUnlessEqual(response.status_code, 200)
     self.failUnlessEqual(len(find_in_context(response.context, "bundles")), 1)
Exemple #4
0
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)
Exemple #5
0
class BundleTestBase(TestCase):
    def setUp(self, patch_count=3):
        patch_names = ["testpatch%d" % (i) for i in range(1, patch_count + 1)]
        self.user = create_user()
        self.client.login(username=self.user.username, password=self.user.username)
        defaults.project.save()
        self.bundle = Bundle(owner=self.user, project=defaults.project, name="testbundle")
        self.bundle.save()
        self.patches = []

        for patch_name in patch_names:
            patch = Patch(
                project=defaults.project,
                msgid=patch_name,
                name=patch_name,
                submitter=Person.objects.get(user=self.user),
                content="",
            )
            patch.save()
            self.patches.append(patch)

    def tearDown(self):
        for patch in self.patches:
            patch.delete()
        self.bundle.delete()
        self.user.delete()
Exemple #6
0
 def testSingleBundle(self):
     defaults.project.save()
     bundle = Bundle(owner=self.user, project=defaults.project)
     bundle.save()
     response = self.client.get('/user/bundles/')
     self.assertEqual(response.status_code, 200)
     self.assertEqual(
         len(find_in_context(response.context, 'bundles')), 1)
Exemple #7
0
    def testUserProfileBundles(self):
        project = defaults.project
        project.save()

        bundle = Bundle(project=project, name='test-1', owner=self.user.user)
        bundle.save()

        response = self.client.get('/user/')

        self.assertContains(response, 'You have the following bundle')
        self.assertContains(response, bundle.get_absolute_url())
Exemple #8
0
    def testUserProfileBundles(self):
        project = defaults.project
        project.save()

        bundle = Bundle(project = project, name = 'test-1',
                        owner = self.user.user)
        bundle.save()

        response = self.client.get('/user/')

        self.assertContains(response, 'You have the following bundle')
        self.assertContains(response, bundle.get_absolute_url())
Exemple #9
0
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')
Exemple #10
0
def create_bundle(**kwargs):
    """Create 'Bundle' object."""
    num = Bundle.objects.count()

    values = {
        'owner': create_user(),
        'project': create_project(),
        'name': 'test_bundle_%d' % num,
    }
    values.update(kwargs)

    bundle = Bundle(**values)
    bundle.save()

    return bundle
Exemple #11
0
def set_bundle(user, project, action, data, patches, context):
    # set up the bundle
    bundle = None
    if 'messages' not in context:
        context['messages'] = []

    if action == 'create':
        bundle_name = data['bundle_name'].strip()
        if '/' in bundle_name:
            return ['Bundle names can\'t contain slashes']

        if not bundle_name:
            return ['No bundle name was specified']

        if Bundle.objects.filter(owner=user, name=bundle_name).count() > 0:
            return ['You already have a bundle called "%s"' % bundle_name]

        bundle = Bundle(owner=user, project=project,
                        name=bundle_name)
        bundle.save()
        context['messages'] += ["Bundle %s created" % bundle.name]

    elif action == 'add':
        bundle = get_object_or_404(Bundle, id=data['bundle_id'])

    elif action == 'remove':
        bundle = get_object_or_404(Bundle, id=data['removed_bundle_id'])

    if not bundle:
        return ['no such bundle']

    for patch in patches:
        if action == 'create' or action == 'add':
            bundlepatch_count = BundlePatch.objects.filter(bundle=bundle,
                                                           patch=patch).count()
            if bundlepatch_count == 0:
                bundle.append_patch(patch)
                context['messages'] += ["Patch '%s' added to bundle %s" %
                        (patch.name, bundle.name)]
            else:
                context['messages'] += ["Patch '%s' already in bundle %s" %
                        (patch.name, bundle.name)]

        elif action == 'remove':
            try:
                bp = BundlePatch.objects.get(bundle=bundle, patch=patch)
                bp.delete()
                context['messages'] += ["Patch '%s' removed from bundle %s\n" %
                        (patch.name, bundle.name)]
            except Exception:
                pass

    bundle.save()

    return []
Exemple #12
0
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')
Exemple #13
0
    def setUp(self, patch_count=3):
        patch_names = ['testpatch%d' % (i) for i in range(1, patch_count+1)]
        self.user = create_user()
        self.client.login(username = self.user.username,
                password = self.user.username)
        defaults.project.save()
        self.bundle = Bundle(owner = self.user, project = defaults.project,
                name = 'testbundle')
        self.bundle.save()
        self.patches = []

        for patch_name in patch_names:
            patch = Patch(project = defaults.project,
                               msgid = patch_name, name = patch_name,
                               submitter = Person.objects.get(user = self.user),
                               content = '')
            patch.save()
            self.patches.append(patch)
Exemple #14
0
 def setUp(self, patch_count=3):
     self.user = create_user()
     self.client.login(username=self.user.username,
                       password=self.user.username)
     defaults.project.save()
     self.bundle = Bundle(owner=self.user, project=defaults.project,
                          name='testbundle')
     self.bundle.save()
     self.patches = create_patches(patch_count)
Exemple #15
0
class BundleTestBase(TestCase):
    fixtures = ['default_states']

    def setUp(self, patch_count=3):
        self.user = create_user()
        self.client.login(username=self.user.username,
                          password=self.user.username)
        defaults.project.save()
        self.bundle = Bundle(owner=self.user, project=defaults.project,
                             name='testbundle')
        self.bundle.save()
        self.patches = create_patches(patch_count)

    def tearDown(self):
        for patch in self.patches:
            patch.delete()
        self.bundle.delete()
        self.user.delete()
Exemple #16
0
def set_bundle(request, project, action, data, patches, context):
    # set up the bundle
    bundle = None
    user = request.user

    if action == 'create':
        bundle_name = data['bundle_name'].strip()
        if '/' in bundle_name:
            return ['Bundle names can\'t contain slashes']

        if not bundle_name:
            return ['No bundle name was specified']

        if Bundle.objects.filter(owner=user, name=bundle_name).count() > 0:
            return ['You already have a bundle called "%s"' % bundle_name]

        bundle = Bundle(owner=user, project=project,
                        name=bundle_name)
        bundle.save()
        messages.success(request, "Bundle %s created" % bundle.name)
    elif action == 'add':
        bundle = get_object_or_404(Bundle, id=data['bundle_id'])
    elif action == 'remove':
        bundle = get_object_or_404(Bundle, id=data['removed_bundle_id'])

    if not bundle:
        return ['no such bundle']

    for patch in patches:
        if action in ['create', 'add']:
            bundlepatch_count = BundlePatch.objects.filter(bundle=bundle,
                                                           patch=patch).count()
            if bundlepatch_count == 0:
                bundle.append_patch(patch)
                messages.success(request, "Patch '%s' added to bundle %s" %
                                 (patch.name, bundle.name))
            else:
                messages.warning(request, "Patch '%s' already in bundle %s" %
                                 (patch.name, bundle.name))
        elif action == 'remove':
            try:
                bp = BundlePatch.objects.get(bundle=bundle, patch=patch)
                bp.delete()
            except BundlePatch.DoesNotExist:
                pass
            else:
                messages.success(
                    request,
                    "Patch '%s' removed from bundle %s\n" % (patch.name,
                                                             bundle.name))

    bundle.save()

    return []
Exemple #17
0
def set_bundle(request, project, action, data, patches, context):
    # set up the bundle
    bundle = None
    user = request.user

    if action == 'create':
        bundle_name = data['bundle_name'].strip()
        if '/' in bundle_name:
            return ['Bundle names can\'t contain slashes']

        if not bundle_name:
            return ['No bundle name was specified']

        if Bundle.objects.filter(owner=user, name=bundle_name).count() > 0:
            return ['You already have a bundle called "%s"' % bundle_name]

        bundle = Bundle(owner=user, project=project,
                        name=bundle_name)
        bundle.save()
        messages.success(request, "Bundle %s created" % bundle.name)
    elif action == 'add':
        bundle = get_object_or_404(Bundle, id=data['bundle_id'])
    elif action == 'remove':
        bundle = get_object_or_404(Bundle, id=data['removed_bundle_id'])

    if not bundle:
        return ['no such bundle']

    for patch in patches:
        if action in ['create', 'add']:
            bundlepatch_count = BundlePatch.objects.filter(bundle=bundle,
                                                           patch=patch).count()
            if bundlepatch_count == 0:
                bundle.append_patch(patch)
                messages.success(request, "Patch '%s' added to bundle %s" %
                                 (patch.name, bundle.name))
            else:
                messages.warning(request, "Patch '%s' already in bundle %s" %
                                 (patch.name, bundle.name))
        elif action == 'remove':
            try:
                bp = BundlePatch.objects.get(bundle=bundle, patch=patch)
                bp.delete()
            except BundlePatch.DoesNotExist:
                pass
            else:
                messages.success(
                    request,
                    "Patch '%s' removed from bundle %s\n" % (patch.name,
                                                             bundle.name))

    bundle.save()

    return []
Exemple #18
0
def set_bundle(user, project, action, data, patches, context):
    # set up the bundle
    bundle = None
    if action == 'create':
        bundle_name = data['bundle_name'].strip()
        if not bundle_name:
            return ['No bundle name was specified']

        if Bundle.objects.filter(owner = user, name = bundle_name).count() > 0:
            return ['You already have a bundle called "%s"' % bundle_name]

        bundle = Bundle(owner = user, project = project,
                name = bundle_name)
        bundle.save()
        context.add_message("Bundle %s created" % bundle.name)

    elif action =='add':
        bundle = get_object_or_404(Bundle, id = data['bundle_id'])

    elif action =='remove':
        bundle = get_object_or_404(Bundle, id = data['removed_bundle_id'])

    if not bundle:
        return ['no such bundle']

    for patch in patches:
        if action == 'create' or action == 'add':
            bundlepatch_count = BundlePatch.objects.filter(bundle = bundle,
                        patch = patch).count()
            if bundlepatch_count == 0:
                bundle.append_patch(patch)
                context.add_message("Patch '%s' added to bundle %s" % \
                        (patch.name, bundle.name))
            else:
                context.add_message("Patch '%s' already in bundle %s" % \
                        (patch.name, bundle.name))

        elif action == 'remove':
            try:
                bp = BundlePatch.objects.get(bundle = bundle, patch = patch)
                bp.delete()
                context.add_message("Patch '%s' removed from bundle %s\n" % \
                        (patch.name, bundle.name))
            except Exception:
                pass

    bundle.save()

    return []
Exemple #19
0
def patch_detail(request, patch_id):
    # redirect to cover letters where necessary
    try:
        patch = get_object_or_404(Patch, id=patch_id)
    except Http404 as exc:
        submissions = Submission.objects.filter(id=patch_id)
        if submissions:
            return HttpResponseRedirect(
                reverse('cover-detail', kwargs={'cover_id': patch_id}))
        raise exc

    editable = patch.is_editable(request.user)
    context = {
        'project': patch.project
    }

    form = None
    createbundleform = None

    if editable:
        form = PatchForm(instance=patch)
    if is_authenticated(request.user):
        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()
                messages.success(request, 'Bundle %s created' % bundle.name)
        elif action == 'addtobundle':
            bundle = get_object_or_404(
                Bundle, id=request.POST.get('bundle_id'))
            if bundle.append_patch(patch):
                messages.success(request,
                                 'Patch "%s" added to bundle "%s"' % (
                                     patch.name, bundle.name))
            else:
                messages.error(request,
                               'Failed to add patch "%s" to bundle "%s": '
                               'patch is already in bundle' % (
                                   patch.name, bundle.name))

        # 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()
                messages.success(request, 'Patch updated')

    if is_authenticated(request.user):
        context['bundles'] = Bundle.objects.filter(owner=request.user)

    context['submission'] = patch
    context['patchform'] = form
    context['createbundleform'] = createbundleform
    context['project'] = patch.project

    return render(request, 'patchwork/submission.html', context)
Exemple #20
0
def patch_detail(request, patch_id):
    # redirect to cover letters where necessary
    try:
        patch = get_object_or_404(Patch, id=patch_id)
    except Http404 as exc:
        submissions = Submission.objects.filter(id=patch_id)
        if submissions:
            return HttpResponseRedirect(
                reverse('cover-detail', kwargs={'cover_id': patch_id}))
        raise exc

    editable = patch.is_editable(request.user)
    context = {'project': patch.project}

    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()
                messages.success(request, 'Bundle %s created' % bundle.name)
        elif action == 'addtobundle':
            bundle = get_object_or_404(Bundle,
                                       id=request.POST.get('bundle_id'))
            if bundle.append_patch(patch):
                messages.success(
                    request, 'Patch "%s" added to bundle "%s"' %
                    (patch.name, bundle.name))
            else:
                messages.error(
                    request, 'Failed to add patch "%s" to bundle "%s": '
                    'patch is already in bundle' % (patch.name, bundle.name))

        # 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()
                messages.success(request, 'Patch updated')

    if request.user.is_authenticated:
        context['bundles'] = request.user.bundles.all()

    comments = patch.comments.all()
    comments = comments.select_related('submitter')
    comments = comments.only('submitter', 'date', 'id', 'content',
                             'submission')

    context['comments'] = comments
    context['checks'] = patch.check_set.all().select_related('user')
    context['submission'] = patch
    context['patchform'] = form
    context['createbundleform'] = createbundleform
    context['project'] = patch.project

    return render(request, 'patchwork/submission.html', context)
Exemple #21
0
def patch_detail(request, project_id, msgid):
    project = get_object_or_404(Project, linkname=project_id)
    db_msgid = ('<%s>' % msgid)

    # redirect to cover letters where necessary
    try:
        patch = Patch.objects.get(project_id=project.id, msgid=db_msgid)
    except Patch.DoesNotExist:
        submissions = Submission.objects.filter(project_id=project.id,
                                                msgid=db_msgid)
        if submissions:
            return HttpResponseRedirect(
                reverse('cover-detail',
                        kwargs={'project_id': project.linkname,
                                'msgid': msgid}))
        raise Http404('Patch does not exist')

    editable = patch.is_editable(request.user)
    context = {
        'project': patch.project
    }

    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=project)
            createbundleform = CreateBundleForm(instance=bundle,
                                                data=request.POST)
            if createbundleform.is_valid():
                createbundleform.save()
                bundle.append_patch(patch)
                bundle.save()
                createbundleform = CreateBundleForm()
                messages.success(request, 'Bundle %s created' % bundle.name)
        elif action == 'addtobundle':
            bundle = get_object_or_404(
                Bundle, id=request.POST.get('bundle_id'))
            if bundle.append_patch(patch):
                messages.success(request,
                                 'Patch "%s" added to bundle "%s"' % (
                                     patch.name, bundle.name))
            else:
                messages.error(request,
                               'Failed to add patch "%s" to bundle "%s": '
                               'patch is already in bundle' % (
                                   patch.name, bundle.name))

        # 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()
                messages.success(request, 'Patch updated')

    if request.user.is_authenticated:
        context['bundles'] = request.user.bundles.all()

    comments = patch.comments.all()
    comments = comments.select_related('submitter')
    comments = comments.only('submitter', 'date', 'id', 'content',
                             'submission')

    if patch.related:
        related_same_project = patch.related.patches.only(
            'name', 'msgid', 'project', 'related')
        # avoid a second trip out to the db for info we already have
        related_different_project = [
            related_patch for related_patch in related_same_project
            if related_patch.project_id != patch.project_id
        ]
    else:
        related_same_project = []
        related_different_project = []

    context['comments'] = comments
    context['checks'] = patch.check_set.all().select_related('user')
    context['submission'] = patch
    context['patchform'] = form
    context['createbundleform'] = createbundleform
    context['project'] = patch.project
    context['related_same_project'] = related_same_project
    context['related_different_project'] = related_different_project

    return render(request, 'patchwork/submission.html', context)
Exemple #22
0
    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)
Exemple #23
0
    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)
Exemple #24
0
def setbundle(request):
    context = PatchworkRequestContext(request)

    bundle = None

    if request.method == 'POST':
        action = request.POST.get('action', None)
        if action is None:
            pass
        elif action == 'create':
            project = get_object_or_404(Project,
                    id = request.POST.get('project'))
            bundle = Bundle(owner = request.user, project = project,
                    name = request.POST['name'])
            bundle.save()
            patch_id = request.POST.get('patch_id', None)
            if patch_id:
                patch = get_object_or_404(Patch, id = patch_id)
                try:
                    bundle.append_patch(patch)
                except Exception:
                    pass
            bundle.save()
        elif action == 'add':
            bundle = get_object_or_404(Bundle,
                    owner = request.user, id = request.POST['id'])
            bundle.save()

            patch_id = request.get('patch_id', None)
            if patch_id:
                patch_ids = patch_id
            else:
                patch_ids = get_patch_ids(request.POST)

            for id in patch_ids:
                try:
                    patch = Patch.objects.get(id = id)
                    bundle.append_patch(patch)
                except:
                    pass

            bundle.save()
        elif action == 'delete':
            try:
                bundle = Bundle.objects.get(owner = request.user,
                        id = request.POST['id'])
                bundle.delete()
            except Exception:
                pass

            bundle = None

    else:
        bundle = get_object_or_404(Bundle, owner = request.user,
                id = request.POST['bundle_id'])

    if 'error' in context:
        pass

    if bundle:
        return HttpResponseRedirect(
                django.core.urlresolvers.reverse(
                    'patchwork.views.bundle.bundle',
                    kwargs = {'bundle_id': bundle.id}
                    )
                )
    else:
        return HttpResponseRedirect(
                django.core.urlresolvers.reverse(
                    'patchwork.views.bundle.list')
                )
Exemple #25
0
def setbundle(request):
    bundle = None

    if request.method == 'POST':
        action = request.POST.get('action', None)
        if action is None:
            pass
        elif action == 'create':
            project = get_object_or_404(Project,
                                        id=request.POST.get('project'))
            bundle = Bundle(owner=request.user,
                            project=project,
                            name=request.POST['name'])
            bundle.save()
            patch_id = request.POST.get('patch_id', None)
            if patch_id:
                patch = get_object_or_404(Patch, id=patch_id)
                try:
                    bundle.append_patch(patch)
                except Exception:
                    pass
            bundle.save()
        elif action == 'add':
            bundle = get_object_or_404(Bundle,
                                       owner=request.user,
                                       id=request.POST['id'])
            bundle.save()

            patch_id = request.get('patch_id', None)
            if patch_id:
                patch_ids = patch_id
            else:
                patch_ids = get_patch_ids(request.POST)

            for id in patch_ids:
                try:
                    patch = Patch.objects.get(id=id)
                    bundle.append_patch(patch)
                except Exception:
                    pass

            bundle.save()
        elif action == 'delete':
            try:
                bundle = Bundle.objects.get(owner=request.user,
                                            id=request.POST['id'])
                bundle.delete()
            except Exception:
                pass

            bundle = None

    else:
        bundle = get_object_or_404(Bundle,
                                   owner=request.user,
                                   id=request.POST['bundle_id'])

    if bundle:
        return HttpResponseRedirect(
            reverse('bundle', kwargs={'bundle_id': bundle.id}))
    else:
        return HttpResponseRedirect(reverse('bundle_list'))
Exemple #26
0
def setbundle(request):
    bundle = None

    if request.method == 'POST':
        action = request.POST.get('action', None)
        if action is None:
            pass
        elif action == 'create':
            project = get_object_or_404(Project,
                                        id=request.POST.get('project'))
            bundle = Bundle(owner=request.user, project=project,
                            name=request.POST['name'])
            bundle.save()
            patch_id = request.POST.get('patch_id', None)
            if patch_id:
                patch = get_object_or_404(Patch, id=patch_id)
                bundle.append_patch(patch)
            bundle.save()
        elif action == 'add':
            bundle = get_object_or_404(Bundle,
                                       owner=request.user,
                                       id=request.POST['id'])
            bundle.save()

            patch_id = request.get('patch_id', None)
            if patch_id:
                patch_ids = patch_id
            else:
                patch_ids = get_patch_ids(request.POST)

            for patch_id in patch_ids:
                patch = Patch.objects.get(id=patch_id)
                bundle.append_patch(patch)

            bundle.save()
        elif action == 'delete':
            try:
                bundle = Bundle.objects.get(owner=request.user,
                                            id=request.POST['id'])
                bundle.delete()
            except Bundle.DoesNotExist:
                pass

            bundle = None
    else:
        bundle = get_object_or_404(Bundle, owner=request.user,
                                   id=request.POST['bundle_id'])

    if bundle:
        return HttpResponseRedirect(
            django.core.urlresolvers.reverse(
                'bundle-detail',
                kwargs={'bundle_id': bundle.id}
            )
        )
    else:
        return HttpResponseRedirect(
            django.core.urlresolvers.reverse('user-bundles')
        )
Exemple #27
0
def patch(request, patch_id):
    patch = get_object_or_404(Patch, id=patch_id)
    editable = Can(request.user).edit(patch)
    messages = []

    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()
                messages += ['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()
                messages += ['Patch added to bundle "%s"' % bundle.name]
            except Exception as ex:
                messages += ["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()
                messages += ['Patch updated']

    context = {
        'series': patch.series(),
        'patch': patch,
        'patchform': form,
        'createbundleform': createbundleform,
        'project': patch.project,
        'messages': messages,
        'test_results': TestResult.objects
                        .filter(revision=None, patch=patch)
                        .order_by('test__name').select_related('test')}

    return render(request, 'patchwork/patch.html', context)
Exemple #28
0
def patch(request, patch_id):
    patch = get_object_or_404(Patch, id=patch_id)
    editable = patch.is_editable(request.user)

    context = {
        'project': patch.project
    }

    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()
                messages.success(request, '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()
                messages.success(request,
                                 'Patch added to bundle "%s"' % bundle.name)
            except Exception as ex:
                messages.error(request,
                               "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()
                messages.success(request, 'Patch updated')

    if request.user.is_authenticated():
        context['bundles'] = Bundle.objects.filter(owner=request.user)

    context['patch'] = patch
    context['patchform'] = form
    context['createbundleform'] = createbundleform
    context['project'] = patch.project

    return render(request, 'patchwork/patch.html', context)