# Path: upribox_interface/vpn/models.py
# class VpnProfile(models.Model):
#     profilename = models.CharField(max_length=32)
#     config = models.TextField()
#     creation_date = models.DateField(auto_now_add=True)
#     # first slug - this field is used to reference the object, e.g. when creating a download link or when deleting
#     slug = autoslug.AutoSlugField(unique=True, populate_from=utils.secure_random_id)
#     # second slug - this field is used for the download link
#     download_slug = autoslug.AutoSlugField(unique=True, populate_from=utils.secure_random_id, always_update=True, null=True)
#     download_valid_until = models.DateTimeField(null=True)
#     dyndomain = models.CharField(max_length=256)
# 
#     class Meta:
#         ordering = ["creation_date"]


import logging
from django import forms
from django.utils.translation import ugettext_lazy
from lib import domain
from lib.utils import get_fact
from .models import VpnProfile
    profilename = forms.CharField(
        required=True,
        label=ugettext_lazy("Name:"),
        max_length=64,
    )

    dyndomain = forms.CharField(
        required=True,
        label=ugettext_lazy("Domain:"),
        max_length=64,
    )

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

        upri_dns_domain = None

        try:
            upri_dns_domain = get_fact('dns', 'dns', 'hostname')
        except:
            logger.error('Kein upri DNS fact gefunden.')

        if upri_dns_domain:
            self.fields['dyndomain'].widget = forms.HiddenInput()
            self.fields['dyndomain'].initial = upri_dns_domain
            self.fields['dyndomain'].label = ""

    def clean_profilename(self):
        profilename = self.cleaned_data['profilename']
        try:

# Path: upribox_interface/vpn/models.py
# class VpnProfile(models.Model):
#     profilename = models.CharField(max_length=32)
#     config = models.TextField()
#     creation_date = models.DateField(auto_now_add=True)
#     # first slug - this field is used to reference the object, e.g. when creating a download link or when deleting
#     slug = autoslug.AutoSlugField(unique=True, populate_from=utils.secure_random_id)
#     # second slug - this field is used for the download link
#     download_slug = autoslug.AutoSlugField(unique=True, populate_from=utils.secure_random_id, always_update=True, null=True)
#     download_valid_until = models.DateTimeField(null=True)
#     dyndomain = models.CharField(max_length=256)
# 
#     class Meta:
#         ordering = ["creation_date"]


# Path: upribox_interface/vpn/forms.py
import logging
from django import forms
from django.utils.translation import ugettext_lazy
from lib import domain
from lib.utils import get_fact
from .models import VpnProfile

    profilename = forms.CharField(
        required=True,
        label=ugettext_lazy("Name:"),
        max_length=64,
    )

    dyndomain = forms.CharField(
        required=True,
        label=ugettext_lazy("Domain:"),
        max_length=64,
    )

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

        upri_dns_domain = None

        try:
            upri_dns_domain = get_fact('dns', 'dns', 'hostname')
        except:
            logger.error('Kein upri DNS fact gefunden.')

        if upri_dns_domain:
            self.fields['dyndomain'].widget = forms.HiddenInput()
            self.fields['dyndomain'].initial = upri_dns_domain
            self.fields['dyndomain'].label = ""

    def clean_profilename(self):
        profilename = self.cleaned_data['profilename']
        try:

            VpnProfile.objects.get(profilename=profilename)