1
from django.shortcuts import render
2
from django.contrib.auth.decorators import login_required
3
from collections import OrderedDict
4
from notification.models import *
8
def notice_settings(request):
10
for notice_type in NoticeType.objects.all().order_by('label'):
11
# Assuming each notice_type.label begins with the name of the app
12
# followed by an underscore:
13
app = notice_type.label.partition('_')[0]
14
app_tables.setdefault(app, [])
16
for medium_id, medium_display in NOTICE_MEDIA:
17
form_label = '%s_%s' % (notice_type.label, medium_id)
18
setting = get_notification_setting(
19
request.user, notice_type, medium_id)
20
if request.method == 'POST':
21
if request.POST.get(form_label) == 'on':
26
checkbox_values.append((form_label, setting.send))
28
app_tables[app].append({'notice_type': notice_type, 'html_values': checkbox_values})
30
return render(request, 'notification/notice_settings.html', {
31
'column_headers': [medium_display for medium_id, medium_display in NOTICE_MEDIA],
32
'app_tables': OrderedDict(sorted(list(app_tables.items()), key=lambda t: t[0]))