Compare commits

...

5 Commits

Author SHA1 Message Date
Nate Smith 31ea760f9d add template for ticket with email sending 2019-08-07 01:06:38 -05:00
Nate Smith bfbf37fceb WIP commit 2019-08-07 01:05:58 -05:00
Nate Smith e0caeefce2 good migration 2019-07-19 20:53:17 -05:00
Nate Smith 004353343f remove bad migration 2019-07-19 20:53:04 -05:00
Nate Smith 05d5898fa9 add EmailTemplate 2019-07-19 20:52:01 -05:00
4 changed files with 103 additions and 1 deletions

View File

@ -1,6 +1,7 @@
from django.conf.urls import url
from django.contrib import admin from django.contrib import admin
from django.forms import ModelForm from django.forms import ModelForm
from .models import Ticket, Note from .models import Ticket, Note, EmailTemplate
class ImmutableNoteInline(admin.TabularInline): class ImmutableNoteInline(admin.TabularInline):
@ -23,6 +24,11 @@ class NewNoteInline(admin.StackedInline):
return queryset.none() return queryset.none()
@admin.register(EmailTemplate)
class EmailTemplateAdmin(admin.ModelAdmin):
fields = ('name', 'body')
@admin.register(Ticket) @admin.register(Ticket)
class TicketAdmin(admin.ModelAdmin): class TicketAdmin(admin.ModelAdmin):
inlines = [ImmutableNoteInline, NewNoteInline] inlines = [ImmutableNoteInline, NewNoteInline]
@ -31,6 +37,8 @@ class TicketAdmin(admin.ModelAdmin):
list_filter = ('issue_status', 'issue_type', 'assigned') list_filter = ('issue_status', 'issue_type', 'assigned')
fields = ('submitted', 'name', 'email', 'assigned', 'issue_status', 'issue_type', 'issue_text') fields = ('submitted', 'name', 'email', 'assigned', 'issue_status', 'issue_type', 'issue_text')
change_form_template = "admin/ticket_with_email.html"
def save_related(self, request, form, formsets, change): def save_related(self, request, form, formsets, change):
# THIS IS EXTREMELY BOOTLEG AND MAY BREAK IF MORE INLINES ARE ADDED TO THIS ADMIN. # THIS IS EXTREMELY BOOTLEG AND MAY BREAK IF MORE INLINES ARE ADDED TO THIS ADMIN.
for formset in formsets: for formset in formsets:
@ -42,3 +50,23 @@ class TicketAdmin(admin.ModelAdmin):
note_form.save(commit=False) note_form.save(commit=False)
note_form.save_m2m() note_form.save_m2m()
return super().save_related(request, form, formsets, change) return super().save_related(request, form, formsets, change)
def change_view(self, request, object_id, form_url='', extra_context=None):
if extra_context is None:
extra_context = {}
extra_context['email_templates'] = EmailTemplate.objects.all()
return super().change_view(request, object_id, form_url, extra_context=extra_context)
def get_urls(self):
urls = super().get_urls()
custom_urls = [
url(r'emails/send$', self.admin_site.admin_view(self.send_email_view)),
]
return urls + custom_urls
def send_email_view(self, request):
pass

View File

@ -0,0 +1,23 @@
# -*- coding: utf-8 -*-
# Generated by Django 1.10.2 on 2019-07-20 01:53
from __future__ import unicode_literals
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('help', '0008_auto_20190718_2223'),
]
operations = [
migrations.CreateModel(
name='EmailTemplate',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('name', models.CharField(max_length=50)),
('body', models.TextField()),
],
),
]

View File

@ -46,3 +46,11 @@ class Note(Model):
def __str__(self): def __str__(self):
return "admin note" return "admin note"
class EmailTemplate(Model):
name = CharField(blank=False, null=False, max_length=50)
body = TextField(blank=False, null=False)
def __str__(self):
return f"'{self.name}' email template"

View File

@ -0,0 +1,43 @@
{% extends 'admin/change_form.html' %}
{% block after_field_sets %}
<h2>Send an email</h2>
<table>
<tr>
<td>
<textarea id="send_email_body" rows="20" cols="60"></textarea>
</td>
<td>
<h3>Copy a template over?</h3>
<table>
<!-- loop over email_templates -->
{% for tmpl in email_templates %}
<tr>
<td>
{{ tmpl }}
{% endfor %}
<tr>
<td><button>copy</button></td>
<td>
<h4>lost key</h4>
<p>Hi!<br>to update your key, please respond to this message with your new pub key.</p>
</td>
</tr>
<tr>
<td><button>copy</button></td>
<td>
<h4>delete confirmation</h4>
<p>Hi,<br>this email is to confirm you would like your town account deleted. would you
like your public html files to remain accessible?</p>
</td>
</tr>
</table>
</td>
</tr>
<tr>
<td>
<button>Send!</button>
</td>
</tr>
</table>
{% endblock %}