def new(request):
    error_message = ''
    if request.method == 'POST':
        form = forms.AddDHCPScopeForm(request.POST)
        if form.is_valid():
            truth_exists = False
            try:
                tmp = Truth.objects.get(name=form.cleaned_data['scope_name'])
                truth_exists = True
            except:
                pass
            if truth_exists is False: 
                t = Truth(name=form.cleaned_data['scope_name'], description=form.cleaned_data['scope_description'])
                t.save()
                k = TruthKeyValue(truth=t,key='is_dhcp_scope',value='True')
                k.save()
                return redirect('/dhcp/edit/%s' % t.name)
            else:
                error_message = 'DHCP Scope Exists'
    else:
        form = forms.AddDHCPScopeForm()

    return jinja_render_to_response('dhcp/new.html', {
            "form": form ,
            "error_message":error_message
           })
dataset/ETHPy150Open rtucker-mozilla/mozilla_inventory/dhcp/views.py/new/original