add author field to rideshare, add help_text on all rideshare fields, fixup the rideshare templates a bit

This commit is contained in:
Thomas Steen Rasmussen 2019-07-13 09:27:14 +02:00
parent 2cad801769
commit 5fa07f130a
7 changed files with 118 additions and 12 deletions

View file

@ -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'),
),
]

View file

@ -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),
),
]

View file

@ -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),
),
]

View file

@ -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(

View file

@ -14,6 +14,8 @@
<div class="panel panel-default">
<div class="panel-heading">
<h4>
<strong>{{ object.author }}</strong>
{% if object.has_car %}has {% else %}needs {% endif %}
<strong>{{ object.seats }}</strong>
seats free, going from
<strong>{{ object.from_location }}</strong>

View file

@ -26,6 +26,8 @@ On this page participants of {{ camp.title }} can communicate about ridesharing
<table class="table table-condensed table-striped">
<thead>
<th>
Author
<th>
Type
<th>
@ -37,10 +39,13 @@ On this page participants of {{ camp.title }} can communicate about ridesharing
<th>
Seats Free/Needed
<th>
Actions
<tbody>
{% for ride in ride_list %}
<tr>
<td>
{{ ride.author }}
<td>
{% if ride.has_car %}
<i class="fas fa-car"></i> Has car
@ -53,9 +58,17 @@ On this page participants of {{ camp.title }} can communicate about ridesharing
{{ ride.from_location }}
<td>
{{ ride.to_location }}
<td class="text-center">
<span class="badge">{{ ride.seats }}</span>
<td>
{{ ride.seats }}
<td>
{% if request.user == ride.user %}
<a class="btn btn-danger pull-right" href="{% url 'rideshare:delete' camp_slug=camp.slug pk=ride.pk %}">
<i class="fas fa-times"></i> Delete
</a>
<a class="btn btn-primary pull-right" href="{% url 'rideshare:update' camp_slug=camp.slug pk=ride.pk %}">
<i class="fas fa-edit"></i> Update
</a>
{% endif %}
<a class="btn btn-primary pull-right" href="{% url 'rideshare:detail' camp_slug=camp.slug pk=ride.pk %}">
<i class="fas fa-eye"></i> Details
</a>

View file

@ -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):