Initial work on rideshare feature.
This commit is contained in:
parent
badd18cb1b
commit
1c8685d15e
|
@ -46,6 +46,7 @@ INSTALLED_APPS = [
|
|||
'bar',
|
||||
'backoffice',
|
||||
'events',
|
||||
'rideshare',
|
||||
|
||||
'allauth',
|
||||
'allauth.account',
|
||||
|
|
|
@ -182,6 +182,11 @@ urlpatterns = [
|
|||
include('teams.urls', namespace='teams')
|
||||
),
|
||||
|
||||
path(
|
||||
'rideshare/',
|
||||
include('rideshare.urls', namespace='rideshare')
|
||||
),
|
||||
|
||||
path(
|
||||
'backoffice/',
|
||||
include('backoffice.urls', namespace='backoffice')
|
||||
|
|
0
src/rideshare/__init__.py
Normal file
0
src/rideshare/__init__.py
Normal file
3
src/rideshare/admin.py
Normal file
3
src/rideshare/admin.py
Normal file
|
@ -0,0 +1,3 @@
|
|||
from django.contrib import admin
|
||||
|
||||
# Register your models here.
|
5
src/rideshare/apps.py
Normal file
5
src/rideshare/apps.py
Normal file
|
@ -0,0 +1,5 @@
|
|||
from django.apps import AppConfig
|
||||
|
||||
|
||||
class RideshareConfig(AppConfig):
|
||||
name = 'rideshare'
|
36
src/rideshare/migrations/0001_initial.py
Normal file
36
src/rideshare/migrations/0001_initial.py
Normal file
|
@ -0,0 +1,36 @@
|
|||
# Generated by Django 2.0.4 on 2018-08-08 20:18
|
||||
|
||||
from django.conf import settings
|
||||
from django.db import migrations, models
|
||||
import django.db.models.deletion
|
||||
import uuid
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
initial = True
|
||||
|
||||
dependencies = [
|
||||
('camps', '0028_auto_20180525_1025'),
|
||||
migrations.swappable_dependency(settings.AUTH_USER_MODEL),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.CreateModel(
|
||||
name='Ride',
|
||||
fields=[
|
||||
('uuid', models.UUIDField(default=uuid.uuid4, editable=False, primary_key=True, serialize=False)),
|
||||
('created', models.DateTimeField(auto_now_add=True)),
|
||||
('updated', models.DateTimeField(auto_now=True)),
|
||||
('seats', models.PositiveIntegerField()),
|
||||
('location', models.CharField(max_length=100)),
|
||||
('when', models.DateTimeField()),
|
||||
('description', models.TextField()),
|
||||
('camp', models.ForeignKey(on_delete=django.db.models.deletion.PROTECT, to='camps.Camp')),
|
||||
('user', models.ForeignKey(on_delete=django.db.models.deletion.PROTECT, to=settings.AUTH_USER_MODEL)),
|
||||
],
|
||||
options={
|
||||
'abstract': False,
|
||||
},
|
||||
),
|
||||
]
|
0
src/rideshare/migrations/__init__.py
Normal file
0
src/rideshare/migrations/__init__.py
Normal file
22
src/rideshare/models.py
Normal file
22
src/rideshare/models.py
Normal file
|
@ -0,0 +1,22 @@
|
|||
from django.db import models
|
||||
from django.urls import reverse
|
||||
|
||||
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)
|
||||
seats = models.PositiveIntegerField()
|
||||
location = models.CharField(max_length=100)
|
||||
when = models.DateTimeField()
|
||||
description = models.TextField()
|
||||
|
||||
def get_absolute_url(self):
|
||||
return reverse(
|
||||
'rideshare:detail',
|
||||
kwargs={
|
||||
'pk': self.pk,
|
||||
'camp_slug': self.camp.slug
|
||||
}
|
||||
)
|
10
src/rideshare/templates/rideshare/ride_confirm_delete.html
Normal file
10
src/rideshare/templates/rideshare/ride_confirm_delete.html
Normal file
|
@ -0,0 +1,10 @@
|
|||
{% extends 'base.html' %}
|
||||
|
||||
{% block content %}
|
||||
|
||||
<form method="post">{% csrf_token %}
|
||||
<p>Are you sure you want to delete {{ object }}?</p>
|
||||
<input type="submit" class="btn btn-danger" value="Confirm" />
|
||||
</form>
|
||||
|
||||
{% endblock %}
|
12
src/rideshare/templates/rideshare/ride_detail.html
Normal file
12
src/rideshare/templates/rideshare/ride_detail.html
Normal file
|
@ -0,0 +1,12 @@
|
|||
{% extends 'base.html' %}
|
||||
{% load commonmark %}
|
||||
|
||||
{% block content %}
|
||||
|
||||
{{ object.location }}
|
||||
|
||||
{{ object.datetime }}
|
||||
|
||||
{{ object.description }}
|
||||
|
||||
{% endblock %}
|
15
src/rideshare/templates/rideshare/ride_form.html
Normal file
15
src/rideshare/templates/rideshare/ride_form.html
Normal file
|
@ -0,0 +1,15 @@
|
|||
{% extends 'base.html' %}
|
||||
{% load commonmark %}
|
||||
{% load bootstrap3 %}
|
||||
|
||||
{% block content %}
|
||||
|
||||
<form method="POST">
|
||||
{% csrf_token %}
|
||||
{% bootstrap_form form %}
|
||||
<button type="submit" class="btn btn-success">
|
||||
{% if object.pk %}Update{% else %}Create{% endif %}
|
||||
</button>
|
||||
</form>
|
||||
|
||||
{% endblock %}
|
18
src/rideshare/templates/rideshare/ride_list.html
Normal file
18
src/rideshare/templates/rideshare/ride_list.html
Normal file
|
@ -0,0 +1,18 @@
|
|||
{% extends 'base.html' %}
|
||||
|
||||
{% block content %}
|
||||
|
||||
<a class="btn btn-success" href="{% url 'rideshare:create' camp_slug=camp.slug %}">
|
||||
Create ride
|
||||
</a>
|
||||
|
||||
<hr />
|
||||
|
||||
{% for ride in ride_list %}
|
||||
|
||||
{{ ride.from_location }} at {{ ride.from_datetime}}
|
||||
|
||||
|
||||
{% endfor %}
|
||||
|
||||
{% endblock %}
|
3
src/rideshare/tests.py
Normal file
3
src/rideshare/tests.py
Normal file
|
@ -0,0 +1,3 @@
|
|||
from django.test import TestCase
|
||||
|
||||
# Create your tests here.
|
43
src/rideshare/urls.py
Normal file
43
src/rideshare/urls.py
Normal file
|
@ -0,0 +1,43 @@
|
|||
from django.urls import path, include
|
||||
|
||||
from .views import (
|
||||
RideList,
|
||||
RideCreate,
|
||||
RideDetail,
|
||||
RideUpdate,
|
||||
RideDelete,
|
||||
)
|
||||
|
||||
app_name = 'rideshare'
|
||||
|
||||
urlpatterns = [
|
||||
path(
|
||||
'',
|
||||
RideList.as_view(),
|
||||
name='list'
|
||||
),
|
||||
path(
|
||||
'create/',
|
||||
RideCreate.as_view(),
|
||||
name='create'
|
||||
),
|
||||
path(
|
||||
'<uuid:pk>/', include([
|
||||
path(
|
||||
'',
|
||||
RideDetail.as_view(),
|
||||
name='detail'
|
||||
),
|
||||
path(
|
||||
'update/',
|
||||
RideUpdate.as_view(),
|
||||
name='update'
|
||||
),
|
||||
path(
|
||||
'delete/',
|
||||
RideDelete.as_view(),
|
||||
name='delete'
|
||||
),
|
||||
])
|
||||
)
|
||||
]
|
43
src/rideshare/views.py
Normal file
43
src/rideshare/views.py
Normal file
|
@ -0,0 +1,43 @@
|
|||
from django.contrib.auth.mixins import LoginRequiredMixin
|
||||
from django.views.generic import (
|
||||
ListView,
|
||||
DetailView,
|
||||
CreateView,
|
||||
UpdateView,
|
||||
DeleteView,
|
||||
)
|
||||
from django.http import HttpResponseRedirect
|
||||
|
||||
from camps.mixins import CampViewMixin
|
||||
|
||||
from .models import Ride
|
||||
|
||||
|
||||
class RideList(LoginRequiredMixin, CampViewMixin, ListView):
|
||||
model = Ride
|
||||
|
||||
|
||||
class RideDetail(LoginRequiredMixin, CampViewMixin, DetailView):
|
||||
model = Ride
|
||||
|
||||
|
||||
class RideCreate(LoginRequiredMixin, CampViewMixin, CreateView):
|
||||
model = Ride
|
||||
fields = ['location', 'when', 'seats', 'description']
|
||||
|
||||
def form_valid(self, form, **kwargs):
|
||||
ride = form.save(commit=False)
|
||||
ride.camp = self.camp
|
||||
ride.user = self.request.user
|
||||
ride.save()
|
||||
self.object = ride
|
||||
return HttpResponseRedirect(self.get_success_url())
|
||||
|
||||
|
||||
class RideUpdate(LoginRequiredMixin, CampViewMixin, UpdateView):
|
||||
model = Ride
|
||||
fields = ['location', 'when', 'seats', 'description']
|
||||
|
||||
|
||||
class RideDelete(LoginRequiredMixin, CampViewMixin, DeleteView):
|
||||
model = Ride
|
|
@ -5,6 +5,7 @@
|
|||
<a class="btn {% menubuttonclass 'villages' %}" href="{% url 'village_list' camp_slug=camp.slug %}">Villages</a>
|
||||
<a class="btn {% menubuttonclass 'sponsors' %}" href="{% url 'sponsors' camp_slug=camp.slug %}">Sponsors</a>
|
||||
<a class="btn {% menubuttonclass 'teams' %}" href="{% url 'teams:list' camp_slug=camp.slug %}">Teams</a>
|
||||
<a class="btn {% menubuttonclass 'rideshare' %}" href="{% url 'rideshare:list' camp_slug=camp.slug %}">Rideshare</a>
|
||||
{% if request.user.is_staff %}
|
||||
<a class="btn {% menubuttonclass 'backoffice' %}" href="{% url 'backoffice:index' camp_slug=camp.slug %}">Backoffice</a>
|
||||
{% endif %}
|
||||
|
|
Loading…
Reference in a new issue