WIP commit

helpdesk-email
Nate Smith 2019-08-07 01:05:58 -05:00
parent e0caeefce2
commit bfbf37fceb
1 changed files with 29 additions and 1 deletions

View File

@ -1,6 +1,7 @@
from django.conf.urls import url
from django.contrib import admin
from django.forms import ModelForm
from .models import Ticket, Note
from .models import Ticket, Note, EmailTemplate
class ImmutableNoteInline(admin.TabularInline):
@ -23,6 +24,11 @@ class NewNoteInline(admin.StackedInline):
return queryset.none()
@admin.register(EmailTemplate)
class EmailTemplateAdmin(admin.ModelAdmin):
fields = ('name', 'body')
@admin.register(Ticket)
class TicketAdmin(admin.ModelAdmin):
inlines = [ImmutableNoteInline, NewNoteInline]
@ -31,6 +37,8 @@ class TicketAdmin(admin.ModelAdmin):
list_filter = ('issue_status', 'issue_type', 'assigned')
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):
# THIS IS EXTREMELY BOOTLEG AND MAY BREAK IF MORE INLINES ARE ADDED TO THIS ADMIN.
for formset in formsets:
@ -42,3 +50,23 @@ class TicketAdmin(admin.ModelAdmin):
note_form.save(commit=False)
note_form.save_m2m()
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