diff options
| author | Mitch Riedstra <mitch@riedstra.us> | 2017-11-10 21:08:11 -0500 |
|---|---|---|
| committer | Mitch Riedstra <mitch@riedstra.us> | 2017-11-10 21:08:11 -0500 |
| commit | 4d1ce945792648fca00d50ce18a61b775589d9ae (patch) | |
| tree | 3686b541946af10aae92ef104aa5cbd31483687f | |
| parent | 6155857dcd9a88d07756c465df42c5155c7183dc (diff) | |
| download | dispatch-tracker-4d1ce945792648fca00d50ce18a61b775589d9ae.tar.gz dispatch-tracker-4d1ce945792648fca00d50ce18a61b775589d9ae.tar.xz | |
Working invites in the Driver's list page
| -rw-r--r-- | app/app/settings.py | 2 | ||||
| -rw-r--r-- | app/config-example.yml | 2 | ||||
| -rw-r--r-- | app/dispatch/forms.py | 7 | ||||
| -rw-r--r-- | app/dispatch/templates/dispatch/drivers/list.html | 5 | ||||
| -rw-r--r-- | app/dispatch/templates/dispatch/invite_email.txt | 6 | ||||
| -rw-r--r-- | app/dispatch/templates/dispatch/invite_user.html | 23 | ||||
| -rw-r--r-- | app/dispatch/urls.py | 1 | ||||
| -rw-r--r-- | app/dispatch/views.py | 19 | ||||
| -rw-r--r-- | app/dispatchAuth/models.py | 5 |
9 files changed, 61 insertions, 9 deletions
diff --git a/app/app/settings.py b/app/app/settings.py index 23c1452..59c7c1a 100644 --- a/app/app/settings.py +++ b/app/app/settings.py @@ -52,6 +52,7 @@ ALLOWED_HOSTS = CONFIG['allowed_hosts'] ADMINS = CONFIG['admins'] WEBSITE_URI = CONFIG['website_uri'] +WEB_APP_NAME =CONFIG['application_name'] if CONFIG.get('SET_EMAIL'): EMAIL_HOST = CONFIG['EMAIL_HOST'] @@ -59,6 +60,7 @@ if CONFIG.get('SET_EMAIL'): EMAIL_HOST_USER = CONFIG['EMAIL_HOST_USER'] EMAIL_PORT = CONFIG['EMAIL_PORT'] EMAIL_USE_TLS = CONFIG['EMAIL_USE_TLS'] + DEFAULT_FROM_EMAIL = CONFIG['DEFAULT_FROM_EMAIL'] else: print("WARNING EMAIL SETTINGS NOT APPLIED. CHECK CONFIG") diff --git a/app/config-example.yml b/app/config-example.yml index e5fffdf..09a23b9 100644 --- a/app/config-example.yml +++ b/app/config-example.yml @@ -35,6 +35,7 @@ SECRET_KEY: 'h$r_bwlp@#h#y#%&qhw-n=gb2%wva1d_h65+o94u&!a#%iv&lo' admins: - 'bob@example.com' +application_name: "Yo Momma's Dispatch Tracker" website_uri: 'http://localhost:8080' ACCOUNT_ACTIVATION_DAYS: 7 @@ -47,3 +48,4 @@ EMAIL_HOST_PASSWORD: p@$$w0rd9876543210 EMAIL_HOST_USER: django@example.com EMAIL_PORT: 2525 EMAIL_USE_TLS: True +DEFAULT_FROM_EMAIL: webmaster@localhost 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 @@ -10,6 +10,11 @@ </div> <div class="row"> + <div class="col s12 right-align"> + <a href="{% url 'invite_user' %}" class="btn blue">Invite User</a> </div> +</div> + +<div class="row"> <div class="col s12"> <table class="striped bordered"> <thead> 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 %} + + +<div class="row"> + <div class="col s12"> + + <form action="" method="post">{% csrf_token %} + {% for field in form %} + <p> + {{field.label_tag}} {{field}} + </p> + {% endfor %} + <input type="submit" class="btn blue" value="Update" /> + </form> + + </div> +</div> + +{% 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<user_id>\d+)/identity/default/(?P<pk>\d+)$', views.SetDefaultIdentity, name='identity_default'), url(r'drivers/(?P<user_id>\d+)/invoice/edit/(?P<pk>\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): diff --git a/app/dispatchAuth/models.py b/app/dispatchAuth/models.py index 8173146..a1c4b55 100644 --- a/app/dispatchAuth/models.py +++ b/app/dispatchAuth/models.py @@ -1,5 +1,5 @@ from django.contrib.auth.models import AbstractUser, AbstractBaseUser, PermissionsMixin, BaseUserManager -from app.settings import WEBSITE_URI +from app.settings import WEBSITE_URI, WEB_APP_NAME from django.template.loader import render_to_string from django.core.mail import send_mail from django.core.urlresolvers import reverse @@ -77,7 +77,8 @@ class User(PermissionsMixin, AbstractBaseUser): """Send an invite for a new user to register""" current_site = WEBSITE_URI message = render_to_string('dispatch/invite_email.txt', - { 'name': name, 'user': self, 'site': current_site }) + { 'name': name, 'user': self, 'site': current_site, + 'app_name': WEB_APP_NAME }) send_mail("Invitation to register at {}".format(current_site), message, |
