Esempio n. 1
0
def todo_lists(request):
    todo_lists = []

    for project in Project.objects.all():
        patches = request.user.profile.todo_patches(project=project)
        series = request.user.profile.todo_series(project=project)

        n_series = series.count()
        n_patches = patches.count()
        if (n_series + n_patches) == 0:
            continue

        todo_lists.append({'project': project,
                           'n_series': n_series,
                           'n_patches': n_patches})

    if len(todo_lists) == 1:
        return HttpResponseRedirect(
            urlresolvers.reverse(
                'patchwork.views.user.todo_list',
                kwargs={'project_id': todo_lists[0]['project'].linkname}))

    context = PatchworkRequestContext(request)
    context['todo_lists'] = todo_lists
    context.project = request.user.profile.primary_project
    return render_to_response('patchwork/todo-lists.html', context)
Esempio n. 2
0
def profile(request):
    context = PatchworkRequestContext(request)

    if request.method == 'POST':
        form = UserProfileForm(instance=request.user.profile,
                               data=request.POST)
        if form.is_valid():
            form.save()
    else:
        form = UserProfileForm(instance=request.user.profile)

    context.project = request.user.profile.primary_project
    context['bundles'] = Bundle.objects.filter(owner=request.user)
    context['profileform'] = form

    optout_query = '%s.%s IN (SELECT %s FROM %s)' % (
        Person._meta.db_table, Person._meta.get_field('email').column,
        EmailOptout._meta.get_field('email').column,
        EmailOptout._meta.db_table)
    people = Person.objects.filter(user = request.user) \
             .extra(select = {'is_optout': optout_query})
    context['linked_emails'] = people
    context['linkform'] = UserPersonLinkForm()

    return render_to_response('patchwork/profile.html', context)
Esempio n. 3
0
def profile(request):
    context = PatchworkRequestContext(request)

    if request.method == 'POST':
        form = UserProfileForm(instance = request.user.get_profile(),
                data = request.POST)
        if form.is_valid():
            form.save()
    else:
        form = UserProfileForm(instance = request.user.get_profile())

    context.project = request.user.get_profile().primary_project
    context['bundles'] = Bundle.objects.filter(owner = request.user)
    context['profileform'] = form

    optout_query = '%s.%s IN (SELECT %s FROM %s)' % (
                        Person._meta.db_table,
                        Person._meta.get_field('email').column,
                        EmailOptout._meta.get_field('email').column,
                        EmailOptout._meta.db_table)
    people = Person.objects.filter(user = request.user) \
             .extra(select = {'is_optout': optout_query})
    context['linked_emails'] = people
    context['linkform'] = UserPersonLinkForm()

    return render_to_response('patchwork/profile.html', context)
Esempio n. 4
0
def list(request, project_id):
    project = get_object_or_404(Project, linkname=project_id)
    context = generic_list(request, project, 'patchwork.views.patch.list',
            view_args = {'project_id': project.linkname})
    return render_to_response('patchwork/list.html', context)

    context = PatchworkRequestContext(request,
            list_view = 'patchwork.views.patch.list',
            list_view_params = {'project_id': project_id})
    order = get_order(request)
    project = get_object_or_404(Project, linkname=project_id)
    context.project = project

    form = None
    errors = []

    if request.method == 'POST':
        action = request.POST.get('action', None)
        if action:
            action = action.lower()

        # special case: the user may have hit enter in the 'create bundle'
        # text field, so if non-empty, assume the create action:
        if request.POST.get('bundle_name', False):
            action = 'create'

        ps = []
        for patch_id in get_patch_ids(request.POST):
            try:
                patch = Patch.objects.get(id = patch_id)
            except Patch.DoesNotExist:
                pass
            ps.append(patch)

        (errors, form) = set_patches(request.user, project, action, \
                                        request.POST, ps)
        if errors:
            context['errors'] = errors


    elif request.user.is_authenticated() and \
            project in request.user.get_profile().maintainer_projects.all():
        form = MultiplePatchForm(project)

    patches = Patch.objects.filter(project=project).order_by(order)
    patches = context.filters.apply(patches)

    paginator = Paginator(request, patches)

    context.update({
            'page':             paginator.current_page,
            'patchform':        form,
            'project':          project,
            'errors':           errors,
            })

    return render_to_response('patchwork/list.html', context)
