From e4f6670c45c2d9116aa9ca3dd40c3c0f6145aa8b Mon Sep 17 00:00:00 2001 From: Thomas Steen Rasmussen Date: Thu, 11 Jul 2019 20:48:14 +0200 Subject: [PATCH] fixup rideshare a bit --- src/rideshare/admin.py | 2 +- src/rideshare/migrations/0003_ride_has_car.py | 18 ++++++++++++++ .../migrations/0004_auto_20190711_2036.py | 18 ++++++++++++++ .../migrations/0005_ride_to_location.py | 19 +++++++++++++++ src/rideshare/models.py | 11 ++++++--- .../templates/rideshare/ride_detail.html | 4 +++- .../templates/rideshare/ride_list.html | 24 ++++++++++++++----- src/rideshare/views.py | 4 ++-- 8 files changed, 87 insertions(+), 13 deletions(-) create mode 100644 src/rideshare/migrations/0003_ride_has_car.py create mode 100644 src/rideshare/migrations/0004_auto_20190711_2036.py create mode 100644 src/rideshare/migrations/0005_ride_to_location.py diff --git a/src/rideshare/admin.py b/src/rideshare/admin.py index 4ced6bf9..2a9064e0 100644 --- a/src/rideshare/admin.py +++ b/src/rideshare/admin.py @@ -5,5 +5,5 @@ from .models import Ride @admin.register(Ride) class RideModelAdmin(admin.ModelAdmin): - list_display = ("location", "when", "seats", "user") + list_display = ("camp", "user", "from_location", "to_location", "when", "seats") list_filter = ("camp", "user") diff --git a/src/rideshare/migrations/0003_ride_has_car.py b/src/rideshare/migrations/0003_ride_has_car.py new file mode 100644 index 00000000..51ec21a3 --- /dev/null +++ b/src/rideshare/migrations/0003_ride_has_car.py @@ -0,0 +1,18 @@ +# Generated by Django 2.1.7 on 2019-07-11 18:23 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('rideshare', '0002_auto_20180814_1942'), + ] + + operations = [ + migrations.AddField( + model_name='ride', + name='has_car', + field=models.BooleanField(default=True, help_text='Leave checked if you are offering a ride, uncheck if you need a ride'), + ), + ] diff --git a/src/rideshare/migrations/0004_auto_20190711_2036.py b/src/rideshare/migrations/0004_auto_20190711_2036.py new file mode 100644 index 00000000..4d5270bb --- /dev/null +++ b/src/rideshare/migrations/0004_auto_20190711_2036.py @@ -0,0 +1,18 @@ +# Generated by Django 2.1.7 on 2019-07-11 18:36 + +from django.db import migrations + + +class Migration(migrations.Migration): + + dependencies = [ + ('rideshare', '0003_ride_has_car'), + ] + + operations = [ + migrations.RenameField( + model_name='ride', + old_name='location', + new_name='from_location', + ), + ] diff --git a/src/rideshare/migrations/0005_ride_to_location.py b/src/rideshare/migrations/0005_ride_to_location.py new file mode 100644 index 00000000..8767d0c7 --- /dev/null +++ b/src/rideshare/migrations/0005_ride_to_location.py @@ -0,0 +1,19 @@ +# Generated by Django 2.1.7 on 2019-07-11 18:37 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('rideshare', '0004_auto_20190711_2036'), + ] + + operations = [ + migrations.AddField( + model_name='ride', + name='to_location', + field=models.CharField(default='BornHack', max_length=100), + preserve_default=False, + ), + ] diff --git a/src/rideshare/models.py b/src/rideshare/models.py index 5379f21f..35315288 100644 --- a/src/rideshare/models.py +++ b/src/rideshare/models.py @@ -7,8 +7,13 @@ from utils.models import UUIDModel, CampRelatedModel class Ride(UUIDModel, CampRelatedModel): camp = models.ForeignKey("camps.Camp", on_delete=models.PROTECT) user = models.ForeignKey("auth.User", on_delete=models.PROTECT) + has_car = models.BooleanField( + default=True, + help_text="Leave checked if you are offering a ride, uncheck if you need a ride" + ) seats = models.PositiveIntegerField() - location = models.CharField(max_length=100) + from_location = models.CharField(max_length=100) + to_location = models.CharField(max_length=100) when = models.DateTimeField(help_text="Format is YYYY-MM-DD HH:mm") description = models.TextField() @@ -18,6 +23,6 @@ class Ride(UUIDModel, CampRelatedModel): ) def __str__(self): - return "{} seats from {} at {} by {}".format( - self.seats, self.location, self.when, self.user + return "{} seats from {} to {} at {} by {}".format( + self.seats, self.from_location, self.to_location, self.when, self.user ) diff --git a/src/rideshare/templates/rideshare/ride_detail.html b/src/rideshare/templates/rideshare/ride_detail.html index bb9e90f5..292d4fff 100644 --- a/src/rideshare/templates/rideshare/ride_detail.html +++ b/src/rideshare/templates/rideshare/ride_detail.html @@ -16,7 +16,9 @@

{{ object.seats }} seats free, going from - {{ object.location }} + {{ object.from_location }} + to + {{ object.to_location }} at {{ object.when|date:"jS \o\f F \a\t H:i T" }}

diff --git a/src/rideshare/templates/rideshare/ride_list.html b/src/rideshare/templates/rideshare/ride_list.html index 7b39ac5e..f8c3a2a1 100644 --- a/src/rideshare/templates/rideshare/ride_list.html +++ b/src/rideshare/templates/rideshare/ride_list.html @@ -6,8 +6,8 @@

Ridesharing

-

-On this page participants of {{ camp.title }} can communicate about ridesharing to and from the festival. +

+On this page participants of {{ camp.title }} can communicate about ridesharing to and from the festival. Press "Details" to send a message to the author of the entry.

@@ -21,20 +21,32 @@ On this page participants of {{ camp.title }} can communicate about ridesharing {% for ride in ride_list %} +
- When + Type - Location + Leaving When - Seats + From Location + + To Location + + Seats Free/Needed
+ {% if ride.has_car %} + Has car + {% else %} + Needs ride + {% endif %} {{ ride.when|date:"c" }} - {{ ride.location }} + {{ ride.from_location }} + + {{ ride.to_location }} {{ ride.seats }} diff --git a/src/rideshare/views.py b/src/rideshare/views.py index 563e96aa..78fa39a6 100644 --- a/src/rideshare/views.py +++ b/src/rideshare/views.py @@ -63,7 +63,7 @@ class RideDetail(LoginRequiredMixin, CampViewMixin, DetailView): class RideCreate(LoginRequiredMixin, CampViewMixin, CreateView): model = Ride - fields = ["location", "when", "seats", "description"] + fields = ["has_car", "from_location", "to_location", "when", "seats", "description"] def form_valid(self, form, **kwargs): ride = form.save(commit=False) @@ -81,7 +81,7 @@ class IsRideOwnerMixin(UserPassesTestMixin): class RideUpdate(LoginRequiredMixin, CampViewMixin, IsRideOwnerMixin, UpdateView): model = Ride - fields = ["location", "when", "seats", "description"] + fields = ["has_car", "from_location", "to_location", "when", "seats", "description"] class RideDelete(LoginRequiredMixin, CampViewMixin, IsRideOwnerMixin, DeleteView):