# Path: sshkm/models.py
# class Key(models.Model):
#     name = models.CharField(max_length=191, unique=True)
#     description = models.CharField(max_length=191, null=True, blank=True)
#     firstname = models.CharField(max_length=191, null=True, blank=True)
#     lastname = models.CharField(max_length=191, null=True, blank=True)
#     email = models.EmailField(max_length=191, null=True, blank=True)
#     publickey = models.TextField(null=True, blank=True)
#     member_of = models.ManyToManyField('Group', through='KeyGroup', blank=True)
# 
# class Group(models.Model):
#     name = models.CharField(max_length=191, unique=True)
#     description = models.CharField(max_length=191, null=True, blank=True)
#     members = models.ManyToManyField('Key', through='KeyGroup', blank=True)
# 
# class Host(models.Model):
#     name = models.CharField(max_length=191, unique=True)
#     superuser = models.CharField(max_length=191, null=True, blank=True)
#     description = models.CharField(max_length=191, null=True, blank=True)
#     status = models.CharField(max_length=10, null=True, blank=True)
#     last_status = models.DateTimeField(null=True, blank=True)
# 
# class Osuser(models.Model):
#     name = models.CharField(max_length=191, unique=True)
#     home = models.CharField(max_length=191, null=True, blank=True)
#     description = models.CharField(max_length=191, null=True, blank=True)
# 
# class KeyGroup(models.Model):
#     key = models.ForeignKey('Key', on_delete=models.CASCADE)
#     group = models.ForeignKey('Group', on_delete=models.CASCADE)
# 
# class Permission(models.Model):
#     group = models.ForeignKey(Group, on_delete=models.CASCADE)
#     host = models.ForeignKey(Host, on_delete=models.CASCADE)
#     osuser = models.ForeignKey(Osuser, on_delete=models.CASCADE)
# 
#     class Meta:
#         unique_together = ("group", "host", "osuser")


from django import forms
from .models import Key, Group, Host, Osuser, KeyGroup, Permission
from django.contrib.auth.models import User
from django.utils.translation import ugettext_lazy as _
from django.forms import ModelMultipleChoiceField
        super(HostForm, self).__init__(*args, **kwargs)
        self.fields['name'].widget.attrs['placeholder'] = 'host1.example.com or 192.168.1.33'
        self.fields['superuser'].widget.attrs['placeholder'] = 'default: root'
        self.fields['superuser'].label = 'Superuser (OS-User used to connect to your host to deploy all other keys)'
        self.fields['description'].widget.attrs['placeholder'] = ''

class OsuserForm(forms.ModelForm):
    class Meta:
        model = Osuser
        fields = ('name', 'home', 'description',)
        labels = {
            'name': _('Username'),
            'home': _('Home Directory (optional)'),
            'description': _('Description (optional)'),
        }

    def __init__(self, *args, **kwargs):
        super(OsuserForm, self).__init__(*args, **kwargs)
        self.fields['name'].widget.attrs['placeholder'] = 'root, oracle, john, ...'
        self.fields['home'].widget.attrs['placeholder'] = '/root, /home/oracle, ...'
        self.fields['description'].widget.attrs['placeholder'] = ''

class PermissionForm(forms.ModelForm):
    class Meta:
        model = Permission
        fields = ('host', 'group', 'osuser',)

    def __init__(self, *args, **kwargs):
        super(PermissionForm, self).__init__(*args, **kwargs)
        self.fields['host'] = ModelMultipleChoiceFieldNames(queryset=Host.objects.all().order_by('name'), label='Select host(s) on which you want to set perssion(s):')

# Path: sshkm/models.py
# class Key(models.Model):
#     name = models.CharField(max_length=191, unique=True)
#     description = models.CharField(max_length=191, null=True, blank=True)
#     firstname = models.CharField(max_length=191, null=True, blank=True)
#     lastname = models.CharField(max_length=191, null=True, blank=True)
#     email = models.EmailField(max_length=191, null=True, blank=True)
#     publickey = models.TextField(null=True, blank=True)
#     member_of = models.ManyToManyField('Group', through='KeyGroup', blank=True)
# 
# class Group(models.Model):
#     name = models.CharField(max_length=191, unique=True)
#     description = models.CharField(max_length=191, null=True, blank=True)
#     members = models.ManyToManyField('Key', through='KeyGroup', blank=True)
# 
# class Host(models.Model):
#     name = models.CharField(max_length=191, unique=True)
#     superuser = models.CharField(max_length=191, null=True, blank=True)
#     description = models.CharField(max_length=191, null=True, blank=True)
#     status = models.CharField(max_length=10, null=True, blank=True)
#     last_status = models.DateTimeField(null=True, blank=True)
# 
# class Osuser(models.Model):
#     name = models.CharField(max_length=191, unique=True)
#     home = models.CharField(max_length=191, null=True, blank=True)
#     description = models.CharField(max_length=191, null=True, blank=True)
# 
# class KeyGroup(models.Model):
#     key = models.ForeignKey('Key', on_delete=models.CASCADE)
#     group = models.ForeignKey('Group', on_delete=models.CASCADE)
# 
# class Permission(models.Model):
#     group = models.ForeignKey(Group, on_delete=models.CASCADE)
#     host = models.ForeignKey(Host, on_delete=models.CASCADE)
#     osuser = models.ForeignKey(Osuser, on_delete=models.CASCADE)
# 
#     class Meta:
#         unique_together = ("group", "host", "osuser")


# Path: sshkm/forms.py
from django import forms
from .models import Key, Group, Host, Osuser, KeyGroup, Permission
from django.contrib.auth.models import User
from django.utils.translation import ugettext_lazy as _
from django.forms import ModelMultipleChoiceField

        super(HostForm, self).__init__(*args, **kwargs)
        self.fields['name'].widget.attrs['placeholder'] = 'host1.example.com or 192.168.1.33'
        self.fields['superuser'].widget.attrs['placeholder'] = 'default: root'
        self.fields['superuser'].label = 'Superuser (OS-User used to connect to your host to deploy all other keys)'
        self.fields['description'].widget.attrs['placeholder'] = ''

class OsuserForm(forms.ModelForm):
    class Meta:
        model = Osuser
        fields = ('name', 'home', 'description',)
        labels = {
            'name': _('Username'),
            'home': _('Home Directory (optional)'),
            'description': _('Description (optional)'),
        }

    def __init__(self, *args, **kwargs):
        super(OsuserForm, self).__init__(*args, **kwargs)
        self.fields['name'].widget.attrs['placeholder'] = 'root, oracle, john, ...'
        self.fields['home'].widget.attrs['placeholder'] = '/root, /home/oracle, ...'
        self.fields['description'].widget.attrs['placeholder'] = ''

class PermissionForm(forms.ModelForm):
    class Meta:
        model = Permission
        fields = ('host', 'group', 'osuser',)

    def __init__(self, *args, **kwargs):
        super(PermissionForm, self).__init__(*args, **kwargs)
        self.fields['host'] = ModelMultipleChoiceFieldNames(queryset=Host.objects.all().order_by('name'), label='Select host(s) on which you want to set perssion(s):')

        self.fields['group'] = ModelMultipleChoiceFieldNames(queryset=Group.objects.all().order_by('name'), label='Select the group(s) which has/have permission on the selected host(s):')