Esempio n. 5
0
def pwclientrc(request, project_id):
    project = get_object_or_404(Project, linkname = project_id)
    context = PatchworkRequestContext(request)
    context.project = project
    if request.is_secure():
        context['scheme'] = 'https'
    else:
        context['scheme'] = 'http'
    response = HttpResponse(mimetype = "text/plain")
    response['Content-Disposition'] = 'attachment; filename=.pwclientrc'
    response.write(render_to_string('patchwork/pwclientrc', context))
    return response
Esempio n. 6
0
def pwclientrc(request, project_id):
    project = get_object_or_404(Project, linkname=project_id)
    context = PatchworkRequestContext(request)
    context.project = project
    if settings.FORCE_HTTPS_LINKS or request.is_secure():
        context['scheme'] = 'https'
    else:
        context['scheme'] = 'http'
    response = HttpResponse(content_type="text/plain")
    response['Content-Disposition'] = 'attachment; filename=.pwclientrc'
    response.write(render_to_string('patchwork/pwclientrc', context))
    return response
Esempio n. 7
0
def project(request, project_id):
    context = PatchworkRequestContext(request)
    project = get_object_or_404(Project, linkname = project_id)
    context.project = project

    context['maintainers'] = User.objects.filter( \
            userprofile__maintainer_projects = project)
    context['n_patches'] = Patch.objects.filter(project = project,
            archived = False).count()
    context['n_archived_patches'] = Patch.objects.filter(project = project,
            archived = True).count()

    return render_to_response('patchwork/project.html', context)
Esempio n. 8
0
def project(request, project_id):
    context = PatchworkRequestContext(request)
    project = get_object_or_404(Project, linkname=project_id)
    context.project = project

    context['maintainers'] = User.objects.filter( \
            profile__maintainer_projects = project)
    context['n_patches'] = Patch.objects.filter(project=project,
                                                archived=False).count()
    context['n_archived_patches'] = Patch.objects.filter(
        project=project, archived=True).count()
    context['n_series'] = Series.objects.filter(project=project).count()

    return render_to_response('patchwork/project.html', context)
Esempio n. 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')
Esempio n. 10
0
def bundles(request, project_id=None):
    context = PatchworkRequestContext(request)

    if request.method == 'POST':
        form_name = request.POST.get('form_name', '')

        if form_name == DeleteBundleForm.name:
            form = DeleteBundleForm(request.POST)
            if form.is_valid():
                bundle = get_object_or_404(Bundle,
                                           id=form.cleaned_data['bundle_id'])
                bundle.delete()

    if project_id is None:
        project = None
        bundles = Bundle.objects.filter(owner=request.user)
    else:
        project = get_object_or_404(Project, linkname=project_id)
        bundles = Bundle.objects.filter(owner=request.user, project=project)
    for bundle in bundles:
        bundle.delete_form = DeleteBundleForm(auto_id=False,
                                              initial={'bundle_id': bundle.id})

    context['bundles'] = bundles
    context['project'] = project

    return render_to_response('patchwork/bundles.html', context)
Esempio n. 11
0
def confirm(request, key):
    import patchwork.views.user
    import patchwork.views.mail
    views = {
        'userperson': patchwork.views.user.link_confirm,
        'registration': patchwork.views.user.register_confirm,
        'optout': patchwork.views.mail.optout_confirm,
        'optin': patchwork.views.mail.optin_confirm,
    }

    conf = get_object_or_404(EmailConfirmation, key=key)
    if conf.type not in views:
        raise Http404

    if conf.active and conf.is_valid():
        return views[conf.type](request, conf)

    context = PatchworkRequestContext(request)
    context['conf'] = conf
    if not conf.active:
        context['error'] = 'inactive'
    elif not conf.is_valid():
        context['error'] = 'expired'

    return render_to_response('patchwork/confirm-error.html', context)
