Merge pull request #107 from danieldupriest/request-tracker-integration
Implement Request Tracker integration
This commit is contained in:
commit
914a35c7fb
10 changed files with 55 additions and 13 deletions
1
.gitignore
vendored
1
.gitignore
vendored
|
@ -2,6 +2,7 @@
|
||||||
# Edit at https://www.gitignore.io/?templates=linux,macos,python,django,windows,pycharm,intellij,visualstudio
|
# Edit at https://www.gitignore.io/?templates=linux,macos,python,django,windows,pycharm,intellij,visualstudio
|
||||||
|
|
||||||
### Django ###
|
### Django ###
|
||||||
|
*.env
|
||||||
*.log
|
*.log
|
||||||
*.pot
|
*.pot
|
||||||
*.pyc
|
*.pyc
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
EMAIL_HOST_USER=accountemail@yourmail.com
|
EMAIL_HOST_USER=accountemail@youremail.com
|
||||||
EMAIL_HOST_PASSWORD=accountpasswordhere
|
EMAIL_HOST_PASSWORD=yourpassword
|
||||||
SUBMIT_REPORT_DESTINATION_EMAIL=to-address@yourmail.com
|
SUBMIT_REPORT_DESTINATION_EMAIL=administratoremail@yourmail.com
|
||||||
SUBMIT_REPORT_FROM_EMAIL=from-address@yourmail.com
|
SUBMIT_REPORT_FROM_EMAIL=from-address@yourmail.com
|
||||||
|
|
18
back/backend/migrations/0009_report_reference_number.py
Normal file
18
back/backend/migrations/0009_report_reference_number.py
Normal 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),
|
||||||
|
),
|
||||||
|
]
|
|
@ -13,6 +13,7 @@ class Report(models.Model):
|
||||||
date_created = models.DateTimeField('date created', default=datetime.date.today)
|
date_created = models.DateTimeField('date created', default=datetime.date.today)
|
||||||
date_submitted = models.DateTimeField('date submitted', default=datetime.date.today)
|
date_submitted = models.DateTimeField('date submitted', default=datetime.date.today)
|
||||||
submitted = models.BooleanField(default=False)
|
submitted = models.BooleanField(default=False)
|
||||||
|
reference_number = models.CharField(max_length=32, default='')
|
||||||
|
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
"""
|
"""
|
||||||
|
|
|
@ -4,6 +4,7 @@
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
<h1>Title: {{ title }}</h1>
|
<h1>Title: {{ title }}</h1>
|
||||||
|
<p>Reference #: {{ reference_number }}</p>
|
||||||
{% for section in sections %}
|
{% for section in sections %}
|
||||||
{% if section.completed %}
|
{% if section.completed %}
|
||||||
<h2>{{section.title}}</h2>
|
<h2>{{section.title}}</h2>
|
||||||
|
|
|
@ -4,6 +4,7 @@
|
||||||
***
|
***
|
||||||
|
|
||||||
Title: {{title}}
|
Title: {{title}}
|
||||||
|
Reference #: {{reference_number}}
|
||||||
{% for section in sections %}
|
{% for section in sections %}
|
||||||
{{section.title}}
|
{{section.title}}
|
||||||
{% for field in section.fields %}
|
{% for field in section.fields %}
|
||||||
|
|
|
@ -23,6 +23,7 @@ def get_report(report_pk):
|
||||||
"date_created": i.date_created,
|
"date_created": i.date_created,
|
||||||
"submitted": i.submitted,
|
"submitted": i.submitted,
|
||||||
"date_submitted": i.date_submitted,
|
"date_submitted": i.date_submitted,
|
||||||
|
"reference_number": i.reference_number,
|
||||||
}
|
}
|
||||||
# append the sections for each report
|
# append the sections for each report
|
||||||
data.update(get_sections(i.id))
|
data.update(get_sections(i.id))
|
||||||
|
@ -121,8 +122,12 @@ def report(request):
|
||||||
}
|
}
|
||||||
"""
|
"""
|
||||||
# Create the report
|
# Create the report
|
||||||
report = Report.objects.create(user_id=request.user, title=request.data['title'],
|
report = Report.objects.create(
|
||||||
date_created=datetime.date.today())
|
user_id=request.user,
|
||||||
|
title=request.data['title'],
|
||||||
|
date_created=datetime.date.today(),
|
||||||
|
reference_number=request.data['reference']
|
||||||
|
)
|
||||||
report.save()
|
report.save()
|
||||||
|
|
||||||
# Create the sections
|
# Create the sections
|
||||||
|
@ -161,6 +166,7 @@ def reports(request):
|
||||||
"date_created": i.date_created,
|
"date_created": i.date_created,
|
||||||
"submitted": i.submitted,
|
"submitted": i.submitted,
|
||||||
"date_submitted": i.date_submitted,
|
"date_submitted": i.date_submitted,
|
||||||
|
"reference_number": i.reference_number,
|
||||||
}
|
}
|
||||||
# append the sections for each report
|
# append the sections for each report
|
||||||
report_set["reports"].append(data.copy())
|
report_set["reports"].append(data.copy())
|
||||||
|
@ -385,13 +391,23 @@ def send_report_to_admin(request, report_pk):
|
||||||
cc = request.user.email
|
cc = request.user.email
|
||||||
msg_html = render_to_string('backend/email.html', params)
|
msg_html = render_to_string('backend/email.html', params)
|
||||||
msg_plain = render_to_string('backend/email.txt', params)
|
msg_plain = render_to_string('backend/email.txt', params)
|
||||||
message = EmailMultiAlternatives(
|
message = None
|
||||||
"Reimbursinator - {}".format(params['title']),
|
if params['reference_number'] == '':
|
||||||
msg_plain,
|
message = EmailMultiAlternatives(
|
||||||
from_email,
|
"{}".format(params['title']),
|
||||||
[to_email],
|
msg_plain,
|
||||||
cc=[request.user.email],
|
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")
|
message.attach_alternative(msg_html, "text/html")
|
||||||
for f in get_files(report_pk):
|
for f in get_files(report_pk):
|
||||||
message.attach_file(f)
|
message.attach_file(f)
|
||||||
|
|
BIN
back/db.sqlite3
BIN
back/db.sqlite3
Binary file not shown.
|
@ -560,7 +560,7 @@ if (newReportForm) {
|
||||||
newReportForm.addEventListener("submit", function(event) {
|
newReportForm.addEventListener("submit", function(event) {
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
const url = getEndpointDomain() + "api/v1/report";
|
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);
|
console.log("Payload:\n" + payload);
|
||||||
const type = reportType.NEW;
|
const type = reportType.NEW;
|
||||||
makeAjaxRequest("POST", url, createReportForm, type, payload);
|
makeAjaxRequest("POST", url, createReportForm, type, payload);
|
||||||
|
|
|
@ -51,6 +51,10 @@
|
||||||
<label for="title">Report title:</label>
|
<label for="title">Report title:</label>
|
||||||
<input type="text" class="form-control" name="title" id="title" autofocus>
|
<input type="text" class="form-control" name="title" id="title" autofocus>
|
||||||
</div>
|
</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>
|
<button type="submit" class="btn btn-primary" data-toggle="modal" data-target="#newReportModal">Create</button>
|
||||||
</form>
|
</form>
|
||||||
</div>
|
</div>
|
||||||
|
|
Loading…
Reference in a new issue