Skip to content
This repository has been archived by the owner on Jan 26, 2021. It is now read-only.

Commit

Permalink
Merge pull request #825 from anjali-dhanuka/report_pdf
Browse files Browse the repository at this point in the history
Report pdf
  • Loading branch information
abarya authored Aug 1, 2018
2 parents 2a1e158 + 7405a84 commit dc7673e
Show file tree
Hide file tree
Showing 7 changed files with 139 additions and 1 deletion.
2 changes: 2 additions & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,6 @@ django-cities-light == 3.2.0
Unidecode == 0.4.19
django-braces == 1.9.0
djangorestframework == 3.8.2
django-easy-pdf == 0.1.1
WeasyPrint == 0.34

10 changes: 10 additions & 0 deletions vms/administrator/templates/administrator/confirm_report.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
Hello {{volunteer.first_name}} {{volunteer.last_name}},

{{admin.first_name}} {{admin.last_name}} has approved and created your Volunteer Hours Report. It is attached in this email with additional contact information if your organization needs to contact an administrator.

Thank you for your service.


Best,
{{volunteer.organization}}

47 changes: 47 additions & 0 deletions vms/administrator/templates/administrator/pdf.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
<html>
<body>
{{report.date_submitted}}<br>
AnitaB.org<br>
1501 Page Mill Road<br>
MS 1105<br>
Palo Alto, CA 94304<br>
<br>
To Whom It May Concern:<br>
<br>
Re: {{report.volunteer.first_name}} {{report.volunteer.last_name}}<br>
<br>
This letter is to confirm that {{report.volunteer.first_name}} {{report.volunteer.last_name}} completed {{report.total_hrs}} of unpaid volunteer work at AnitaB.org. All details related to their volunteer work is included below:

<hr />
<div class="well">
<table class="table table-striped table-hover">
<td>Event Name</td>
<td>Job Name</td>
<td>Date</td>
<td>Logged Start Time</td>
<td>Logged End Time</td>
<td>Duration</td>
{% for report in report_list %}
<tr>
<td>{{report.event_name}}</td>
<td>{{report.job_name}}</td>
<td>{{report.date}}</td>
<td>{{report.logged_start_time}}</td>
<td>{{report.logged_end_time}}</td>
<td>{{report.duration}}</td>
</tr>
{% endfor %}
</table>
</div>
<hr />

<br>
If you require further confirmation of the report generated above, please contact {{admin.first_name}} {{admin.last_name}} at {{admin.email}}.
<br><br>

{{admin.first_name}} {{admin.last_name}}<br>
{{admin.organization}}<br>
{{admin.email}}
</body>
</html>

9 changes: 9 additions & 0 deletions vms/administrator/templates/administrator/reject_report.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
Hello {{volunteer.first_name}} {{volunteer.last_name}},

Unfortunately, {{admin.first_name}} {{admin.last_name}} has rejected your request for your Volunteer Hours Report. Please contact {{admin.first_name}} {{admin.last_name}} at {{admin.email}} to learn the reasons why the request was not processed. If you are aware about the errors, please adjust your report and re-submit your request.

Thank you for your service.

Best,
{{volunteer.organization}}

41 changes: 41 additions & 0 deletions vms/administrator/tests/test_report.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

# Django
from django.contrib.staticfiles.testing import LiveServerTestCase
from django.core import mail

# local Django
from selenium.common.exceptions import NoSuchElementException
Expand All @@ -23,6 +24,7 @@
register_past_event_utility, register_past_job_utility, register_past_shift_utility,
create_report_with_details, create_volunteer_with_details)


class Report(LiveServerTestCase):

@classmethod
Expand Down Expand Up @@ -152,3 +154,42 @@ def test_approve_report(self):
self.assertEqual(report_page.remove_i18n(self.driver.current_url), self.live_server_url + report_page.administrator_report_page)
with self.assertRaises(NoSuchElementException):
report_page.get_report()

