From 4d1ce945792648fca00d50ce18a61b775589d9ae Mon Sep 17 00:00:00 2001 From: Mitch Riedstra Date: Fri, 10 Nov 2017 21:08:11 -0500 Subject: Working invites in the Driver's list page --- app/dispatch/forms.py | 7 ++++--- app/dispatch/templates/dispatch/drivers/list.html | 5 +++++ app/dispatch/templates/dispatch/invite_email.txt | 6 +++--- app/dispatch/templates/dispatch/invite_user.html | 23 +++++++++++++++++++++++ app/dispatch/urls.py | 1 + app/dispatch/views.py | 19 ++++++++++++++++++- 6 files changed, 54 insertions(+), 7 deletions(-) create mode 100644 app/dispatch/templates/dispatch/invite_user.html (limited to 'app/dispatch') diff --git a/app/dispatch/forms.py b/app/dispatch/forms.py index 6333486..feeda39 100644 --- a/app/dispatch/forms.py +++ b/app/dispatch/forms.py @@ -6,7 +6,8 @@ from dispatch.models import Paperwork class AddPaperworkForm(forms.ModelForm): class Meta: model = Paperwork - # widgets = {'load': forms.HiddenInput()} - # fields = ('load', 'description', 'document') fields = ('description', 'document') - # exclude = ('load',) + +class InviteForm(forms.Form): + first_name = forms.CharField(label="User's name") + email_address = forms.EmailField(label="User's email address") diff --git a/app/dispatch/templates/dispatch/drivers/list.html b/app/dispatch/templates/dispatch/drivers/list.html index c87f99f..f1e5be6 100644 --- a/app/dispatch/templates/dispatch/drivers/list.html +++ b/app/dispatch/templates/dispatch/drivers/list.html @@ -9,6 +9,11 @@ +
+ +
+
diff --git a/app/dispatch/templates/dispatch/invite_email.txt b/app/dispatch/templates/dispatch/invite_email.txt index eb888a6..9c3faf7 100644 --- a/app/dispatch/templates/dispatch/invite_email.txt +++ b/app/dispatch/templates/dispatch/invite_email.txt @@ -1,7 +1,7 @@ -Hi {{name}}, +{% autoescape off %}Hi {{name}}, -You've been invited by {{user.first_name}} to register +You've been invited by {{user.first_name}} to register at {{app_name}} Please click the following link to start this process -{{site}}{% url 'registration_register' %} +{{site}}{% url 'registration_register' %}{% endautoescape %} diff --git a/app/dispatch/templates/dispatch/invite_user.html b/app/dispatch/templates/dispatch/invite_user.html new file mode 100644 index 0000000..86dab40 --- /dev/null +++ b/app/dispatch/templates/dispatch/invite_user.html @@ -0,0 +1,23 @@ +{% extends 'dispatch/base.html' %} + +{% block title %}Invite User{% endblock %} + +{% block content %} + + +
+
+ +
{% csrf_token %} + {% for field in form %} +

+ {{field.label_tag}} {{field}} +

+ {% endfor %} + + + +
+
+ +{% endblock %} diff --git a/app/dispatch/urls.py b/app/dispatch/urls.py index 14f78f8..c7622ff 100644 --- a/app/dispatch/urls.py +++ b/app/dispatch/urls.py @@ -21,6 +21,7 @@ urlpatterns = [ url(r'^drivers/(?P\d+)/identity/default/(?P\d+)$', views.SetDefaultIdentity, name='identity_default'), url(r'drivers/(?P\d+)/invoice/edit/(?P\d+)$', views.UserInvoiceNumberUpdate.as_view(), name='userinvoicenumber_edit'), + url(r'drivers/invite_user/$', views.InviteUser, name='invite_user'), url(r'^customers/$', views.CustomerList.as_view(), name='customer_list'), url(r'^customers/new$', views.CustomerCreate.as_view(), name='customer_new'), diff --git a/app/dispatch/views.py b/app/dispatch/views.py index 62fc73f..784da9e 100644 --- a/app/dispatch/views.py +++ b/app/dispatch/views.py @@ -14,7 +14,7 @@ from django.views.generic.edit import CreateView, UpdateView, DeleteView from django.core.urlresolvers import reverse_lazy from dispatch.models import Customer, Load, Paperwork, \ Invoice, UserInvoiceNumber, Identity, Settings -from dispatch.forms import AddPaperworkForm +from dispatch.forms import AddPaperworkForm, InviteForm from django.contrib.auth import get_user_model from django.contrib.auth.mixins import UserPassesTestMixin # from django.http import HttpResponseRedirect @@ -362,6 +362,23 @@ class LoadDelete(UserPassesTestMixin, FilteredDeleteView): return self.request.user.is_superuser +def InviteUser(request): + if request.method == 'POST': + form = InviteForm(request.POST) + if form.is_valid(): + request.user.send_invite( + form.cleaned_data.get('first_name'), + form.cleaned_data.get('email_address') + ) + return redirect(reverse('driver_list')) + else: + form = InviteForm() + + ctx = {'form': form} + + return render(request, 'dispatch/invite_user.html', ctx) + + # Paperwork Uploads def PaperworkUpload(request, load_id): -- cgit v1.2.3