admin.py 747 Bytes
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36

from django.contrib import admin
from .models import Submission

from script.main import analyze

from traceback import print_exc


def make_analysis(modeladmin, request, queryset):
    for submission in queryset:
        try:
            print('analisando: '+str(submission))
            analyze(submission)

            submission.processed = True

            print('salvando')
            submission.save()

            print('OK')
        except:
            print('Análise falhou')

            print_exc()


class SubmissionAdmin(admin.ModelAdmin):
    date_hierarchy = 'timestamp'

    list_display = ('author', 'course', 'processed', 'last', 'timestamp')

    actions = [make_analysis]


admin.site.register(Submission, SubmissionAdmin)