from django import forms from django.core.exceptions import ValidationError from django.core import validators from .models import ( Organization, NewsAndArticlesCategory, NewsAndArticles, Newsletter, FaqCategory, Faqs, Education, ) from goodtimes import constants from accounts import resource_action class OrganizationForm(forms.ModelForm): class Meta: model = Organization fields = [ "title", "contact_us_email", "instagram_handle", "facebook_handle", "linkedin_handle", "logo_image", "favicon_image", "website_url", ] labels = { "title": "Organization Title", "contact_us_email": "Contact Email", "instagram_handle": "Instagram URL", "facebook_handle": "Facebook URL", "linkedin_handle": "LinkedIn URL", "logo_image": "Organization Logo", "favicon_image": "Favicon", "website_url": "Website URL", } class NewsAndArticleCategoryForm(forms.ModelForm): class Meta: model = NewsAndArticlesCategory fields = ["name"] labels = {"name": "Category Name"} class NewsAndArticlesForm(forms.ModelForm): image_url = forms.ImageField() class Meta: model = NewsAndArticles fields = [ "title", "small_description", "long_description", "image_url", "video_url", "article_category", "tags", "active", ] labels = { "title": "Article Title", "small_description": "Small Description", "long_description": "Long Description", "image_url": "Image", "video_url": "Video URL", "article_category": "Article Category", "tags": "Tags", "active": "Active", } def __init__(self, *args, **kwargs): instance = kwargs.get("instance") super().__init__(*args, **kwargs) # Fetch the choices for the article_category field from the database self.fields["article_category"].queryset = ( NewsAndArticlesCategory.objects.filter(deleted=False) ) if instance is None: # This is an add operation, exclude the 'active' field self.fields.pop("active") class AboutUsForm(forms.ModelForm): class Meta: model = Organization fields = ["about_us"] labels = {"about_us": "Enter information about your organization:"} class TermsAndConditionForm(forms.ModelForm): class Meta: model = Organization fields = ["terms_condition"] labels = {"terms_condition": "Enter Terms and Conditions:"} class PrivacyPolicyForm(forms.ModelForm): class Meta: model = Organization fields = ["privacy_policy"] labels = {"privacy_policy": "Enter Privacy Police:"} class FaqCategoryFrom(forms.ModelForm): class Meta: model = FaqCategory fields = ["name"] labels = {"name": "Category name"} class FaqsForm(forms.ModelForm): class Meta: model = Faqs fields = [ # "faq_category", "question", "answer", "active", ] # labels = {"faq_category": "Category"} def __init__(self, *args, **kwargs): instance = kwargs.get("instance") super().__init__(*args, **kwargs) # Fetch the choices for the faq_category field from the database # self.fields["faq_category"].queryset = FaqCategory.objects.all() if instance is None: # This is an add operation, exclude the 'active' field self.fields.pop("active") class EducationVideoForm(forms.ModelForm): published_at = forms.DateTimeField() withdrawn_at = forms.DateTimeField() thumbnail = forms.ImageField() class Meta: model = Education fields = [ "content_type", "title", "description", "thumbnail", "video_url", "tags", "published_at", "withdrawn_at", "active", ] labels = { "content_type": "Type", "title": "Title", "description": "Description", "thumbnail": "Thumbnail", "video_url": "Video Url", "tags": "Tags", "published_at": "Publish Date", "withdrawn_at": "Withdrawn Date", "active": "Active", } def __init__(self, *args, **kwargs): instance = kwargs.get("instance") super().__init__(*args, **kwargs) self.fields["content_type"].initial = Education.VIDEO self.fields["content_type"].widget = forms.HiddenInput() if instance is None: self.fields.pop("active") class EducationMaterialForm(forms.ModelForm): published_at = forms.DateTimeField() withdrawn_at = forms.DateTimeField() file = forms.FileField() class Meta: model = Education fields = [ "content_type", "title", "file", "tags", "published_at", "withdrawn_at", "active", ] labels = { "content_type": "Type", "title": "Title", "file": "Upload File", "tags": "Tags", "published_at": "Publish Date", "withdrawn_at": "Withdrawn Date", "active": "Active", } def __init__(self, *args, **kwargs): instance = kwargs.get("instance") super().__init__(*args, **kwargs) self.fields["content_type"].initial = Education.MATERIAL self.fields["content_type"].widget = forms.HiddenInput() if instance is None: self.fields.pop("active")