def repo_edit(request, repo_id): repo = get_object_or_404(Repository, id=repo_id) if request.method == 'POST': if 'save' in request.POST: edit_form = EditRepoForm(request.POST, instance=repo) if edit_form.is_valid(): repo = edit_form.save() repo.save() mirrors = edit_form.cleaned_data['mirrors'] for mirror in mirrors: mirror.repo = repo mirror.save() if repo.enabled: repo.enable() else: repo.disable() text = 'Saved changes to Repository {0!s}'.format(repo) messages.info(request, text) return HttpResponseRedirect(repo.get_absolute_url()) else: repo = get_object_or_404(Repository, id=repo_id) elif 'cancel' in request.POST: return HttpResponseRedirect(reverse('repo_detail', args=[repo_id])) else: edit_form = EditRepoForm(instance=repo) edit_form.initial['mirrors'] = repo.mirror_set.all() return render(request, 'repos/repo_edit.html', {'repo': repo, 'edit_form': edit_form}, )
def repo_edit(request, repo_id): repo = get_object_or_404(Repository, id=repo_id) if request.method == "POST": edit_form = EditRepoForm(request.POST, instance=repo) if edit_form.is_valid(): repo = edit_form.save() repo.save() mirrors = edit_form.cleaned_data["mirrors"] for mirror in mirrors: mirror.repo = repo mirror.save() if repo.enabled: repo.enable() else: repo.disable() messages.info(request, "Saved changes to Repository %s" % repo) return HttpResponseRedirect(repo.get_absolute_url()) else: repo = get_object_or_404(Repository, id=repo_id) else: edit_form = EditRepoForm(instance=repo) edit_form.initial["mirrors"] = repo.mirror_set.all() return render_to_response( "repos/repo_edit.html", {"repo": repo, "edit_form": edit_form}, context_instance=RequestContext(request) )
def repo_edit(request, repo_id): repo = get_object_or_404(Repository, id=repo_id) if request.method == 'POST': edit_form = EditRepoForm(request.POST, instance=repo) if edit_form.is_valid(): repo = edit_form.save() repo.save() mirrors = edit_form.cleaned_data['mirrors'] for mirror in mirrors: mirror.repo = repo mirror.save() messages.info(request, 'Saved changes to Repository %s' % repo) return HttpResponseRedirect(repo.get_absolute_url()) else: repo = get_object_or_404(Repository, id=repo_id) else: edit_form = EditRepoForm(instance=repo) edit_form.initial['mirrors'] = repo.mirror_set.all() return render_to_response('repos/repo_edit.html', {'repo': repo, 'edit_form': edit_form}, context_instance=RequestContext(request))
def repo_edit(request, repo_id): repo = get_object_or_404(Repository, id=repo_id) if request.method == 'POST': if 'save' in request.POST: edit_form = EditRepoForm(request.POST, instance=repo) if edit_form.is_valid(): repo = edit_form.save() repo.save() mirrors = edit_form.cleaned_data['mirrors'] for mirror in mirrors: mirror.repo = repo mirror.save() if repo.enabled: repo.enable() else: repo.disable() text = 'Saved changes to Repository {0!s}'.format(repo) messages.info(request, text) return HttpResponseRedirect(repo.get_absolute_url()) else: repo = get_object_or_404(Repository, id=repo_id) elif 'cancel' in request.POST: return HttpResponseRedirect(reverse('repo_detail', args=[repo_id])) else: edit_form = EditRepoForm(instance=repo) edit_form.initial['mirrors'] = repo.mirror_set.all() return render( request, 'repos/repo_edit.html', { 'repo': repo, 'edit_form': edit_form }, )