diff --git a/src/rideshare/migrations/0006_auto_20190713_0859.py b/src/rideshare/migrations/0006_auto_20190713_0859.py new file mode 100644 index 00000000..bb205ca1 --- /dev/null +++ b/src/rideshare/migrations/0006_auto_20190713_0859.py @@ -0,0 +1,43 @@ +# Generated by Django 2.1.7 on 2019-07-13 06:59 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('rideshare', '0005_ride_to_location'), + ] + + operations = [ + migrations.AlterField( + model_name='ride', + name='description', + field=models.TextField(help_text='Include any details you want, like luggage space/requirements, contact info and so on.'), + ), + migrations.AlterField( + model_name='ride', + name='from_location', + field=models.CharField(help_text='Where does this ride begin?', max_length=100), + ), + migrations.AlterField( + 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.'), + ), + migrations.AlterField( + model_name='ride', + name='seats', + field=models.PositiveIntegerField(help_text='How many seats are you offering/how many seats do you need?'), + ), + migrations.AlterField( + model_name='ride', + name='to_location', + field=models.CharField(help_text='What is the destination of this ride?', max_length=100), + ), + migrations.AlterField( + model_name='ride', + name='when', + field=models.DateTimeField(help_text='When does this ride leave? Format is YYYY-MM-DD HH:mm'), + ), + ] diff --git a/src/rideshare/migrations/0007_ride_author.py b/src/rideshare/migrations/0007_ride_author.py new file mode 100644 index 00000000..4c59a976 --- /dev/null +++ b/src/rideshare/migrations/0007_ride_author.py @@ -0,0 +1,18 @@ +# Generated by Django 2.1.7 on 2019-07-13 07:05 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('rideshare', '0006_auto_20190713_0859'), + ] + + operations = [ + migrations.AddField( + model_name='ride', + name='author', + field=models.CharField(default='Unnamed', help_text='Let people know who posted this', max_length=100), + ), + ] diff --git a/src/rideshare/migrations/0008_auto_20190713_0924.py b/src/rideshare/migrations/0008_auto_20190713_0924.py new file mode 100644 index 00000000..6e1aa172 --- /dev/null +++ b/src/rideshare/migrations/0008_auto_20190713_0924.py @@ -0,0 +1,18 @@ +# Generated by Django 2.1.7 on 2019-07-13 07:24 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('rideshare', '0007_ride_author'), + ] + + operations = [ + migrations.AlterField( + model_name='ride', + name='author', + field=models.CharField(default='Anonymous', help_text='Let people know who posted this', max_length=100), + ), + ] diff --git a/src/rideshare/models.py b/src/rideshare/models.py index 35315288..dd430827 100644 --- a/src/rideshare/models.py +++ b/src/rideshare/models.py @@ -7,15 +7,16 @@ 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) + author = models.CharField(max_length=100, help_text="Let people know who posted this", default="Anonymous") has_car = models.BooleanField( default=True, - help_text="Leave checked if you are offering a ride, uncheck if you need a ride" + help_text="Leave checked if you are offering a ride, uncheck if you need a ride." ) - seats = models.PositiveIntegerField() - 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() + seats = models.PositiveIntegerField(help_text="How many seats are you offering/how many seats do you need?") + from_location = models.CharField(max_length=100, help_text="Where does this ride begin?") + to_location = models.CharField(max_length=100, help_text="What is the destination of this ride?") + when = models.DateTimeField(help_text="When does this ride leave? Format is YYYY-MM-DD HH:mm") + description = models.TextField(help_text="Include any details you want, like luggage space/requirements, contact info and so on.") def get_absolute_url(self): return reverse( diff --git a/src/rideshare/templates/rideshare/ride_detail.html b/src/rideshare/templates/rideshare/ride_detail.html index 292d4fff..e1696103 100644 --- a/src/rideshare/templates/rideshare/ride_detail.html +++ b/src/rideshare/templates/rideshare/ride_detail.html @@ -14,6 +14,8 @@

+ {{ object.author }} + {% if object.has_car %}has {% else %}needs {% endif %} {{ object.seats }} seats free, going from {{ object.from_location }} diff --git a/src/rideshare/templates/rideshare/ride_list.html b/src/rideshare/templates/rideshare/ride_list.html index 929fb10f..7a94e8c4 100644 --- a/src/rideshare/templates/rideshare/ride_list.html +++ b/src/rideshare/templates/rideshare/ride_list.html @@ -26,6 +26,8 @@ On this page participants of {{ camp.title }} can communicate about ridesharing + {% for ride in ride_list %} +
+ Author Type @@ -37,10 +39,13 @@ On this page participants of {{ camp.title }} can communicate about ridesharing Seats Free/Needed + Actions
+ {{ ride.author }} {% if ride.has_car %} Has car @@ -53,9 +58,17 @@ On this page participants of {{ camp.title }} can communicate about ridesharing {{ ride.from_location }} {{ ride.to_location }} + + {{ ride.seats }} - {{ ride.seats }} - + {% if request.user == ride.user %} + + Delete + + + Update + + {% endif %} Details diff --git a/src/rideshare/views.py b/src/rideshare/views.py index 78fa39a6..36b4ed3e 100644 --- a/src/rideshare/views.py +++ b/src/rideshare/views.py @@ -22,8 +22,8 @@ class ContactRideForm(forms.Form): widget=forms.Textarea( attrs={"placeholder": "Remember to include your contact information!"} ), - label="Write a message to this rideshare", - help_text="ATTENTION!: Pressing send will send an email with the above text. It is up to you to include your contact information so the person receiving the email can contact you.", + label="Write a message to the author of this rideshare", + help_text="ATTENTION!: Pressing send will send an email to the author with the above text. It is up to you to include your contact information in the message so the person receiving the email can contact you.", ) @@ -63,9 +63,20 @@ class RideDetail(LoginRequiredMixin, CampViewMixin, DetailView): class RideCreate(LoginRequiredMixin, CampViewMixin, CreateView): model = Ride - fields = ["has_car", "from_location", "to_location", "when", "seats", "description"] + fields = ["author", "has_car", "from_location", "to_location", "when", "seats", "description"] + + def get_initial(self): + """ + Default 'author' to users public_credit_name where relevant + """ + return { + "author": self.request.user.profile.get_public_credit_name + } def form_valid(self, form, **kwargs): + """ + Set camp and user before saving + """ ride = form.save(commit=False) ride.camp = self.camp ride.user = self.request.user @@ -81,7 +92,7 @@ class IsRideOwnerMixin(UserPassesTestMixin): class RideUpdate(LoginRequiredMixin, CampViewMixin, IsRideOwnerMixin, UpdateView): model = Ride - fields = ["has_car", "from_location", "to_location", "when", "seats", "description"] + fields = ["author", "has_car", "from_location", "to_location", "when", "seats", "description"] class RideDelete(LoginRequiredMixin, CampViewMixin, IsRideOwnerMixin, DeleteView):