126 lines
4.2 KiB
Python
126 lines
4.2 KiB
Python
"""
|
|
Auction Forms
|
|
"""
|
|
|
|
from django import forms
|
|
from .models import Auction, Bid
|
|
|
|
|
|
class AuctionForm(forms.ModelForm):
|
|
"""Form für Auktion erstellen/bearbeiten"""
|
|
|
|
class Meta:
|
|
model = Auction
|
|
fields = [
|
|
'title', 'description', 'fursuit_type', 'character_description',
|
|
'reference_images', 'special_requirements', 'starting_bid',
|
|
'reserve_price', 'duration_days'
|
|
]
|
|
widgets = {
|
|
'title': forms.TextInput(attrs={
|
|
'class': 'form-control',
|
|
'placeholder': 'Auktion Titel'
|
|
}),
|
|
'description': forms.Textarea(attrs={
|
|
'class': 'form-control',
|
|
'rows': 4,
|
|
'placeholder': 'Beschreibung der Auktion'
|
|
}),
|
|
'fursuit_type': forms.Select(attrs={
|
|
'class': 'form-control'
|
|
}),
|
|
'character_description': forms.Textarea(attrs={
|
|
'class': 'form-control',
|
|
'rows': 6,
|
|
'placeholder': 'Detaillierte Beschreibung des Charakters...'
|
|
}),
|
|
'special_requirements': forms.Textarea(attrs={
|
|
'class': 'form-control',
|
|
'rows': 3,
|
|
'placeholder': 'Besondere Anforderungen (optional)'
|
|
}),
|
|
'starting_bid': forms.NumberInput(attrs={
|
|
'class': 'form-control',
|
|
'min': '0',
|
|
'step': '0.01',
|
|
'placeholder': '0.00'
|
|
}),
|
|
'reserve_price': forms.NumberInput(attrs={
|
|
'class': 'form-control',
|
|
'min': '0',
|
|
'step': '0.01',
|
|
'placeholder': 'Reserve Price (optional)'
|
|
}),
|
|
'duration_days': forms.NumberInput(attrs={
|
|
'class': 'form-control',
|
|
'min': '1',
|
|
'max': '30',
|
|
'placeholder': '7'
|
|
}),
|
|
}
|
|
|
|
def clean_starting_bid(self):
|
|
"""Starting Bid validieren"""
|
|
starting_bid = self.cleaned_data.get('starting_bid')
|
|
if starting_bid <= 0:
|
|
raise forms.ValidationError('Starting Bid muss größer als 0 sein')
|
|
return starting_bid
|
|
|
|
def clean_reserve_price(self):
|
|
"""Reserve Price validieren"""
|
|
reserve_price = self.cleaned_data.get('reserve_price')
|
|
starting_bid = self.cleaned_data.get('starting_bid')
|
|
|
|
if reserve_price and reserve_price <= starting_bid:
|
|
raise forms.ValidationError('Reserve Price muss höher als Starting Bid sein')
|
|
|
|
return reserve_price
|
|
|
|
def clean_duration_days(self):
|
|
"""Duration validieren"""
|
|
duration = self.cleaned_data.get('duration_days')
|
|
if duration < 1 or duration > 30:
|
|
raise forms.ValidationError('Duration muss zwischen 1 und 30 Tagen liegen')
|
|
return duration
|
|
|
|
|
|
class BidForm(forms.ModelForm):
|
|
"""Form für Gebot platzieren"""
|
|
|
|
class Meta:
|
|
model = Bid
|
|
fields = ['amount']
|
|
widgets = {
|
|
'amount': forms.NumberInput(attrs={
|
|
'class': 'form-control',
|
|
'min': '0',
|
|
'step': '0.01',
|
|
'placeholder': 'Dein Gebot'
|
|
})
|
|
}
|
|
|
|
def __init__(self, *args, **kwargs):
|
|
self.auction = kwargs.pop('auction', None)
|
|
super().__init__(*args, **kwargs)
|
|
|
|
if self.auction:
|
|
min_bid = self.auction.current_bid or self.auction.starting_bid
|
|
self.fields['amount'].widget.attrs['min'] = float(min_bid) + 0.01
|
|
self.fields['amount'].widget.attrs['placeholder'] = f'Min. €{float(min_bid) + 0.01}'
|
|
|
|
def clean_amount(self):
|
|
"""Amount validieren"""
|
|
amount = self.cleaned_data.get('amount')
|
|
|
|
if not self.auction:
|
|
raise forms.ValidationError('Auktion nicht gefunden')
|
|
|
|
if not self.auction.is_active:
|
|
raise forms.ValidationError('Auktion ist nicht aktiv')
|
|
|
|
min_bid = self.auction.current_bid or self.auction.starting_bid
|
|
|
|
if amount <= min_bid:
|
|
raise forms.ValidationError(f'Gebot muss höher als €{float(min_bid)} sein')
|
|
|
|
return amount |