2014-04-28 10:18:42 +00:00
|
|
|
from django.utils.translation import ugettext as _
|
2009-05-17 11:34:55 +00:00
|
|
|
from django.contrib import admin
|
2018-07-24 15:25:07 +00:00
|
|
|
from django.urls import reverse
|
2016-07-26 21:08:23 +00:00
|
|
|
from .models import (Choice, Questionnaire, Question, QuestionSet, Subject,
|
|
|
|
RunInfo, RunInfoHistory, Answer, DBStylesheet, Landing)
|
2009-05-17 11:34:55 +00:00
|
|
|
|
|
|
|
adminsite = admin.site
|
|
|
|
|
2015-03-10 22:47:13 +00:00
|
|
|
|
2009-05-17 11:34:55 +00:00
|
|
|
class SubjectAdmin(admin.ModelAdmin):
|
|
|
|
search_fields = ['surname', 'givenname', 'email']
|
|
|
|
list_display = ['surname', 'givenname', 'email']
|
|
|
|
|
2015-03-10 22:47:13 +00:00
|
|
|
|
2009-05-17 11:34:55 +00:00
|
|
|
class ChoiceAdmin(admin.ModelAdmin):
|
|
|
|
list_display = ['sortid', 'text', 'value', 'question']
|
|
|
|
|
2015-03-10 22:47:13 +00:00
|
|
|
|
2009-05-17 11:34:55 +00:00
|
|
|
class ChoiceInline(admin.TabularInline):
|
|
|
|
ordering = ['sortid']
|
|
|
|
model = Choice
|
|
|
|
extra = 5
|
|
|
|
|
2015-03-10 22:47:13 +00:00
|
|
|
|
2009-05-17 11:34:55 +00:00
|
|
|
class QuestionSetAdmin(admin.ModelAdmin):
|
|
|
|
ordering = ['questionnaire', 'sortid', ]
|
|
|
|
list_filter = ['questionnaire', ]
|
|
|
|
list_display = ['questionnaire', 'heading', 'sortid', ]
|
|
|
|
list_editable = ['sortid', ]
|
|
|
|
|
2015-03-10 22:47:13 +00:00
|
|
|
|
2009-05-17 11:34:55 +00:00
|
|
|
class QuestionAdmin(admin.ModelAdmin):
|
2015-03-10 22:47:13 +00:00
|
|
|
ordering = ['questionset__questionnaire', 'questionset', 'sort_id', 'number']
|
2009-05-17 11:34:55 +00:00
|
|
|
inlines = [ChoiceInline]
|
2014-05-05 19:38:45 +00:00
|
|
|
list_filter = ['questionset__questionnaire']
|
2009-05-17 11:34:55 +00:00
|
|
|
|
2009-09-11 13:16:50 +00:00
|
|
|
def changelist_view(self, request, extra_context=None):
|
|
|
|
"Hack to have Questionnaire list accessible for custom changelist template"
|
|
|
|
if not extra_context:
|
|
|
|
extra_context = {}
|
2014-05-05 19:38:45 +00:00
|
|
|
|
|
|
|
questionnaire_id = request.GET.get('questionset__questionnaire__id__exact', None)
|
|
|
|
if questionnaire_id:
|
|
|
|
args = {"id": questionnaire_id}
|
|
|
|
else:
|
|
|
|
args = {}
|
|
|
|
extra_context['questionnaires'] = Questionnaire.objects.filter(**args).order_by('name')
|
2009-09-11 13:16:50 +00:00
|
|
|
return super(QuestionAdmin, self).changelist_view(request, extra_context)
|
2009-05-17 11:34:55 +00:00
|
|
|
|
2015-03-10 22:47:13 +00:00
|
|
|
|
2009-05-17 11:34:55 +00:00
|
|
|
class QuestionnaireAdmin(admin.ModelAdmin):
|
2014-04-28 10:18:42 +00:00
|
|
|
list_display = ('name', 'redirect_url', 'export')
|
|
|
|
readonly_fields = ('export',)
|
|
|
|
|
|
|
|
def export(self, obj):
|
2017-06-08 21:28:18 +00:00
|
|
|
csv_url = reverse("export_csv", args=[obj.id,])
|
|
|
|
summary_url = reverse("export_summary", args=[obj.id,])
|
|
|
|
return '<a href="{}">{}</a> <a href="{}">{}</a>'.format(
|
|
|
|
csv_url, _("Download data"), summary_url, _("Show summary")
|
|
|
|
)
|
2014-04-28 10:18:42 +00:00
|
|
|
|
|
|
|
export.allow_tags = True
|
|
|
|
export.short_description = _('Export to CSV')
|
2009-05-17 11:34:55 +00:00
|
|
|
|
2015-03-10 22:47:13 +00:00
|
|
|
|
2009-05-17 11:34:55 +00:00
|
|
|
class RunInfoAdmin(admin.ModelAdmin):
|
2016-11-03 15:43:08 +00:00
|
|
|
list_display = ['random', 'run', 'subject', 'created', 'emailsent', 'lastemailerror']
|
2009-05-17 11:34:55 +00:00
|
|
|
pass
|
|
|
|
|
2015-03-10 22:47:13 +00:00
|
|
|
|
2009-05-17 11:34:55 +00:00
|
|
|
class RunInfoHistoryAdmin(admin.ModelAdmin):
|
|
|
|
pass
|
|
|
|
|
2015-03-10 22:47:13 +00:00
|
|
|
|
2009-05-17 11:34:55 +00:00
|
|
|
class AnswerAdmin(admin.ModelAdmin):
|
2016-11-03 15:43:08 +00:00
|
|
|
search_fields = ['subject__email', 'run__id', 'question__number', 'answer']
|
|
|
|
list_display = ['id', 'run', 'subject', 'question']
|
|
|
|
list_filter = ['subject', 'run__id']
|
|
|
|
ordering = [ 'id', 'subject', 'run__id', 'question', ]
|
2016-07-26 21:08:23 +00:00
|
|
|
|
|
|
|
from django.contrib import admin
|
|
|
|
|
|
|
|
# new in dj1.7
|
|
|
|
# @admin.register(Landing)
|
|
|
|
class LandingAdmin(admin.ModelAdmin):
|
2016-11-03 15:43:08 +00:00
|
|
|
list_display = ('label', 'content_type', 'object_id', )
|
|
|
|
ordering = [ 'object_id', ]
|
2009-05-17 11:34:55 +00:00
|
|
|
|
|
|
|
adminsite.register(Questionnaire, QuestionnaireAdmin)
|
|
|
|
adminsite.register(Question, QuestionAdmin)
|
|
|
|
adminsite.register(QuestionSet, QuestionSetAdmin)
|
|
|
|
adminsite.register(Subject, SubjectAdmin)
|
|
|
|
adminsite.register(RunInfo, RunInfoAdmin)
|
|
|
|
adminsite.register(RunInfoHistory, RunInfoHistoryAdmin)
|
2016-01-13 09:32:55 +00:00
|
|
|
adminsite.register(Answer, AnswerAdmin)
|
2016-07-26 21:08:23 +00:00
|
|
|
adminsite.register(Landing, LandingAdmin)
|
2016-01-13 09:32:55 +00:00
|
|
|
adminsite.register(DBStylesheet)
|