Merge pull request #107 from danieldupriest/request-tracker-integration

Implement Request Tracker integration
This commit is contained in:
rupikad 2019-03-02 21:17:53 -08:00 committed by GitHub
commit 914a35c7fb
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
10 changed files with 55 additions and 13 deletions

1
.gitignore vendored
View file

@ -2,6 +2,7 @@
# Edit at https://www.gitignore.io/?templates=linux,macos,python,django,windows,pycharm,intellij,visualstudio
### Django ###
*.env
*.log
*.pot
*.pyc

View file

@ -1,4 +1,4 @@
EMAIL_HOST_USER=accountemail@yourmail.com
EMAIL_HOST_PASSWORD=accountpasswordhere
SUBMIT_REPORT_DESTINATION_EMAIL=to-address@yourmail.com
EMAIL_HOST_USER=accountemail@youremail.com
EMAIL_HOST_PASSWORD=yourpassword
SUBMIT_REPORT_DESTINATION_EMAIL=administratoremail@yourmail.com
SUBMIT_REPORT_FROM_EMAIL=from-address@yourmail.com

View file

@ -0,0 +1,18 @@
# Generated by Django 2.1.7 on 2019-03-01 20:17
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('backend', '0008_auto_20190214_1421'),
]
operations = [
migrations.AddField(
model_name='report',
name='reference_number',
field=models.CharField(default='', max_length=32),
),
]

View file

@ -13,6 +13,7 @@ class Report(models.Model):
date_created = models.DateTimeField('date created', default=datetime.date.today)
date_submitted = models.DateTimeField('date submitted', default=datetime.date.today)
submitted = models.BooleanField(default=False)
reference_number = models.CharField(max_length=32, default='')
def __str__(self):
"""

View file

@ -4,6 +4,7 @@
</head>
<body>
<h1>Title: {{ title }}</h1>
<p>Reference #: {{ reference_number }}</p>
{% for section in sections %}
{% if section.completed %}
<h2>{{section.title}}</h2>

View file

@ -4,6 +4,7 @@
***
Title: {{title}}
Reference #: {{reference_number}}
{% for section in sections %}
{{section.title}}
{% for field in section.fields %}

View file

@ -23,6 +23,7 @@ def get_report(report_pk):
"date_created": i.date_created,
"submitted": i.submitted,
"date_submitted": i.date_submitted,
"reference_number": i.reference_number,
}
# append the sections for each report
data.update(get_sections(i.id))
@ -121,8 +122,12 @@ def report(request):
}
"""
# Create the report
report = Report.objects.create(user_id=request.user, title=request.data['title'],
date_created=datetime.date.today())
report = Report.objects.create(
user_id=request.user,
title=request.data['title'],
date_created=datetime.date.today(),
reference_number=request.data['reference']
)
report.save()
# Create the sections
@ -161,6 +166,7 @@ def reports(request):
"date_created": i.date_created,
"submitted": i.submitted,
"date_submitted": i.date_submitted,
"reference_number": i.reference_number,
}
# append the sections for each report
report_set["reports"].append(data.copy())
@ -385,13 +391,23 @@ def send_report_to_admin(request, report_pk):
cc = request.user.email
msg_html = render_to_string('backend/email.html', params)
msg_plain = render_to_string('backend/email.txt', params)
message = EmailMultiAlternatives(
"Reimbursinator - {}".format(params['title']),
msg_plain,
from_email,
[to_email],
cc=[request.user.email],
)
message = None
if params['reference_number'] == '':
message = EmailMultiAlternatives(
"{}".format(params['title']),
msg_plain,
from_email,
[to_email],
cc=[request.user.email],
)
else:
message = EmailMultiAlternatives(
"[RT - Request Tracker #{}] {}".format(params['reference_number'], params['title']),
msg_plain,
from_email,
[to_email],
cc=[request.user.email],
)
message.attach_alternative(msg_html, "text/html")
for f in get_files(report_pk):
message.attach_file(f)

Binary file not shown.

View file

@ -560,7 +560,7 @@ if (newReportForm) {
newReportForm.addEventListener("submit", function(event) {
event.preventDefault();
const url = getEndpointDomain() + "api/v1/report";
const payload = JSON.stringify({ "title": event.target.elements.title.value });
const payload = JSON.stringify({ "title": event.target.elements.title.value, "reference": event.target.elements.reference.value });
console.log("Payload:\n" + payload);
const type = reportType.NEW;
makeAjaxRequest("POST", url, createReportForm, type, payload);

View file

@ -51,6 +51,10 @@
<label for="title">Report title:</label>
<input type="text" class="form-control" name="title" id="title" autofocus>
</div>
<div class="form-group">
<label for="reference">Ticket number (if available):</label>
<input type="text" class="form-control" name="reference" id="reference">
</div>
<button type="submit" class="btn btn-primary" data-toggle="modal" data-target="#newReportModal">Create</button>
</form>
</div>