Ejemplo n.º 1
0
def network_edit(request, pk):
    """ Edit network page. """

    network = get_object_or_404(Network, pk=pk)

    if request.method == "POST":
        networkform = NetworkForm(data=request.POST, instance=network)
        if networkform.is_valid():
            networkform.save()
            return redirect('network_detail', pk=network.id)
    else:
        networkform = NetworkForm(instance=network)

    return render(request, 'editorial/networkedit.html', {
            'network': network,
            'networkform': networkform,
        })
Ejemplo n.º 2
0
def network_new(request):
    """ Create a new network. """

    networkform = NetworkForm()
    owner_org = request.user.organization
    if request.method == "POST":
        networkform = NetworkForm(request.POST or None)
        if networkform.is_valid():
            network = networkform.save(commit=False)
            network.owner_organization = owner_org
            network.creation_date = timezone.now()
            discussion = Discussion.objects.create_discussion("NET")
            network.discussion = discussion
            network.save()
            network.organizations.add(owner_org)
            network.save()
            return redirect('network_detail', pk=network.pk)
    else:
        networkform = NetworkForm()
    return render(request, 'editorial/networknew.html', {
            'networkform': networkform
        })