From 3229838d0ad880eb5aa8d77fab774a622c36dec9 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?V=C3=AD=C3=B0ir=20Valberg=20Gu=C3=B0mundsson?=
Date: Fri, 10 Aug 2018 17:41:19 +0200
Subject: [PATCH] Adding contact options.
---
.../rideshare/emails/contact_mail.html | 13 +++++
.../rideshare/emails/contact_mail.txt | 13 +++++
.../templates/rideshare/ride_detail.html | 25 ++++++++--
.../templates/rideshare/ride_list.html | 8 +++-
src/rideshare/urls.py | 6 ---
src/rideshare/views.py | 48 +++++++++++++++----
6 files changed, 93 insertions(+), 20 deletions(-)
create mode 100644 src/rideshare/templates/rideshare/emails/contact_mail.html
create mode 100644 src/rideshare/templates/rideshare/emails/contact_mail.txt
diff --git a/src/rideshare/templates/rideshare/emails/contact_mail.html b/src/rideshare/templates/rideshare/emails/contact_mail.html
new file mode 100644
index 00000000..6855a686
--- /dev/null
+++ b/src/rideshare/templates/rideshare/emails/contact_mail.html
@@ -0,0 +1,13 @@
+Hello!
+
+The following message has been submitted to your rideshare on {{ rideshare_url }}.
+
+<message>
+
+ {{ message }}
+
+</message>
+
+Best regards,
+
+The BornHack Teamp
diff --git a/src/rideshare/templates/rideshare/emails/contact_mail.txt b/src/rideshare/templates/rideshare/emails/contact_mail.txt
new file mode 100644
index 00000000..8225c0d5
--- /dev/null
+++ b/src/rideshare/templates/rideshare/emails/contact_mail.txt
@@ -0,0 +1,13 @@
+Hello!
+
+The following message has been submitted to your rideshare on {{ rideshare_url }}.
+
+
+
+{{ message }}
+
+
+
+Best regards,
+
+The BornHack Team
diff --git a/src/rideshare/templates/rideshare/ride_detail.html b/src/rideshare/templates/rideshare/ride_detail.html
index 09383672..bb9e90f5 100644
--- a/src/rideshare/templates/rideshare/ride_detail.html
+++ b/src/rideshare/templates/rideshare/ride_detail.html
@@ -1,5 +1,6 @@
{% extends 'base.html' %}
{% load commonmark %}
+{% load bootstrap3 %}
{% block content %}
@@ -26,14 +27,32 @@
{{ object.description|untrustedcommonmark }}
+ {% if user == object.user %}
+ {% else %}
+
+
+ {% endif %}
diff --git a/src/rideshare/templates/rideshare/ride_list.html b/src/rideshare/templates/rideshare/ride_list.html
index ca022df6..7b39ac5e 100644
--- a/src/rideshare/templates/rideshare/ride_list.html
+++ b/src/rideshare/templates/rideshare/ride_list.html
@@ -10,9 +10,13 @@
On this page participants of {{ camp.title }} can communicate about ridesharing to and from the festival.
-
- Create ride
+
+
+ Create ride
+
+
+
diff --git a/src/rideshare/urls.py b/src/rideshare/urls.py
index 6f07621d..e528e248 100644
--- a/src/rideshare/urls.py
+++ b/src/rideshare/urls.py
@@ -6,7 +6,6 @@ from .views import (
RideDetail,
RideUpdate,
RideDelete,
- RideContactConfirm,
)
app_name = 'rideshare'
@@ -39,11 +38,6 @@ urlpatterns = [
RideDelete.as_view(),
name='delete'
),
- path(
- 'confirm/',
- RideContactConfirm.as_view(),
- name='contact-confirm'
- ),
])
)
]
diff --git a/src/rideshare/views.py b/src/rideshare/views.py
index f11eed0e..19e4ef31 100644
--- a/src/rideshare/views.py
+++ b/src/rideshare/views.py
@@ -1,19 +1,31 @@
+from django.contrib import messages
from django.contrib.auth.mixins import LoginRequiredMixin
+from django.urls import reverse
from django.views.generic import (
ListView,
DetailView,
CreateView,
UpdateView,
DeleteView,
- TemplateView,
+ FormView
)
from django.http import HttpResponseRedirect
+from django import forms
from camps.mixins import CampViewMixin
+from utils.email import add_outgoing_email
from .models import Ride
+class ContactRideForm(forms.Form):
+ message = forms.CharField(
+ 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.",
+ )
+
+
class RideList(LoginRequiredMixin, CampViewMixin, ListView):
model = Ride
@@ -21,6 +33,32 @@ class RideList(LoginRequiredMixin, CampViewMixin, ListView):
class RideDetail(LoginRequiredMixin, CampViewMixin, DetailView):
model = Ride
+ def get_context_data(self, **kwargs):
+ context = super().get_context_data(**kwargs)
+ context['form'] = ContactRideForm()
+ return context
+
+ def post(self, request, **kwargs):
+ form = ContactRideForm(request.POST)
+ if form.is_valid():
+ ride = self.get_object()
+ add_outgoing_email(
+ text_template='rideshare/emails/contact_mail.txt',
+ to_recipients=[ride.user.emailaddress_set.get(primary=True).email],
+ formatdict=dict(
+ rideshare_url="https://bornhack.dk{}".format(
+ reverse(
+ 'rideshare:detail',
+ kwargs={"camp_slug": self.camp.slug, "pk": ride.pk}
+ )
+ ),
+ message=form.cleaned_data['message'],
+ ),
+ subject="BornHack rideshare message!",
+ )
+ messages.info(request, "Your message has been sent.")
+ return HttpResponseRedirect(ride.get_absolute_url())
+
class RideCreate(LoginRequiredMixin, CampViewMixin, CreateView):
model = Ride
@@ -42,11 +80,3 @@ class RideUpdate(LoginRequiredMixin, CampViewMixin, UpdateView):
class RideDelete(LoginRequiredMixin, CampViewMixin, DeleteView):
model = Ride
-
-
-class RideContactConfirm(LoginRequiredMixin, CampViewMixin, DetailView):
- model = Ride
- template_name = "rideshare/ride_contact_confirm.html"
-
-
-# class RideContact(View):