2013-09-28 20:01:09 +02:00
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
|
|
|
|
from django import forms
|
|
|
|
from django.contrib.auth.models import User
|
|
|
|
from main.models import *
|
|
|
|
|
|
|
|
class HostForm(forms.ModelForm):
|
|
|
|
class Meta:
|
|
|
|
model = Host
|
|
|
|
fields = ['fqdn', 'comment', ]
|
|
|
|
|
2013-09-28 21:32:29 +02:00
|
|
|
def __init__(self, user, *args, **kwargs):
|
|
|
|
super(HostForm, self).__init__(*args, **kwargs)
|
|
|
|
self.created_by = user
|
|
|
|
|
|
|
|
def create_host(self, user):
|
2013-09-28 20:18:20 +02:00
|
|
|
self.clean()
|
|
|
|
host = Host(fqdn=self.cleaned_data['fqdn'],
|
2013-09-28 21:32:29 +02:00
|
|
|
comment=self.cleaned_data['comment'],
|
|
|
|
created_by=user)
|
2013-09-28 20:18:20 +02:00
|
|
|
host.save()
|
2013-09-28 21:32:29 +02:00
|
|
|
# TODO: Update NS with self.cleaned_data['ipv4addr']
|
2013-09-28 20:18:20 +02:00
|
|
|
return host
|
|
|
|
|