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)
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 data = {} if request.method == 'GET': data = request.GET elif request.method == 'POST': data = request.POST order = Order(data.get('order'), editable=editable_order) # Explicitly set data to None because request.POST will be an empty dict # when the form is not submitted, but passing a non-None data argument to # a forms.Form will make it bound and we don't want that to happen unless # there's been a form submission. if request.method != 'POST': data = None user = request.user properties_form = None if user.is_authenticated(): # we only pass the post data to the MultiplePatchForm if that was # the actual form submitted data_tmp = None if data and data.get('form', '') == 'patchlistform': data_tmp = data properties_form = MultiplePatchForm(project, data=data_tmp) if request.method == 'POST' and data.get('form') == 'patchlistform': action = data.get('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 data.get('bundle_name', False): action = 'create' ps = Patch.objects.filter(id__in=get_patch_ids(data)) if action in bundle_actions: errors = set_bundle(user, project, action, data, ps, context) elif properties_form and action == properties_form.action: errors = process_multiplepatch_form(properties_form, user, action, ps, context) else: errors = [] if errors: context['errors'] = errors 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) # annotate with tag counts patches = patches.with_tag_counts(project) patches = context.filters.apply(patches) if not editable_order: patches = order.apply(patches) # we don't need the content or headers for a list; they're text fields # that can potentially contain a lot of data patches = patches.defer('content', 'headers') # but we will need to follow the state and submitter relations for # rendering the list template patches = patches.select_related('state', 'submitter', 'delegate') paginator = Paginator(request, patches) context.update({ 'page': paginator.current_page, 'patchform': properties_form, 'project': project, 'order': order, }) return context
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'))
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) # Explicitly set data to None because request.POST will be an empty dict # when the form is not submitted, but passing a non-None data argument to # a forms.Form will make it bound and we don't want that to happen unless # there's been a form submission. data = None if request.method == 'POST': data = request.POST user = request.user properties_form = None if project.is_editable(user): # we only pass the post data to the MultiplePatchForm if that was # the actual form submitted data_tmp = None if data and data.get('form', '') == 'patchlistform': data_tmp = data properties_form = MultiplePatchForm(project, data = data_tmp) if request.method == 'POST' and data.get('form') == 'patchlistform': action = data.get('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 data.get('bundle_name', False): action = 'create' ps = Patch.objects.filter(id__in = get_patch_ids(data)) if action in bundle_actions: errors = set_bundle(user, project, action, data, ps, context) elif properties_form and action == properties_form.action: errors = process_multiplepatch_form(properties_form, user, action, ps, context) else: errors = [] if errors: context['errors'] = errors 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': properties_form, 'project': project, 'order': order, }) return context
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') )
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 data = {} if request.method == 'GET': data = request.GET elif request.method == 'POST': data = request.POST order = Order(data.get('order'), editable=editable_order) # Explicitly set data to None because request.POST will be an empty dict # when the form is not submitted, but passing a non-None data argument to # a forms.Form will make it bound and we don't want that to happen unless # there's been a form submission. if request.method != 'POST': data = None user = request.user properties_form = None if user.is_authenticated(): # we only pass the post data to the MultiplePatchForm if that was # the actual form submitted data_tmp = None if data and data.get('form', '') == 'patchlistform': data_tmp = data properties_form = MultiplePatchForm(project, data = data_tmp) if request.method == 'POST' and data.get('form') == 'patchlistform': action = data.get('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 data.get('bundle_name', False): action = 'create' ps = Patch.objects.filter(id__in = get_patch_ids(data)) if action in bundle_actions: errors = set_bundle(user, project, action, data, ps, context) elif properties_form and action == properties_form.action: errors = process_multiplepatch_form(properties_form, user, action, ps, context) else: errors = [] if errors: context['errors'] = errors 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) # annotate with tag counts patches = patches.with_tag_counts(project) patches = context.filters.apply(patches) if not editable_order: patches = order.apply(patches) # we don't need the content or headers for a list; they're text fields # that can potentially contain a lot of data patches = patches.defer('content', 'headers') # but we will need to follow the state and submitter relations for # rendering the list template patches = patches.select_related('state', 'submitter', 'delegate') paginator = Paginator(request, patches) context.update({ 'page': paginator.current_page, 'patchform': properties_form, 'project': project, 'order': order, }) return context
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