# 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
        'related_systems_table': tablefy(list(related_systems),
                                         request=request),
        'obj_type': 'system',
        'obj': system,
        'obj_table': system_table,
        'pretty_obj_type': system.pretty_type,
    })

def validate_system_create_form(request):
    system = None
    post_data = copy(request.POST)
    if not post_data.get('ctnr'):
        post_data['ctnr'] = request.session['ctnr'].id

    system_form = ExtendedSystemForm(post_data)
    if system_form.is_valid():
        system = system_form.save()
        post_data['system'] = system.id
    else:
        return HttpResponse(json.dumps({'errors': system_form.errors}))

    if post_data.get('interface_type', None) == 'static_interface':
        try:
            post_data['ip_type'] = ipaddr.IPAddress(
                post_data.get('ip_str', None)).version
        except:
            post_data['ip_type'] = None

        form = StaticInterfaceForm(post_data)
    else:

# 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

        'related_systems_table': tablefy(list(related_systems),
                                         request=request),
        'obj_type': 'system',
        'obj': system,
        'obj_table': system_table,
        'pretty_obj_type': system.pretty_type,
    })

def validate_system_create_form(request):
    system = None
    post_data = copy(request.POST)
    if not post_data.get('ctnr'):
        post_data['ctnr'] = request.session['ctnr'].id

    system_form = ExtendedSystemForm(post_data)
    if system_form.is_valid():
        system = system_form.save()
        post_data['system'] = system.id
    else:
        return HttpResponse(json.dumps({'errors': system_form.errors}))

    if post_data.get('interface_type', None) == 'static_interface':
        try:
            post_data['ip_type'] = ipaddr.IPAddress(
                post_data.get('ip_str', None)).version
        except:
            post_data['ip_type'] = None

        form = StaticInterfaceForm(post_data)
    else:

        form = DynamicInterfaceForm(post_data)