Skip to content

Commit

Permalink
Merge pull request #51 from ateliware/refactor/change-city-to-ride-or…
Browse files Browse the repository at this point in the history
…igin-in-ride-views

Refactor/change city to ride origin in ride views
  • Loading branch information
victorbilly authored May 20, 2024
2 parents 15fe4ac + b0020b3 commit 333f14f
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 12 deletions.
15 changes: 7 additions & 8 deletions apps/ride_manager/views/ride.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
Ride,
StatusChoices as RideStatusChoices,
)
from apps.ride_manager.models.ride_origin import RideOrigin
from apps.ride_manager.models.vehicle import Vehicle


Expand All @@ -42,7 +43,7 @@ def create_ride(request):
affected_places = AffectedPlace.objects.filter(is_active=True).order_by(
"city"
)
cities = City.objects.all()
origins = RideOrigin.objects.all()

if request.method == "POST":
form = RideForm(request.POST, request.FILES)
Expand Down Expand Up @@ -72,7 +73,7 @@ def create_ride(request):
{
"form": form,
"vehicle": vehicle,
"cities": cities,
"origins": origins,
"affected_places": affected_places,
},
)
Expand Down Expand Up @@ -139,8 +140,8 @@ def ride_list(request):
date = request.GET.get("date")

if origin:
city = City.objects.get(id=origin)
applyed_filters_str = f"Filtrando por: saindo de {city}"
origin_city = RideOrigin.objects.get(id=origin)
applyed_filters_str = f"Filtrando por: saindo de {origin_city}"
filters["origin"] = origin

if destination:
Expand Down Expand Up @@ -182,11 +183,11 @@ def ride_list(request):
affected_places = AffectedPlace.objects.filter(is_active=True).order_by(
"city"
)
cities = City.objects.all().order_by("name")
origins = RideOrigin.objects.filter(enabled=True).order_by("city__name")
context = {
"rides": rides,
"affected_places": affected_places,
"cities": cities,
"origins": origins,
"filters": applyed_filters_str,
}
return render(request, "ride/list_ride.html", context)
Expand Down Expand Up @@ -349,9 +350,7 @@ def mount_header(request):

# mounting back link dynamically
referer = request.META.get("HTTP_REFERER")
print(referer)
if referer != request.build_absolute_uri("/") + "rides/":
application_url = request.build_absolute_uri("/")
referer = application_url + "ride/my-rides"
print(referer)
return message, referer
4 changes: 2 additions & 2 deletions apps/templates/ride/create_ride.html
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,8 @@ <h5 class="card-title"><i class="fas fa-car"></i> {{ vehicle.model }} </h5>
<label for="origin" class="form-label">Origem</label>
<select class="form-control" id="origin" name="origin" required>
<option value="">Selecione a origem</option>
{% for city in cities %}
<option value="{{ city.id }}">{{ city }}</option>
{% for origin in origins %}
<option value="{{ origin.id }}">{{ origin }}</option>
{% endfor %}
</select>
<!-- Display origin field errors -->
Expand Down
4 changes: 2 additions & 2 deletions apps/templates/ride/list_ride.html
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@ <h5 class="mb-0">
<label for="origin">Origem<small>*</small></label>
<select class="form-control" id="origin" name="origin" required>
<option value="">Selecione a origem</option>
{% for city in cities %}
<option value="{{ city.id }}">{{ city }}</option>
{% for origin in origins %}
<option value="{{ origin.id }}">{{ origin }}</option>
{% endfor %}
</select>
</div>
Expand Down

0 comments on commit 333f14f

Please sign in to comment.