Esempio n. 12
0
def link(request):
    context = PatchworkRequestContext(request)

    if request.method == 'POST':
        form = UserPersonLinkForm(request.POST)
        if form.is_valid():
            conf = EmailConfirmation(type='userperson',
                                     user=request.user,
                                     email=form.cleaned_data['email'])
            conf.save()
            context['confirmation'] = conf

            try:
                send_mail(
                    'Patchwork email address confirmation',
                    render_to_string('patchwork/user-link.mail', context),
                    settings.DEFAULT_FROM_EMAIL, [form.cleaned_data['email']])
            except Exception:
                context['confirmation'] = None
                context['error'] = 'An error occurred during confirmation. ' + \
                                   'Please try again later'
    else:
        form = UserPersonLinkForm()
    context['linkform'] = form

    return render_to_response('patchwork/user-link.html', context)
Esempio n. 13
0
def settings(request):
    context = PatchworkRequestContext(request)
    if request.method == 'POST':
        form = EmailForm(data=request.POST)
        if form.is_valid():
            email = form.cleaned_data['email']
            is_optout = EmailOptout.objects.filter(email=email).count() > 0
            context.update({
                'email': email,
                'is_optout': is_optout,
            })
            return render_to_response('patchwork/mail-settings.html', context)

    else:
        form = EmailForm()
    context['form'] = form
    return render_to_response('patchwork/mail-form.html', context)
Esempio n. 14
0
def todo_lists(request):
    todo_lists = []

    for project in Project.objects.all():
        patches = request.user.profile.todo_patches(project=project)
        if not patches.count():
            continue

        todo_lists.append({'project': project, 'n_patches': patches.count()})

    if len(todo_lists) == 1:
        return todo_list(request, todo_lists[0]['project'].linkname)

    context = PatchworkRequestContext(request)
    context['todo_lists'] = todo_lists
    context.project = request.user.profile.primary_project
    return render_to_response('patchwork/todo-lists.html', context)
Esempio n. 15
0
def todo_lists(request):
    todo_lists = []

    for project in Project.objects.all():
        patches = request.user.get_profile().todo_patches(project = project)
        if not patches.count():
            continue

        todo_lists.append({'project': project, 'n_patches': patches.count()})

    if len(todo_lists) == 1:
        return todo_list(request, todo_lists[0]['project'].linkname)

    context = PatchworkRequestContext(request)
    context['todo_lists'] = todo_lists
    context.project = request.user.get_profile().primary_project
    return render_to_response('patchwork/todo-lists.html', context)
Esempio n. 16
0
def settings(request):
    context = PatchworkRequestContext(request)
    if request.method == 'POST':
        form = EmailForm(data = request.POST)
        if form.is_valid():
            email = form.cleaned_data['email']
            is_optout = EmailOptout.objects.filter(email = email).count() > 0
            context.update({
                'email': email,
                'is_optout': is_optout,
            })
            return render_to_response('patchwork/mail-settings.html', context)

    else:
        form = EmailForm()
    context['form'] = form
    return render_to_response('patchwork/mail-form.html', context)
Esempio n. 17
0
def optin_confirm(request, conf):
    context = PatchworkRequestContext(request)

    email = conf.email.strip().lower()
    EmailOptout.objects.filter(email=email).delete()

    conf.deactivate()
    context['email'] = conf.email

    return render_to_response('patchwork/optin.html', context)
Esempio n. 18
0
def projects(request):
    context = PatchworkRequestContext(request)
    projects = Project.objects.all()

    if projects.count() == 1:
        return HttpResponseRedirect(
            urlresolvers.reverse('patchwork.views.patch.list',
                                 kwargs={'project_id': projects[0].linkname}))

    context['projects'] = projects
    return render_to_response('patchwork/projects.html', context)
Esempio n. 19
0
def profile(request):
    context = PatchworkRequestContext(request)

    if request.method == 'POST':
        form = UserProfileForm(instance = request.user.get_profile(),
                data = request.POST)
        if form.is_valid():
            form.save()
    else:
        form = UserProfileForm(instance = request.user.get_profile())

    context.project = request.user.get_profile().primary_project
    context['bundles'] = Bundle.objects.filter(owner = request.user)
    context['profileform'] = form

    people = Person.objects.filter(user = request.user)
    context['linked_emails'] = people
    context['linkform'] = UserPersonLinkForm()

    return render_to_response('patchwork/profile.html', context)
