feat: re-add DateWidget but only if creating
This commit is contained in:
parent
52335d0eb3
commit
d14b88e99d
@ -51,6 +51,15 @@ class AdoptionNoticeForm(forms.ModelForm):
|
|||||||
fields = ['name', "group_only", "further_information", "description", "searching_since", "location_string"]
|
fields = ['name', "group_only", "further_information", "description", "searching_since", "location_string"]
|
||||||
|
|
||||||
|
|
||||||
|
class AdoptionNoticeFormWithDateWidget(AdoptionNoticeForm):
|
||||||
|
class Meta:
|
||||||
|
model = AdoptionNotice
|
||||||
|
fields = ['name', "group_only", "further_information", "description", "searching_since", "location_string"]
|
||||||
|
widgets = {
|
||||||
|
'searching_since': DateInput(),
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
class AnimalForm(forms.ModelForm):
|
class AnimalForm(forms.ModelForm):
|
||||||
def __init__(self, *args, **kwargs):
|
def __init__(self, *args, **kwargs):
|
||||||
if 'in_adoption_notice_creation_flow' in kwargs:
|
if 'in_adoption_notice_creation_flow' in kwargs:
|
||||||
@ -71,6 +80,15 @@ class AnimalForm(forms.ModelForm):
|
|||||||
fields = ["name", "date_of_birth", "species", "sex", "description"]
|
fields = ["name", "date_of_birth", "species", "sex", "description"]
|
||||||
|
|
||||||
|
|
||||||
|
class AnimalFormWithDateWidget(AnimalForm):
|
||||||
|
class Meta:
|
||||||
|
model = Animal
|
||||||
|
fields = ["name", "date_of_birth", "species", "sex", "description"]
|
||||||
|
widgets = {
|
||||||
|
'date_of_birth': DateInput(),
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
class ImageForm(forms.ModelForm):
|
class ImageForm(forms.ModelForm):
|
||||||
def __init__(self, *args, **kwargs):
|
def __init__(self, *args, **kwargs):
|
||||||
if 'in_flow' in kwargs:
|
if 'in_flow' in kwargs:
|
||||||
|
@ -11,10 +11,11 @@ from .mail import mail_admins_new_report
|
|||||||
from notfellchen import settings
|
from notfellchen import settings
|
||||||
|
|
||||||
from fellchensammlung import logger
|
from fellchensammlung import logger
|
||||||
from fellchensammlung.models import AdoptionNotice, Text, Animal, Rule, Image, Report, ModerationAction, \
|
from .models import AdoptionNotice, Text, Animal, Rule, Image, Report, ModerationAction, \
|
||||||
User, Location
|
User, Location, AdoptionNoticeStatus
|
||||||
from .forms import AdoptionNoticeForm, ImageForm, ReportAdoptionNoticeForm, CommentForm, ReportCommentForm, AnimalForm, \
|
from .forms import AdoptionNoticeForm, AdoptionNoticeFormWithDateWidget, ImageForm, ReportAdoptionNoticeForm, \
|
||||||
AdoptionNoticeSearchForm
|
CommentForm, ReportCommentForm, AnimalForm, \
|
||||||
|
AdoptionNoticeSearchForm, AnimalFormWithDateWidget
|
||||||
from .models import Language, Announcement
|
from .models import Language, Announcement
|
||||||
from .tools.geo import GeoAPI
|
from .tools.geo import GeoAPI
|
||||||
from .tools.metrics import gather_metrics_data
|
from .tools.metrics import gather_metrics_data
|
||||||
@ -127,14 +128,14 @@ def add_adoption_notice(request):
|
|||||||
|
|
||||||
return redirect(reverse("adoption-notice-add-animal", args=[instance.pk]))
|
return redirect(reverse("adoption-notice-add-animal", args=[instance.pk]))
|
||||||
else:
|
else:
|
||||||
form = AdoptionNoticeForm(in_adoption_notice_creation_flow=True)
|
form = AdoptionNoticeFormWithDateWidget(in_adoption_notice_creation_flow=True)
|
||||||
return render(request, 'fellchensammlung/forms/form_add_adoption.html', {'form': form})
|
return render(request, 'fellchensammlung/forms/form_add_adoption.html', {'form': form})
|
||||||
|
|
||||||
|
|
||||||
@login_required
|
@login_required
|
||||||
def adoption_notice_add_animal(request, adoption_notice_id):
|
def adoption_notice_add_animal(request, adoption_notice_id):
|
||||||
if request.method == 'POST':
|
if request.method == 'POST':
|
||||||
form = AnimalForm(request.POST, request.FILES)
|
form = AnimalFormWithDateWidget(request.POST, request.FILES)
|
||||||
|
|
||||||
if form.is_valid():
|
if form.is_valid():
|
||||||
instance = form.save(commit=False)
|
instance = form.save(commit=False)
|
||||||
@ -142,12 +143,12 @@ def adoption_notice_add_animal(request, adoption_notice_id):
|
|||||||
instance.save()
|
instance.save()
|
||||||
form.save_m2m()
|
form.save_m2m()
|
||||||
if "save-and-add-another-animal" in request.POST:
|
if "save-and-add-another-animal" in request.POST:
|
||||||
form = AnimalForm(in_adoption_notice_creation_flow=True)
|
form = AnimalFormWithDateWidget(in_adoption_notice_creation_flow=True)
|
||||||
return render(request, 'fellchensammlung/forms/form_add_animal_to_adoption.html', {'form': form})
|
return render(request, 'fellchensammlung/forms/form_add_animal_to_adoption.html', {'form': form})
|
||||||
else:
|
else:
|
||||||
return redirect(reverse("adoption-notice-detail", args=[adoption_notice_id]))
|
return redirect(reverse("adoption-notice-detail", args=[adoption_notice_id]))
|
||||||
else:
|
else:
|
||||||
form = AnimalForm(in_adoption_notice_creation_flow=True)
|
form = AnimalFormWithDateWidget(in_adoption_notice_creation_flow=True)
|
||||||
return render(request, 'fellchensammlung/forms/form_add_animal_to_adoption.html', {'form': form})
|
return render(request, 'fellchensammlung/forms/form_add_animal_to_adoption.html', {'form': form})
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user