Exemplo n.º 1
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)
Exemplo n.º 2
0
def generic_list(request, project, view,
        view_args = {}, filter_settings = [], patches = None,
        editable_order = False):

    context = PatchworkRequestContext(request,
            list_view = view,
            list_view_params = view_args)

    context.project = project
    order = Order(request.REQUEST.get('order'), editable = editable_order)

    form = MultiplePatchForm(project)

    if request.method == 'POST' and \
                       request.POST.get('form') == 'patchlistform':
        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, context)
        if errors:
            context['errors'] = errors

    if not (request.user.is_authenticated() and \
            project in request.user.get_profile().maintainer_projects.all()):
        form = None

    for (filterclass, setting) in filter_settings:
        if isinstance(setting, dict):
            context.filters.set_status(filterclass, **setting)
        elif isinstance(setting, list):
            context.filters.set_status(filterclass, *setting)
        else:
            context.filters.set_status(filterclass, setting)

    if patches is None:
        patches = Patch.objects.filter(project=project)

    patches = context.filters.apply(patches)
    if not editable_order:
        patches = patches.order_by(order.query())

    paginator = Paginator(request, patches)

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

    return context