Esempio n. 20
0
def optout_confirm(request, conf):
    context = PatchworkRequestContext(request)

    email = conf.email.strip().lower()
    # silently ignore duplicated optouts
    if EmailOptout.objects.filter(email=email).count() == 0:
        optout = EmailOptout(email=email)
        optout.save()

    conf.deactivate()
    context['email'] = conf.email

    return render_to_response('patchwork/optout.html', context)
Esempio n. 21
0
def link_confirm(request, conf):
    context = PatchworkRequestContext(request)

    try:
        person = Person.objects.get(email__iexact=conf.email)
    except Person.DoesNotExist:
        person = Person(email=conf.email)

    person.link_to_user(conf.user)
    person.save()
    conf.deactivate()

    context['person'] = person

    return render_to_response('patchwork/user-link-confirm.html', context)
Esempio n. 22
0
def register(request):
    context = PatchworkRequestContext(request)
    if request.method == 'POST':
        form = RegistrationForm(request.POST)
        if form.is_valid():
            data = form.cleaned_data
            # create inactive user
            user = auth.models.User.objects.create_user(
                data['username'], data['email'], data['password'])
            user.is_active = False
            user.first_name = data.get('first_name', '')
            user.last_name = data.get('last_name', '')
            user.save()

            # create confirmation
            conf = EmailConfirmation(type='registration',
                                     user=user,
                                     email=user.email)
            conf.save()

            # send email
            mail_ctx = {
                'site': Site.objects.get_current(),
                'confirmation': conf
            }

            subject = render_to_string(
                'patchwork/activation_email_subject.txt',
                mail_ctx).replace('\n', ' ').strip()

            message = render_to_string('patchwork/activation_email.txt',
                                       mail_ctx)

            send_mail(subject, message, settings.DEFAULT_FROM_EMAIL,
                      [conf.email])

            # setting 'confirmation' in the template indicates success
            context['confirmation'] = conf

    else:
        form = RegistrationForm()

    return render_to_response('patchwork/registration_form.html',
                              {'form': form},
                              context_instance=context)
Esempio n. 23
0
def optinout(request, action, description):
    context = PatchworkRequestContext(request)

    mail_template = 'patchwork/%s-request.mail' % action
    html_template = 'patchwork/%s-request.html' % action

    if request.method != 'POST':
        return HttpResponseRedirect(reverse(settings))

    form = OptinoutRequestForm(data=request.POST)
    if not form.is_valid():
        context['error'] = ('There was an error in the %s form. ' +
                            'Please review the form and re-submit.') % \
            description
        context['form'] = form
        return render_to_response(html_template, context)

    email = form.cleaned_data['email']
    if action == 'optin' and \
            EmailOptout.objects.filter(email=email).count() == 0:
        context['error'] = ('The email address %s is not on the ' +
                            'patchwork opt-out list, so you don\'t ' +
                            'need to opt back in') % email
        context['form'] = form
        return render_to_response(html_template, context)

    conf = EmailConfirmation(type=action, email=email)
    conf.save()
    context['confirmation'] = conf
    mail = render_to_string(mail_template, context)
    try:
        send_mail('Patchwork %s confirmation' % description, mail,
                  conf_settings.DEFAULT_FROM_EMAIL, [email])
        context['email'] = mail
        context['email_sent'] = True
    except Exception:
        context['error'] = ('An error occurred during confirmation . '
                            'Please try again later.')
        context['admins'] = conf_settings.ADMINS

    return render_to_response(html_template, context)
Esempio n. 24
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)
Esempio n. 25
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')
Esempio n. 26
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)
Esempio n. 27
0
def pwclient(request):
    context = PatchworkRequestContext(request)
    response = HttpResponse(content_type="text/x-python")
    response['Content-Disposition'] = 'attachment; filename=pwclient'
    response.write(render_to_string('patchwork/pwclient', context))
    return response
Esempio n. 28
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'))
Esempio n. 29
0
def help(request, path):
    context = PatchworkRequestContext(request)
    if path in help_pages:
        return render_to_response('patchwork/help/' + help_pages[path],
                                  context)
    raise Http404
Esempio n. 30
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)