Skip to content

armgit / wger

Public Imported from GitHub
0

Self hosted FLOSS fitness/workout, nutrition and weight tracker

Fixed error when importing duplicate CSV entries

purplebird6295b602fd4a
diff --git a/wger/weight/helpers.py b/wger/weight/helpers.py
index a13f478ed..670d9a736 100644
--- a/wger/weight/helpers.py
+++ b/wger/weight/helpers.py
@@ -44,6 +44,7 @@ def parse_weight_csv(request, cleaned_data):
parsed_csv = csv.reader(six.StringIO(cleaned_data['csv_input']),
dialect)
distinct_weight_entries = []
+ entry_dates = set()
weight_list = []
error_list = []
@@ -54,13 +55,15 @@ def parse_weight_csv(request, cleaned_data):
parsed_weight = decimal.Decimal(row[1].replace(',', '.'))
duplicate_date_in_db = WeightEntry.objects.filter(date=parsed_date,
user=request.user).exists()
- # within the list there are no duplicates
- unique_among_csv = (parsed_date, parsed_weight) not in distinct_weight_entries
+ # within the list there are no duplicate dates
+ unique_among_csv = parsed_date not in entry_dates
+
# there is no existing weight entry in the database for that date
unique_in_db = not duplicate_date_in_db
if unique_among_csv and unique_in_db:
distinct_weight_entries.append((parsed_date, parsed_weight))
+ entry_dates.add(parsed_date)
else:
error_list.append(row)