# 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
        labels = {
            'name': _('Name (unique)'),
            'email': _('Email (optional)'),
            'description': _('Description (optional)'),
            'firstname': _('Firstname (optional)'),
            'lastname': _('Lastname (optional)'),
            'publickey': _('Public Key'),
        }

    def __init__(self, *args, **kwargs):
        super(KeyForm, self).__init__(*args, **kwargs)
        self.fields['member_of'] = ModelMultipleChoiceFieldNames(queryset=Group.objects.all(), required=False, label='Member of Group(s)')
        self.fields['name'].widget.attrs['placeholder'] = ''
        self.fields['email'].widget.attrs['placeholder'] = ''
        self.fields['firstname'].widget.attrs['placeholder'] = ''
        self.fields['lastname'].widget.attrs['placeholder'] = ''
        self.fields['description'].widget.attrs['placeholder'] = ''
        self.fields['publickey'].widget.attrs['placeholder'] = 'ssh-rsa AAAAB3NzaC1yc......== user@example.com'

class GroupForm(forms.ModelForm):
    class Meta:
        model = Group
        fields = ('name', 'description', 'members',)
        labels = {
            'name': _('Groupname (department, external company, remote hostgroup, ...)'),
            'description': _('Description (optional)'),
        }

    def __init__(self, *args, **kwargs):
        super(GroupForm, self).__init__(*args, **kwargs)

# 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

        labels = {
            'name': _('Name (unique)'),
            'email': _('Email (optional)'),
            'description': _('Description (optional)'),
            'firstname': _('Firstname (optional)'),
            'lastname': _('Lastname (optional)'),
            'publickey': _('Public Key'),
        }

    def __init__(self, *args, **kwargs):
        super(KeyForm, self).__init__(*args, **kwargs)
        self.fields['member_of'] = ModelMultipleChoiceFieldNames(queryset=Group.objects.all(), required=False, label='Member of Group(s)')
        self.fields['name'].widget.attrs['placeholder'] = ''
        self.fields['email'].widget.attrs['placeholder'] = ''
        self.fields['firstname'].widget.attrs['placeholder'] = ''
        self.fields['lastname'].widget.attrs['placeholder'] = ''
        self.fields['description'].widget.attrs['placeholder'] = ''
        self.fields['publickey'].widget.attrs['placeholder'] = 'ssh-rsa AAAAB3NzaC1yc......== user@example.com'

class GroupForm(forms.ModelForm):
    class Meta:
        model = Group
        fields = ('name', 'description', 'members',)
        labels = {
            'name': _('Groupname (department, external company, remote hostgroup, ...)'),
            'description': _('Description (optional)'),
        }

    def __init__(self, *args, **kwargs):
        super(GroupForm, self).__init__(*args, **kwargs)

        self.fields['members'] = ModelMultipleChoiceFieldNames(queryset=Key.objects.all(), required=False, label='Members (Key(s))')