| from django import forms | |
| from .widgets import MultipleFileInput | |
| from django.core.exceptions import ValidationError | |
| class ImageUploadForm(forms.Form): | |
| image = forms.ImageField( | |
| widget=forms.ClearableFileInput(attrs={ | |
| 'class': 'form-control', | |
| 'capture': 'user' | |
| }) | |
| ) | |
| class ClassificationForm(forms.Form): | |
| claim = forms.CharField( | |
| label="Claim:", | |
| widget=forms.Textarea(attrs={ | |
| 'class': 'form-control', | |
| 'rows': 5, | |
| 'placeholder': 'Enter your claim or statement', | |
| }) | |
| ) | |
| class RegisterFaceForm(forms.Form): | |
| person = forms.CharField( | |
| label="Person:", | |
| widget=forms.TextInput(attrs={ | |
| 'class': 'form-control', | |
| 'placeholder': 'e.g: ANWAR IBRAHIM', | |
| }) | |
| ) | |
| keywords = forms.CharField( | |
| label="Keyword:", | |
| required=False, | |
| widget=forms.TextInput(attrs={ | |
| 'class': 'form-control', | |
| 'placeholder': 'e.g: Prime Minister of Malaysia', | |
| }) | |
| ) | |
| images = forms.FileField( | |
| required=False, | |
| widget=MultipleFileInput(attrs={ | |
| 'multiple': True, | |
| 'class': 'form-control', | |
| 'capture': 'user' | |
| }) | |
| ) | |
| class TranscribeForm(forms.Form): | |
| url = forms.CharField( | |
| label="YouTube URL:", | |
| required=False, | |
| widget=forms.TextInput(attrs={ | |
| 'type': 'url', | |
| 'class': 'form-control', | |
| 'placeholder': 'Enter YouTube URL', | |
| }) | |
| ) | |
| file = forms.FileField( | |
| label="Upload Audio/Video File", | |
| required=False, | |
| widget=forms.ClearableFileInput(attrs={ | |
| 'class': 'form-control', | |
| 'accept': 'audio/*,video/*', | |
| }) | |
| ) | |
| def clean(self): | |
| cleaned_data = super().clean() | |
| url = cleaned_data.get("url") | |
| file = cleaned_data.get("file") | |
| if not url and not file: | |
| raise ValidationError("You must provide either a YouTube URL or upload a file.") | |
| if url and file: | |
| raise ValidationError("Please provide only one: YouTube URL or a file upload.") | |
| class YouTubeURLForm(forms.Form): | |
| youtube_url = forms.URLField( | |
| label='YouTube Video URL', | |
| widget=forms.URLInput(attrs={ | |
| 'class': 'form-control', | |
| 'placeholder': 'https://www.youtube.com/watch?v=example' | |
| }) | |
| ) | |