This repository has been archived by the owner on Jan 26, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #825 from anjali-dhanuka/report_pdf
Report pdf
- Loading branch information
Showing
7 changed files
with
139 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
10 changes: 10 additions & 0 deletions
10
vms/administrator/templates/administrator/confirm_report.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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}} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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}} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 | ||
|
@@ -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 | ||
|
@@ -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]']) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 | ||
|
@@ -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): | ||
|
@@ -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 | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -39,6 +39,7 @@ | |
'cities_light', | ||
'pom', | ||
'rest_framework', | ||
'easy_pdf', | ||
) | ||
|
||
MIDDLEWARE_CLASSES = ( | ||
|