from django import forms from dbsynce.models import ServiceType, Service, Company from webservice_running.models import Comments, Tasks from django.contrib.auth import get_user_model class ServiceTariffUpdateForm(forms.ModelForm): def __init__(self, *args, **kwargs): super(ServiceTariffUpdateForm, self).__init__(*args, **kwargs) # Добавляет стиль бутстрапа form-control всем полям таблицы если у них нет своих стилей for field in iter(self.fields): if 'class' not in self.fields[field].widget.attrs: self.fields[field].widget.attrs.update({'class':'form-control'}) class Meta: model = Service fields = ['status','ticket_status','servicetype_id','id_provider', 'resource_id','requirements','price_alg','price_km','price_min','price_amount','service_status', 'is_global','is_visible'] widgets = { 'status': forms.TextInput(attrs={'readonly': True}, ), 'ticket_status': forms.TextInput(attrs={'readonly': True}), 'servicetype_id': forms.Select(attrs={'class': 'form-select'}), 'id_provider': forms.Select(attrs={'class': 'form-select'}), 'resource_id': forms.Select(attrs={'class': 'form-select'}), } class ServiceTariffCreateForm(forms.ModelForm): def __init__(self, *args, **kwargs): super(ServiceTariffCreateForm, self).__init__(*args, **kwargs) # Добавляет стиль бутстрапа form-control всем полям таблицы если у них нет своих стилей for field in iter(self.fields): if 'class' not in self.fields[field].widget.attrs: self.fields[field].widget.attrs.update({'class':'form-control'}) class Meta: model = Service fields = '__all__' widgets = { 'servicetype_id': forms.Select(attrs={'class': 'form-select'}), 'id_provider': forms.Select(attrs={'class': 'form-select'}), 'resource_id': forms.Select(attrs={'class': 'form-select'}), 'ticket_status': forms.TextInput(attrs={'readonly': True}), } class ServiceTypeUpdateForm(forms.ModelForm): def __init__(self, *args, **kwargs): super(ServiceTypeUpdateForm, self).__init__(*args, **kwargs) class Meta: model = ServiceType fields = ['codename','requirements','price_type','description', 'caption', 'status', 'id_metaservice', 'ticket_status', 'link_agreement', 'is_global','is_visible'] widgets = { 'status': forms.TextInput(attrs={'readonly': True}), 'ticket_status': forms.TextInput(attrs={'readonly': True}), } PRICE_CHOICES = [ ('one', 'text #1'), ('two', 'text #2'), ('three', 'text #3'), ] class ServiceTypeCreateForm(forms.ModelForm): codename = forms.CharField(label="Название услуги") caption = forms.CharField(label="Полное название") requirements = forms.CharField(label="Требования") price_type = forms.ChoiceField(choices=PRICE_CHOICES, label="Ценообразование") status = forms.CharField(label="Статус") description = forms.CharField(label="Описание") id_metaservice = forms.IntegerField(label="ID метасервиса") link_agreement = forms.CharField(label="Ссылка на договор вики") is_global = forms.BooleanField(label="Доступно во всех сервисах", required=False) is_visible = forms.BooleanField(label="Доступно для планирования цепочек во всех сервисах", required=False) def __init__(self, *args, **kwargs): super(ServiceTypeCreateForm, self).__init__(*args, **kwargs) class Meta: model = ServiceType fields = ['codename','requirements', 'price_type', 'description', 'caption', 'status', 'id_metaservice', 'ticket_status', 'link_agreement', 'is_global','is_visible', ] widgets = { } class CommentsCreateForm(forms.ModelForm): task_description = forms.CharField(label="Описание задачи") is_global = forms.BooleanField(label="Доступно во всех сервисах", required=False) is_visible = forms.BooleanField(label="Доступно для планирования цепочек во всех сервисах", required=False) def __init__(self, *args, **kwargs): super(CommentsCreateForm, self).__init__(*args, **kwargs) class Meta: model = Comments fields = ['description','user_id', 'ticket_status', 'id_metaservice', 'is_global','is_visible',] widgets = { } class TasksCreateForm(forms.ModelForm): description = forms.CharField(label="Описание") is_global = forms.BooleanField(label="Доступно во всех сервисах", required=False) is_visible = forms.BooleanField(label="Доступно для планирования цепочек во всех сервисах", required=False) def __init__(self, *args, **kwargs): super(TasksCreateForm, self).__init__(*args, **kwargs) class Meta: model = Tasks fields = ['task_description','repr_id','user_id','dead_line', 'ticket_status', 'id_metaservice', 'is_global','is_visible',] widgets = { } class ServiceInformationUpdateForm(forms.ModelForm): def __init__(self, *args, **kwargs): super(ServiceInformationUpdateForm, self).__init__(*args, **kwargs) # Добавляет стиль бутстрапа form-control всем полям таблицы если у них нет своих стилей for field in iter(self.fields): if 'class' not in self.fields[field].widget.attrs: self.fields[field].widget.attrs.update({'class':'form-control'}) class Meta: model = Service fields = ['servicetype_id', 'id_provider'] widgets = { # 'status': forms.TextInput(attrs={'readonly': True}), # 'ticket_status': forms.TextInput(attrs={'readonly': True}), 'servicetype_id': forms.Select(attrs={'class': 'form-select'}), #'repr_id': forms.Select(attrs={'class': 'form-select'}), # 'resource_id': forms.Select(attrs={'class': 'form-select'}), } class ServiceInformationCreateForm(forms.ModelForm): def __init__(self, *args, **kwargs): super(ServiceInformationCreateForm, self).__init__(*args, **kwargs) # Добавляет стиль бутстрапа form-control всем полям таблицы если у них нет своих стилей for field in iter(self.fields): if 'class' not in self.fields[field].widget.attrs: self.fields[field].widget.attrs.update({'class':'form-control'}) class Meta: model = Service fields = "__all__" exclude = ["id", "is_global", "is_visible", "ticket_status", "id_metaservice", "resource_id"] widgets = { #'servicetype_id': forms.CharField(max_length=255) # 'legal_name': forms.TextInput(label = 'Название') # 'servicetype_id': forms.Select(attrs={'class': 'form-select'}), #'repr_id': forms.Select(attrs={'class': 'form-select'}), # 'resource_id': forms.Select(attrs={'class': 'form-select'}), # 'ticket_status': forms.Select(attrs={'class': 'form-select'}), } class PartnerInformationUpdateForm(forms.ModelForm): def __init__(self, *args, **kwargs): super(PartnerInformationUpdateForm, self).__init__(*args, **kwargs) # Добавляет стиль бутстрапа form-control всем полям таблицы если у них нет своих стилей for field in iter(self.fields): if 'class' not in self.fields[field].widget.attrs: self.fields[field].widget.attrs.update({'class':'form-control'}) class Meta: model = Company fields = "__all__" exclude = ["id", "ticket_status", "is_global", "is_visible", "id_metaservice", "status" ] widgets = { 'description': forms.Select(attrs={'class': 'form-select'}), 'repr_id': forms.Select(attrs={'class': 'form-select'}), } class PartnerInformationCreateForm(forms.ModelForm): def __init__(self, *args, **kwargs): super(PartnerInformationCreateForm, self).__init__(*args, **kwargs) for field in iter(self.fields): if 'class' not in self.fields[field].widget.attrs: self.fields[field].widget.attrs.update({'class':'form-control'}) # legal_name = forms.Fi() class Meta: model = Company fields = "__all__" exclude = ["id", "ticket_status", "is_global", "is_visible", "id_metaservice", "status" ] widgets = { 'description': forms.Select(attrs={'class': 'form-select'}), 'repr_id': forms.Select(attrs={'class': 'form-select'}), } # username = forms.CharField(label="Номер телефона", # widget=forms.TextInput(attrs={'class':'form-control'})) class UserDataForm(forms.ModelForm): password1 = forms.CharField(label="Пароль", widget=forms.PasswordInput(attrs={'class':'form-control'})) password2 = forms.CharField(label="Подтверждение пароля", widget=forms.PasswordInput(attrs={'class':'form-control'})) phone_number = forms.CharField(label="Номер телефона", widget=forms.TextInput(attrs={'class':'form-control'})) email = forms.CharField(label="Email", widget=forms.TextInput(attrs={'class':'form-control'})) username = forms.CharField(label="Имя пользователя", widget=forms.TextInput(attrs={'class':'form-control'})) first_name = forms.CharField(label="Имя", widget=forms.TextInput(attrs={'class':'form-control'})) last_name = forms.CharField(label="Фамилия", widget=forms.TextInput(attrs={'class':'form-control'})) def __init__(self, *args, **kwargs): super(UserDataForm, self).__init__(*args, **kwargs) class Meta: model = get_user_model() fields = ['username', 'first_name', 'last_name', 'avatar', 'phone_number', "email", 'password1', 'password2' ] widgets = { }