Files
@ b4a2b9c613c1
Branch filter:
Location: website/conservancy/assignment/views.py - annotation
b4a2b9c613c1
1.5 KiB
text/x-python
Calculate hours when only one day is left.
This {% widthratio %} trick is something I found online that didn't
require a django-math module to work, but I would have rather written
something that:
(b) Could have a different message when there is only one hour
left: “less than one hour left” (i.e., tested if hours == 1)
(c) Will say “hour” instead of “hours” when there is exactly 1 hour
left.
This {% widthratio %} trick is something I found online that didn't
require a django-math module to work, but I would have rather written
something that:
(b) Could have a different message when there is only one hour
left: “less than one hour left” (i.e., tested if hours == 1)
(c) Will say “hour” instead of “hours” when there is exactly 1 hour
left.
0565f9b308ed a2675ee029a5 0565f9b308ed 780e0b8dbfe3 2b1fd9ab90d9 0565f9b308ed a2675ee029a5 a2675ee029a5 47a30a750ad1 2b1fd9ab90d9 2b1fd9ab90d9 2b1fd9ab90d9 2b1fd9ab90d9 0565f9b308ed 0565f9b308ed 0565f9b308ed 0565f9b308ed 0565f9b308ed 0565f9b308ed 0565f9b308ed 0565f9b308ed cf3647942768 cf3647942768 0565f9b308ed 0565f9b308ed c9a76ea17fe3 0565f9b308ed 0565f9b308ed 0565f9b308ed 0565f9b308ed 0565f9b308ed 0565f9b308ed 780e0b8dbfe3 0565f9b308ed 0565f9b308ed 0565f9b308ed 0565f9b308ed 0565f9b308ed 0565f9b308ed 0565f9b308ed | from django.core.mail import send_mail
from django.urls import reverse_lazy
from django.views.generic import DetailView
from django.views.generic.edit import CreateView
from .forms import AssignmentForm
from .models import Assignment
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,
'copyright-assignment@sfconservancy.org',
['copyright-assignment@sfconservancy.org', 'copyright-agent@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
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
|