def add_node_view(request): if request.method != 'POST': form = NodeForm(initial={'parent': request.current_node}) current_language = get_language_from_request(request) formset = NodeLanguageVersionFormset( initial=[ { 'language': lang_short, 'DELETE': lang_short != current_language } for lang_short, lang_name in settings.LANGUAGES ], queryset=NodeLanguageVersion.objects.none(), ) else: instance = Node(parent=request.current_node) form = NodeForm(request.POST, instance=instance) formset = NodeLanguageVersionFormset(request.POST) if form.is_valid(): node = form.save(commit=False) formset = NodeLanguageVersionFormset(request.POST, instance=node) if formset.is_valid(): node.save() formset.save() return redirect(portal_url(node=node)) return render(request, 'portals/add-node.html', { 'form': form, 'formset': formset, })
def edit_node_view(request): if request.method != 'POST': form = NodeForm(instance=request.current_node) else: form = NodeForm(request.POST, instance=request.current_node) if form.is_valid(): node = form.save() return redirect(portal_url(node=node)) return render(request, 'portals/edit-node.html', {'form': form})
def add_node_view(request): if request.method != 'POST': form = NodeForm(initial={'parent': request.current_node}) else: instance = Node(parent=request.current_node) form = NodeForm(request.POST, instance=instance) if form.is_valid(): node = form.save() return redirect(portal_url(node=node)) return render(request, 'portals/add-node.html', {'form': form})
def add_node_view(request): if request.method != 'POST': form = NodeForm(initial={'parent': request.current_node}) current_language = get_language_from_request(request) formset = NodeLanguageVersionFormset( initial=[{ 'language': lang_short, 'DELETE': lang_short != current_language } for lang_short, lang_name in settings.LANGUAGES], queryset=NodeLanguageVersion.objects.none(), ) else: instance = Node(parent=request.current_node) form = NodeForm(request.POST, instance=instance) formset = NodeLanguageVersionFormset(request.POST) if form.is_valid(): node = form.save(commit=False) formset = NodeLanguageVersionFormset(request.POST, instance=node) if formset.is_valid(): node.save() formset.save() return redirect(portal_url(node=node)) return render(request, 'portals/add-node.html', { 'form': form, 'formset': formset, })
def edit_node_view(request): if request.method != 'POST': current_language = get_language_from_request(request) languages = [ lang_short for lang_short, lang_name in settings.LANGUAGES ] queryset = NodeLanguageVersion.objects.filter( node=request.current_node) for node_language_version in queryset: languages.remove(node_language_version.language) formset = NodeLanguageVersionFormset( initial=[ {'language': lang, 'DELETE': lang != current_language} for lang in languages ], instance=request.current_node, ) form = NodeForm(instance=request.current_node) else: form = NodeForm(request.POST, instance=request.current_node) formset = NodeLanguageVersionFormset(request.POST) if form.is_valid(): node = form.save(commit=False) formset = NodeLanguageVersionFormset(request.POST, instance=node) if formset.is_valid(): node.save() formset.save() return redirect(portal_url(node=node)) return render(request, 'portals/edit-node.html', { 'form': form, 'formset': formset, })
def edit_node_view(request): if request.method != 'POST': current_language = get_language_from_request(request) languages = [lang_short for lang_short, _ in settings.LANGUAGES] queryset = NodeLanguageVersion.objects.filter( node=request.current_node) for node_language_version in queryset: languages.remove(node_language_version.language) formset = NodeLanguageVersionFormset( initial=[{ 'language': lang, 'DELETE': lang != current_language } for lang in languages], instance=request.current_node, ) form = NodeForm(instance=request.current_node) else: form = NodeForm(request.POST, instance=request.current_node) formset = NodeLanguageVersionFormset(request.POST) if form.is_valid(): node = form.save(commit=False) formset = NodeLanguageVersionFormset(request.POST, instance=node) if formset.is_valid(): node.save() formset.save() return redirect(portal_url(node=node)) return render( request, 'portals/edit-node.html', { 'form': form, 'formset': formset, }, )