26 lines
757 B
Python
Raw Normal View History

# -*- coding: utf-8 -*-
from django import forms
from django.contrib.auth.models import User
2013-09-28 22:20:19 +02:00
from main.models import Host
class HostForm(forms.ModelForm):
class Meta:
model = Host
fields = ['fqdn', 'comment', 'update_secret']
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):
self.clean()
host = Host(fqdn=self.cleaned_data['fqdn'],
2013-09-28 21:32:29 +02:00
comment=self.cleaned_data['comment'],
update_secret=self.cleaned_data['update_secret'],
2013-09-28 21:32:29 +02:00
created_by=user)
host.save()
2013-09-28 21:32:29 +02:00
# TODO: Update NS with self.cleaned_data['ipv4addr']
return host