def test_email_on_report_approval(self):
vol = create_volunteer()
register_past_event_utility()
register_past_job_utility()
shift = register_past_shift_utility()
start=datetime.time(hour=10, minute=0)
end=datetime.time(hour=11, minute=0)
logged_shift = log_hours_with_details(vol, shift, start, end)
report = create_report_with_details(vol, logged_shift)
mail.send_mail("Report Approved", "message", "[email protected]", [vol.email])
self.assertEqual(len(mail.outbox), 1)
msg = mail.outbox[0]
self.assertEqual(msg.subject, 'Report Approved')
self.assertEqual(msg.to, ['[email protected]'])
response = self.client.get('/administrator/report/approve/%s'%report.id)
self.assertEqual(response.status_code, 302)

def test_email_on_reject_report(self):
self.report_page.go_to_admin_report()
vol = create_volunteer()
register_past_event_utility()
register_past_job_utility()
shift = register_past_shift_utility()
start=datetime.time(hour=10, minute=0)
end=datetime.time(hour=11, minute=0)
logged_shift = log_hours_with_details(vol, shift, start, end)
create_report_with_details(vol, logged_shift)
report_page = self.report_page
report_page.get_page(self.live_server_url, PageUrls.administrator_report_page)
self.assertEqual(report_page.get_rejection_context(), 'Reject')
report_page.reject_report()
mail.outbox = []
mail.send_mail("Report Rejected", "message", "[email protected]", [vol.email])
self.assertEqual(len(mail.outbox), 1)
msg = mail.outbox[0]
self.assertEqual(msg.subject, 'Report Rejected')
self.assertEqual(msg.to, ['[email protected]'])

30 changes: 29 additions & 1 deletion vms/administrator/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,15 @@
from django.core.urlresolvers import reverse, reverse_lazy
from django.http import HttpResponseRedirect
from django.shortcuts import render
from django.template.loader import render_to_string
from django.utils.decorators import method_decorator
from django.views.generic import ListView
from django.views.generic.detail import DetailView
from django.views.generic import View
from django.views.generic.edit import FormView, UpdateView
from easy_pdf.rendering import render_to_pdf
from django.core.mail.message import EmailMessage
from django.core.mail import send_mail

# local Django
from administrator.forms import ReportForm, AdministratorForm
Expand Down Expand Up @@ -49,6 +53,14 @@ def reject(request, report_id):
report = get_report_by_id(report_id)
report.confirm_status = 2
report.save()
volunteer = report.volunteer
admin = Administrator.objects.get(user=request.user)
message = render_to_string('administrator/reject_report.html',
{
'volunteer': volunteer,
'admin': admin,
})
send_mail("Report Rejected", message, "[email protected]", [volunteer.email])
return HttpResponseRedirect('/administrator/report')

def approve(request, report_id):
Expand All @@ -61,9 +73,25 @@ def approve(request, report_id):
report = get_report_by_id(report_id)
report.confirm_status = 1
report.save()
admin = Administrator.objects.get(user=request.user)
volunteer_shift_list = report.volunteer_shifts.all()
report_list = generate_report(volunteer_shift_list)
volunteer = report.volunteer
post_pdf = render_to_pdf('administrator/pdf.html',
{'report': report,
'admin': admin,
'report_list': report_list,},
)
message = render_to_string('administrator/confirm_report.html',
{
'volunteer': volunteer,
'admin': admin,
})
msg = EmailMessage("Report Approved", message, "[email protected]", [report.volunteer.email])
msg.attach('file.pdf', post_pdf, 'application/pdf')
msg.send()
return HttpResponseRedirect('/administrator/report')


def show_report(request, report_id):
"""
displays the report
Expand Down
1 change: 1 addition & 0 deletions vms/vms/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
'cities_light',
'pom',
'rest_framework',
'easy_pdf',
)

MIDDLEWARE_CLASSES = (
Expand Down

0 comments on commit dc7673e

Please sign in to comment.