# Path: cyder/cydhcp/interface/dynamic_intr/forms.py
# class DynamicInterfaceForm(RangeWizard, UsabilityFormMixin):
#     def __init__(self, *args, **kwargs):
#         super(DynamicInterfaceForm, self).__init__(*args, **kwargs)
#         self.fields.keyOrder = ['system', 'mac', 'vrf', 'site', 'range',
#                                 'workgroup', 'expire', 'dhcp_enabled']
#         self.fields['expire'].widget.format = "%m/%d/%Y"
#         self.fields['range'].required = True
#         self.fields['range'].queryset = Range.objects.filter(
#             range_type=DYNAMIC)
# 
#     class Meta:
#         model = DynamicInterface
#         exclude = ('last_seen',)
#         always_validate = ('mac',)


import ipaddr
import simplejson as json
from copy import copy
from django import forms
from django.core.urlresolvers import reverse
from django.core.exceptions import ValidationError
from django.db.models import get_model
from django.forms.util import ErrorDict, ErrorList
from django.http import HttpResponse
from django.shortcuts import redirect
from cyder.base.utils import tablefy
from cyder.base.views import cy_render
from cyder.core.system.models import System
from cyder.core.system.forms import ExtendedSystemForm
from cyder.cydhcp.interface.dynamic_intr.models import DynamicInterface
from cyder.cydhcp.interface.dynamic_intr.forms import DynamicInterfaceForm
from cyder.cydhcp.interface.static_intr.models import StaticInterface
from cyder.cydhcp.interface.static_intr.forms import StaticInterfaceForm
        except:
            post_data['ip_type'] = None

        form = StaticInterfaceForm(post_data)
    else:
        form = DynamicInterfaceForm(post_data)

    if form.is_valid():
        try:
            form.save()
            return HttpResponse(json.dumps(
                {'success': True, 'system_id': system.id}))
        except ValidationError as e:
            if form.errors is None:
                form.errors = ErrorDict()
            form.errors.update(e.message_dict)
            return HttpResponse(json.dumps({'errors': form.errors}))
    else:
        if system:
            system.delete()

        return HttpResponse(json.dumps({'errors': form.errors}))


def system_create_view(request):
    if request.method == 'POST':
        return validate_system_create_form(request)

    initial_type = None
    static_form = StaticInterfaceForm()

# Path: cyder/cydhcp/interface/dynamic_intr/forms.py
# class DynamicInterfaceForm(RangeWizard, UsabilityFormMixin):
#     def __init__(self, *args, **kwargs):
#         super(DynamicInterfaceForm, self).__init__(*args, **kwargs)
#         self.fields.keyOrder = ['system', 'mac', 'vrf', 'site', 'range',
#                                 'workgroup', 'expire', 'dhcp_enabled']
#         self.fields['expire'].widget.format = "%m/%d/%Y"
#         self.fields['range'].required = True
#         self.fields['range'].queryset = Range.objects.filter(
#             range_type=DYNAMIC)
# 
#     class Meta:
#         model = DynamicInterface
#         exclude = ('last_seen',)
#         always_validate = ('mac',)


# Path: cyder/core/system/views.py
import ipaddr
import simplejson as json
from copy import copy
from django import forms
from django.core.urlresolvers import reverse
from django.core.exceptions import ValidationError
from django.db.models import get_model
from django.forms.util import ErrorDict, ErrorList
from django.http import HttpResponse
from django.shortcuts import redirect
from cyder.base.utils import tablefy
from cyder.base.views import cy_render
from cyder.core.system.models import System
from cyder.core.system.forms import ExtendedSystemForm
from cyder.cydhcp.interface.dynamic_intr.models import DynamicInterface
from cyder.cydhcp.interface.dynamic_intr.forms import DynamicInterfaceForm
from cyder.cydhcp.interface.static_intr.models import StaticInterface
from cyder.cydhcp.interface.static_intr.forms import StaticInterfaceForm

        except:
            post_data['ip_type'] = None

        form = StaticInterfaceForm(post_data)
    else:
        form = DynamicInterfaceForm(post_data)

    if form.is_valid():
        try:
            form.save()
            return HttpResponse(json.dumps(
                {'success': True, 'system_id': system.id}))
        except ValidationError as e:
            if form.errors is None:
                form.errors = ErrorDict()
            form.errors.update(e.message_dict)
            return HttpResponse(json.dumps({'errors': form.errors}))
    else:
        if system:
            system.delete()

        return HttpResponse(json.dumps({'errors': form.errors}))


def system_create_view(request):
    if request.method == 'POST':
        return validate_system_create_form(request)

    initial_type = None
    static_form = StaticInterfaceForm()

    dynamic_form = DynamicInterfaceForm()