class PatchworkRequestContext(RequestContext): def __init__(self, request, project=None, dict=None, processors=None, list_view=None, list_view_params={}): self._project = project self.filters = Filters(request) if processors is None: processors = [] processors.append(bundle) super(PatchworkRequestContext, self).__init__( request, dict, processors) self.update({ 'filters': self.filters, 'messages': [], }) if list_view: params = self.filters.params() for param in ['order', 'page']: data = {} if request.method == 'GET': data = request.GET elif request.method == 'POST': data = request.POST value = data.get(param, None) if value: params.append((param, value)) self.update({ 'list_view': { 'view': list_view, 'view_params': list_view_params, 'params': params }}) self.projects = Project.objects.all() self.update({ 'project': self.project, 'site': Site.objects.get_current(), 'settings': settings, 'other_projects': len(self.projects) > 1 }) def _set_project(self, project): self._project = project self.filters.set_project(project) self.update({'project': self._project}) def _get_project(self): return self._project project = property(_get_project, _set_project) def add_message(self, message): self['messages'].append(message)
def __init__(self, request, project = None, dict = None, processors = None, list_view = None, list_view_params = {}): self._project = project self.filters = Filters(request) if processors is None: processors = [] processors.append(bundle) super(PatchworkRequestContext, self). \ __init__(request, dict, processors); self.update({'filters': self.filters}) if list_view: params = self.filters.params() for param in ['order', 'page']: value = request.REQUEST.get(param, None) if value: params.append((param, value)) self.update({ 'list_view': { 'view': list_view, 'view_params': list_view_params, 'params': params }}) self.projects = Project.objects.all() self.update({ 'project': self.project, 'site': Site.objects.get_current(), 'settings': settings, 'other_projects': len(self.projects) > 1 })
def generic_list(request, project, view, view_args=None, filter_settings=None, patches=None, editable_order=False): if not filter_settings: filter_settings = [] filters = Filters(request) context = { 'project': project, 'projects': Project.objects.all(), 'filters': filters, } # pagination params = filters.params() for param in ['order', 'page']: data = {} if request.method == 'GET': data = request.GET elif request.method == 'POST': data = request.POST value = data.get(param, None) if value: params.append((param, value)) data = {} if request.method == 'GET': data = request.GET elif request.method == 'POST': data = request.POST order = Order(data.get('order'), editable=editable_order) context.update({ 'order': order, 'list_view': { 'view': view, 'view_params': view_args or {}, 'params': params }}) # form processing # 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(request, project, action, data, ps, context) elif properties_form and action == properties_form.action: errors = process_multiplepatch_form(request, properties_form, 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(patch_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, diff or headers for a list; they're text # fields that can potentially contain a lot of data patches = patches.defer('content', 'diff', 'headers') # but we will need to follow the state and submitter relations for # rendering the list template patches = patches.select_related('state', 'submitter', 'delegate') # we also need checks and series patches = patches.prefetch_related('check_set', 'series') 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): filters = Filters(request) context = { 'project': project, 'projects': Project.objects.all(), 'filters': filters, } # pagination params = filters.params() for param in ['order', 'page']: data = {} if request.method == 'GET': data = request.GET elif request.method == 'POST': data = request.POST value = data.get(param, None) if value: params.append((param, value)) data = {} if request.method == 'GET': data = request.GET elif request.method == 'POST': data = request.POST order = Order(data.get('order'), editable=editable_order) context.update({ 'order': order, 'list_view': { 'view': view, 'view_params': view_args, 'params': params }}) # form processing # 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(request, project, action, data, ps, context) elif properties_form and action == properties_form.action: errors = process_multiplepatch_form(request, properties_form, 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, diff or headers for a list; they're text # fields that can potentially contain a lot of data patches = patches.defer('content', 'diff', 'headers') # but we will need to follow the state and submitter relations for # rendering the list template patches = patches.select_related('state', 'submitter', 'delegate') # we also need checks patches = patches.prefetch_related('check_set') 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=None, filter_settings=None, patches=None, editable_order=False): if not filter_settings: filter_settings = [] filters = Filters(request) context = {"project": project, "projects": Project.objects.all(), "filters": filters} # pagination params = filters.params() for param in ["order", "page"]: data = {} if request.method == "GET": data = request.GET elif request.method == "POST": data = request.POST value = data.get(param, None) if value: params.append((param, value)) data = {} if request.method == "GET": data = request.GET elif request.method == "POST": data = request.POST order = Order(data.get("order"), editable=editable_order) context.update({"order": order, "list_view": {"view": view, "view_params": view_args or {}, "params": params}}) # form processing # 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(request, project, action, data, ps, context) elif properties_form and action == properties_form.action: errors = process_multiplepatch_form(request, properties_form, 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, diff or headers for a list; they're text # fields that can potentially contain a lot of data patches = patches.defer("content", "diff", "headers") # but we will need to follow the state and submitter relations for # rendering the list template patches = patches.select_related("state", "submitter", "delegate") # we also need checks and series patches = patches.prefetch_related("check_set", "series") paginator = Paginator(request, patches) context.update({"page": paginator.current_page, "patchform": properties_form, "project": project, "order": order}) return context