Skip to content

Commit 31ef5d7

Browse files
author
=
committed
simpler copy to new lot code
1 parent f6c6c2e commit 31ef5d7

File tree

1 file changed

+19
-23
lines changed

1 file changed

+19
-23
lines changed

auctions/forms.py

+19-23
Original file line numberDiff line numberDiff line change
@@ -2102,29 +2102,25 @@ def __init__(self, *args, **kwargs):
21022102
# self.fields['species_search'].initial = self.instance.species.common_name.split(",")[0]
21032103
else:
21042104
if self.cloned_from:
2105-
try:
2106-
cloneLot = Lot.objects.get(pk=self.cloned_from, is_deleted=False)
2107-
if (cloneLot.user.pk == self.user.pk) or self.user.is_superuser:
2108-
# you can only clone your lots
2109-
cloneFields = [
2110-
"lot_name",
2111-
"quantity",
2112-
"species_category",
2113-
# "description",
2114-
"summernote_description",
2115-
"i_bred_this_fish",
2116-
"reserve_price",
2117-
"buy_now_price",
2118-
"reference_link",
2119-
"donation",
2120-
"custom_checkbox",
2121-
"custom_field_1",
2122-
]
2123-
for field in cloneFields:
2124-
self.fields[field].initial = getattr(cloneLot, field)
2125-
self.fields["cloned_from"].initial = int(self.cloned_from)
2126-
except:
2127-
pass
2105+
clone_from_lot = Lot.objects.filter(pk=self.cloned_from, is_deleted=False).first()
2106+
if clone_from_lot and ((clone_from_lot.user.pk == self.user.pk) or self.user.is_superuser):
2107+
# you can only clone your lots
2108+
cloneFields = [
2109+
"lot_name",
2110+
"quantity",
2111+
"species_category",
2112+
"summernote_description",
2113+
"i_bred_this_fish",
2114+
"reserve_price",
2115+
"buy_now_price",
2116+
"reference_link",
2117+
"donation",
2118+
"custom_checkbox",
2119+
"custom_field_1",
2120+
]
2121+
for field in cloneFields:
2122+
self.fields[field].initial = getattr(clone_from_lot, field)
2123+
self.fields["cloned_from"].initial = int(self.cloned_from)
21282124
# default to making new lots part of a club auction
21292125
self.fields["part_of_auction"].initial = "True"
21302126
self.fields["run_duration"].initial = 10

0 commit comments

Comments
 (0)