35 lines
1.1 KiB
Python
35 lines
1.1 KiB
Python
from django import forms
|
|
from .models import GeocodingTask
|
|
|
|
|
|
class GeocodingUploadForm(forms.ModelForm):
|
|
"""Form for uploading Excel files for geocoding"""
|
|
|
|
class Meta:
|
|
model = GeocodingTask
|
|
fields = ['uploaded_file']
|
|
widgets = {
|
|
'uploaded_file': forms.FileInput(attrs={
|
|
'class': 'form-control',
|
|
'accept': '.xls,.xlsx',
|
|
})
|
|
}
|
|
labels = {
|
|
'uploaded_file': 'Fichier Excel'
|
|
}
|
|
help_texts = {
|
|
'uploaded_file': 'Sélectionnez un fichier Excel (.xls ou .xlsx) contenant les adresses à géolocaliser'
|
|
}
|
|
|
|
def clean_uploaded_file(self):
|
|
file = self.cleaned_data.get('uploaded_file')
|
|
if file:
|
|
# Check file extension
|
|
if not file.name.lower().endswith(('.xls', '.xlsx')):
|
|
raise forms.ValidationError('Le fichier doit être au format Excel (.xls ou .xlsx)')
|
|
|
|
# Check file size (max 10MB)
|
|
if file.size > 10 * 1024 * 1024:
|
|
raise forms.ValidationError('Le fichier ne doit pas dépasser 10 Mo')
|
|
|
|
return file
|