Skip to content

Commit

Permalink
Adds form for subscription
Browse files Browse the repository at this point in the history
  • Loading branch information
DerGut committed Apr 30, 2018
1 parent c307359 commit 1996a43
Show file tree
Hide file tree
Showing 8 changed files with 69 additions and 19 deletions.
2 changes: 1 addition & 1 deletion creator/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ def clean(self):

class SubscriptionForm(DetailsForm):
email = forms.EmailField(required=True)
first_send_date = forms.DateField(
first_send_date = forms.CharField(
required=True,
widget=forms.TextInput(attrs={
'class': 'datepicker',
Expand Down
4 changes: 2 additions & 2 deletions creator/management/commands/send_mails.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ def new_email(cls, subscription, pdf):
Bye
""".format(first_name=subscription.first_name)
html_content = render_to_string('creator/email_subscription.html', {'context': subscription})
html_content = render_to_string('creator/subscription_email.html', {'context': subscription})

from_email = "subscription@stundenzettel-creator.xyz"
recipient_list = [subscription.email]
Expand All @@ -78,7 +78,7 @@ def new_email(cls, subscription, pdf):
def generate_pdf(cls, subscription):
details = forms.defaults
details.update({
'name': subscription.name,
'surnname': subscription.surname,
'first_name': subscription.first_name,
'year': subscription.next_send_date.year,
'month': subscription.next_send_date.month,
Expand Down
20 changes: 20 additions & 0 deletions creator/migrations/0002_auto_20180430_0945.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# -*- coding: utf-8 -*-
# Generated by Django 1.11.3 on 2018-04-30 07:45
from __future__ import unicode_literals

from django.db import migrations


class Migration(migrations.Migration):

dependencies = [
('creator', '0001_initial'),
]

operations = [
migrations.RenameField(
model_name='subscription',
old_name='name',
new_name='surname',
),
]
11 changes: 6 additions & 5 deletions creator/static/creator/js/main.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
$(document).ready(function(){
$(".datepicker").flatpickr({});
$(".daterangepicker").flatpickr({
let datepickerOptions = {
altInput: true,
altFormat: "F j",
dateFormat: "Y-m-d",
mode: "range"
});
dateFormat: "Y-m-d"
};
$(".datepicker").flatpickr(datepickerOptions);
datepickerOptions.mode = "range";
$(".daterangepicker").flatpickr(datepickerOptions);
$(".collapsible").collapsible();
});
14 changes: 14 additions & 0 deletions creator/templates/creator/subscription_success.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{% extends "creator/base.html" %}

{% block container %}
<h2>Success</h2>

<br/>

<div class="row">
<div class="col s 12 l9">
Your subscription has been processed. You will receive your first timesheet on {{ subscription.next_send_date }}
</div>
</div>
{% endblock %}

7 changes: 4 additions & 3 deletions creator/urls.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
from django.conf.urls import url

from creator.views import DetailsFormView, ResultPdfView, SubscriptionFormView
from creator.views import DetailsFormView, ResultPdfView, SubscriptionFormView, SuccessView

urlpatterns = [
url(r'^$', DetailsFormView.as_view(), name='index'),
url(r'^result', ResultPdfView.as_view(), name='result'),
url(r'^subscribe', SubscriptionFormView.as_view(), name='subscribe'),
url(r'^result/', ResultPdfView.as_view(), name='result'),
url(r'^subscribe/', SubscriptionFormView.as_view(), name='subscribe'),
url(r'^success/', SuccessView.as_view(), name='success')
]
30 changes: 22 additions & 8 deletions creator/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
import random

import numpy as np
from django.shortcuts import get_object_or_404
from django.views import View
from django.views.generic import DetailView
from django.views.generic.edit import FormView
from easy_pdf.views import PDFTemplateView
import holidays
Expand Down Expand Up @@ -148,19 +151,30 @@ class SubscriptionFormView(FormView):
success_url = '/success/'

def form_valid(self, form):
Subscription.objects.create(
email=form.email,
first_send_date=form.first_send_date,
next_send_date=form.first_send_date,
hours=form.hours,
unit_of_organisation=form.unit_of_organisation,
first_name=form.first_name,
surname=form.surname
subscription = Subscription.objects.create(
email=form.cleaned_data['email'],
first_send_date=form.cleaned_data['first_send_date'],
next_send_date=form.cleaned_data['first_send_date'],
hours=form.cleaned_data['hours'],
unit_of_organisation=form.cleaned_data['unit_of_organisation'],
first_name=form.cleaned_data['first_name'],
surname=form.cleaned_data['surname']
)

self.request.session['subscription_id'] = subscription.pk

return super().form_valid(form)


class SuccessView(DetailView):
template_name = 'creator/subscription_success.html'

def get_object(self, queryset=None):
return get_object_or_404(
Subscription, pk=self.request.session['subscription_id']
)


class ResultPdfView(PDFTemplateView):
template_name = 'creator/timesheet.html'

Expand Down

0 comments on commit 1996a43

Please sign in to comment.