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)
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)
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)
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)
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 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
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
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)
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')
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)
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')
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)
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)
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)
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)
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)