fixup rideshare a bit

This commit is contained in:
Thomas Steen Rasmussen 2019-07-11 20:48:14 +02:00
parent 881b0f4cf4
commit e4f6670c45
8 changed files with 87 additions and 13 deletions

View file

@ -5,5 +5,5 @@ from .models import Ride
@admin.register(Ride) @admin.register(Ride)
class RideModelAdmin(admin.ModelAdmin): class RideModelAdmin(admin.ModelAdmin):
list_display = ("location", "when", "seats", "user") list_display = ("camp", "user", "from_location", "to_location", "when", "seats")
list_filter = ("camp", "user") list_filter = ("camp", "user")

View file

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

View file

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

View file

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

View file

@ -7,8 +7,13 @@ from utils.models import UUIDModel, CampRelatedModel
class Ride(UUIDModel, CampRelatedModel): class Ride(UUIDModel, CampRelatedModel):
camp = models.ForeignKey("camps.Camp", on_delete=models.PROTECT) camp = models.ForeignKey("camps.Camp", on_delete=models.PROTECT)
user = models.ForeignKey("auth.User", 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() 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") when = models.DateTimeField(help_text="Format is YYYY-MM-DD HH:mm")
description = models.TextField() description = models.TextField()
@ -18,6 +23,6 @@ class Ride(UUIDModel, CampRelatedModel):
) )
def __str__(self): def __str__(self):
return "{} seats from {} at {} by {}".format( return "{} seats from {} to {} at {} by {}".format(
self.seats, self.location, self.when, self.user self.seats, self.from_location, self.to_location, self.when, self.user
) )

View file

@ -16,7 +16,9 @@
<h4> <h4>
<strong>{{ object.seats }}</strong> <strong>{{ object.seats }}</strong>
seats free, going from seats free, going from
<strong>{{ object.location }}</strong> <strong>{{ object.from_location }}</strong>
to
<strong>{{ object.to_location }}</strong>
at at
<strong>{{ object.when|date:"jS \o\f F \a\t H:i T" }}</strong> <strong>{{ object.when|date:"jS \o\f F \a\t H:i T" }}</strong>
</h4> </h4>

View file

@ -6,8 +6,8 @@
<h1>Ridesharing</h1> <h1>Ridesharing</h1>
</div> </div>
<p> <p class="lead">
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.
</p> </p>
<a class="btn btn-success pull-right" href="{% url 'rideshare:create' camp_slug=camp.slug %}"> <a class="btn btn-success pull-right" href="{% url 'rideshare:create' camp_slug=camp.slug %}">
@ -21,20 +21,32 @@ On this page participants of {{ camp.title }} can communicate about ridesharing
<table class="table table-condensed table-striped"> <table class="table table-condensed table-striped">
<thead> <thead>
<th> <th>
When Type
<th> <th>
Location Leaving When
<th> <th>
Seats From Location
<th>
To Location
<th>
Seats Free/Needed
<th> <th>
<tbody> <tbody>
{% for ride in ride_list %} {% for ride in ride_list %}
<tr> <tr>
<td>
{% if ride.has_car %}
<i class="fas fa-car"></i> Has car
{% else %}
<i class="fas fa-thumbs-up"></i> Needs ride
{% endif %}
<td> <td>
{{ ride.when|date:"c" }} {{ ride.when|date:"c" }}
<td> <td>
{{ ride.location }} {{ ride.from_location }}
<td>
{{ ride.to_location }}
<td> <td>
{{ ride.seats }} {{ ride.seats }}
<td> <td>

View file

@ -63,7 +63,7 @@ class RideDetail(LoginRequiredMixin, CampViewMixin, DetailView):
class RideCreate(LoginRequiredMixin, CampViewMixin, CreateView): class RideCreate(LoginRequiredMixin, CampViewMixin, CreateView):
model = Ride model = Ride
fields = ["location", "when", "seats", "description"] fields = ["has_car", "from_location", "to_location", "when", "seats", "description"]
def form_valid(self, form, **kwargs): def form_valid(self, form, **kwargs):
ride = form.save(commit=False) ride = form.save(commit=False)
@ -81,7 +81,7 @@ class IsRideOwnerMixin(UserPassesTestMixin):
class RideUpdate(LoginRequiredMixin, CampViewMixin, IsRideOwnerMixin, UpdateView): class RideUpdate(LoginRequiredMixin, CampViewMixin, IsRideOwnerMixin, UpdateView):
model = Ride model = Ride
fields = ["location", "when", "seats", "description"] fields = ["has_car", "from_location", "to_location", "when", "seats", "description"]
class RideDelete(LoginRequiredMixin, CampViewMixin, IsRideOwnerMixin, DeleteView): class RideDelete(LoginRequiredMixin, CampViewMixin, IsRideOwnerMixin, DeleteView):