Skip to content

Commit

Permalink
Merge pull request #167 from gcivil-nyu-org/pending-matches
Browse files Browse the repository at this point in the history
Fixed bug for sdate, edate for the trips to consider
  • Loading branch information
sawyer1997 committed Nov 18, 2023
2 parents 09bfa5d + d8da8f7 commit d5130a5
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 11 deletions.
17 changes: 13 additions & 4 deletions matching/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,24 @@ def show_potential_matches(request, utrip_id):
messages.error(request, "Please select a valid trip")
return redirect(reverse("trip:view_trips"))

# applying dynamic filter to generate match pool
# applying dynamic filter to generate match pool where
# usertrip is active AND
# travel_type = companion AND
# destination is matching AND
# trip dates are overlapping (for at least 1 day) AND
# user is not deactivated AND
# user's age is in defined range
matching_trips = UserTrip.objects.filter(
start_trip__lt=current_usertrip.end_trip,
is_active=True,
start_trip__lte=current_usertrip.end_trip,
end_trip__gte=current_usertrip.start_trip,
travel_type=current_usertrip.travel_type,
trip=current_usertrip.trip,
user__userprofile__dob__lt=date.today()
user__is_active=True,
user__userprofile__dob__lte=date.today()
- timedelta(days=365.25 * current_user.userprofile.age_lower),
user__userprofile__dob__gt=date.today()
- timedelta(days=365.25 * current_user.userprofile.age_upper),
- timedelta(days=365.25 * current_user.userprofile.age_upper + 1),
)

try:
Expand Down
2 changes: 1 addition & 1 deletion trip/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

def start_date_in_future(std):
if isinstance(std, datetime.date):
return std > datetime.date.today()
return std >= datetime.date.today()
else:
raise TypeError("Arguments must be of type datetime.date")

Expand Down
21 changes: 15 additions & 6 deletions trip/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,6 @@ def create_trip(request):
if usertrip_creation_form.is_valid():
usertrip_data = usertrip_creation_form.cleaned_data

usertrip_instance = usertrip_creation_form.save(commit=False)

dest_city_raw = usertrip_data["destination_city_ef"]
dest_city = dest_city_raw[0]

Expand All @@ -28,10 +26,21 @@ def create_trip(request):
destination_country=dest_country,
)

usertrip_instance.trip = trip_instance
usertrip_instance.user = request.user
usertrip_instance.save()
messages.success(request, "Successfully created your trip")
usertrip_instance, created = UserTrip.objects.get_or_create(
start_trip=usertrip_data["start_trip"],
end_trip=usertrip_data["end_trip"],
user=request.user,
trip=trip_instance,
)

if created:
messages.success(request, "Successfully created your trip")
else:
messages.info(
request,
"You already have an existing trip with same details, "
"might wanna update the trip?",
)
return redirect(reverse("trip:view_trips"))
else:
usertrip_creation_form = forms.UserTripCreationForm()
Expand Down

0 comments on commit d5130a5

Please sign in to comment.