from django.contrib.auth.decorators import login_required
from django.http import HttpResponse
from django.shortcuts import render

from members.models import User
from .models import Protocol, Topic
from .forms import ProtocolForm, TopicForm, InstitutionForm


@login_required
def add(request):
    data = request.POST if request else None
    form = ProtocolForm(data)

    #import ipdb; ipdb.set_trace()

    if form.is_valid():
        form.save()

    return render(request, 'protocols/add.html', locals())

from django.contrib.auth.decorators import login_required
from django.http import HttpResponse
from django.shortcuts import render

from members.models import User
from .models import Protocol, Topic
from .forms import ProtocolForm, TopicForm, InstitutionForm


@login_required
def add(request):
    data = request.POST if request.POST else None
    form = ProtocolForm(data)

    if form.is_valid():
        form.save()

    return render(request, 'protocols/add.html', locals())

Fix the check if form is submitted
Fix the check if form is submitted

  from django.contrib.auth.decorators import login_required
  from django.http import HttpResponse
  from django.shortcuts import render
  
  from members.models import User
  from .models import Protocol, Topic
  from .forms import ProtocolForm, TopicForm, InstitutionForm
  
  
  @login_required
  def add(request):
-     data = request.POST if request else None
+     data = request.POST if request.POST else None
      form = ProtocolForm(data)
- 
-     #import ipdb; ipdb.set_trace()
  
      if form.is_valid():
          form.save()
  
      return render(request, 'protocols/add.html', locals())
  
Fix the check if form is submitted
## Code Before:
from django.contrib.auth.decorators import login_required
from django.http import HttpResponse
from django.shortcuts import render

from members.models import User
from .models import Protocol, Topic
from .forms import ProtocolForm, TopicForm, InstitutionForm


@login_required
def add(request):
    data = request.POST if request else None
    form = ProtocolForm(data)

    #import ipdb; ipdb.set_trace()

    if form.is_valid():
        form.save()

    return render(request, 'protocols/add.html', locals())

## Instruction:
Fix the check if form is submitted
## Code After:
from django.contrib.auth.decorators import login_required
from django.http import HttpResponse
from django.shortcuts import render

from members.models import User
from .models import Protocol, Topic
from .forms import ProtocolForm, TopicForm, InstitutionForm


@login_required
def add(request):
    data = request.POST if request.POST else None
    form = ProtocolForm(data)

    if form.is_valid():
        form.save()

    return render(request, 'protocols/add.html', locals())
