from nextcloud.models import VMMachine from django import forms from django.core.exceptions import ValidationError from django.utils.translation import get_language, ugettext_lazy as _ from uncloud.forms import MainForm, DomainNameField class InitialRequestForm(MainForm): cores = forms.IntegerField(label='CPU', min_value=1, max_value=48, initial=1) memory = forms.IntegerField(label='RAM', min_value=2, max_value=200, initial=2) storage = forms.IntegerField(label='Storage', min_value=100, max_value=10000, initial=100) pricing_name = forms.CharField(required=True) class RequestDomainsNamesForm(MainForm): subdomain = forms.CharField(required=True, widget=forms.TextInput(attrs={'placeholder': 'Subdomain *'})) main_domain = forms.ChoiceField(required=True, choices= ( ('0co2.cloud', '.0co2.cloud'), ('glarner.cloud', '.glarner.cloud') )) def clean(self): cleaned_data = super().clean() subdomain = cleaned_data['subdomain'] main_domain = cleaned_data['main_domain'] if VMMachine.objects.filter(domain=f"{subdomain}.{main_domain}").exists(): raise ValidationError("domain name already exists") return cleaned_data