website/www/conservancy/apps/assignment/views.py

40 lines
1.4 KiB
Python
Raw Normal View History

from django.core.mail import send_mail
2021-11-30 05:15:59 +00:00
from django.urls import reverse_lazy
from django.views.generic import DetailView
2021-11-30 05:34:26 +00:00
from django.views.generic.edit import CreateView
2021-12-06 22:27:17 +00:00
from .forms import AssignmentForm
2021-11-30 05:15:59 +00:00
from .models import Assignment
2021-12-06 22:27:17 +00:00
class AssignmentCreateView(CreateView):
"""Show a form for the initial copyright assignment."""
form_class = AssignmentForm
template_name = 'assignment/assignment_form.html'
def form_valid(self, form):
intro = 'The following copyright assignment has been submitted:\n\n'
body = intro + '\n'.join(['{}: {}'.format(k, v) for k, v in form.cleaned_data.items() if k != 'agreement_terms'])
send_mail(
'Copyright assignment form: {}'.format(form.cleaned_data['full_name']),
body,
'ben@sturm.com.au',
['denver@sfconservancy.org', 'bsturmfels@sfconservancy.org'],
)
return super().form_valid(form)
def get_success_url(self, *args, **kwargs):
return reverse_lazy('assignment-thanks', kwargs={'pk': str(self.object.uuid)})
class AssignmentThanksView(DetailView):
model = Assignment
2021-11-30 05:34:26 +00:00
template_name = 'assignment/thanks.html'
def get_context_data(self, **kwargs):
context = super().get_context_data(**kwargs)
context['form'] = AssignmentForm(instance=self.object)
for _, field in context['form'].fields.items():
field.widget.attrs['disabled'] = 'disabled'
return context