• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

EQAR / eqar_backend / 5b970840-f92d-4ae6-9c8d-5838e1ba4171

29 Jul 2025 09:08PM UTC coverage: 86.434% (-0.8%) from 87.262%
5b970840-f92d-4ae6-9c8d-5838e1ba4171

push

circleci

web-flow
Merge pull request #551 from EQAR/development

Development

231 of 341 new or added lines in 24 files covered. (67.74%)

56 existing lines in 3 files now uncovered.

10385 of 12015 relevant lines covered (86.43%)

0.86 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

61.11
/submissionapi/admin.py
1
from django.contrib import admin
1✔
2

3
import json
1✔
4
import ast
1✔
5
from pygments import highlight
1✔
6
from pygments.lexers import JsonLexer
1✔
7
from pygments.formatters import HtmlFormatter
1✔
8

9
from django.utils.safestring import mark_safe
1✔
10

11
# Register your models here.
12
from eqar_backend.admin import admin_site, DEQARModelAdmin, DEQARStackedInline
1✔
13
from submissionapi.models import SubmissionPackageLog, SubmissionReportLog
1✔
14

15

16
class SubmissionReportLogInline(DEQARStackedInline):
1✔
17
    model = SubmissionReportLog
1✔
18
    fk_name = 'submission_package_log'
1✔
19
    verbose_name = 'Report'
1✔
20
    verbose_name_plural = 'Reports'
1✔
21
    readonly_fields = ('agency', 'report', 'report_status', 'submission_date')
1✔
22
    can_delete = False
1✔
23

24
    def has_change_permission(self, request, obj=None):
1✔
25
        return False
×
26

27
    def has_add_permission(self, request, obj=None):
1✔
28
        return False
×
29

30
class SubmissionLogAdmin(DEQARModelAdmin):
1✔
31
    list_display = ('id', 'user', 'user_ip_address', 'origin', 'submission_date')
1✔
32
    list_display_links = ('id', 'submission_date')
1✔
33
    ordering = ('-id',) # 'user', 'origin', 'submission_date')
1✔
34
    list_filter = ('user', 'origin', 'submission_date')
1✔
35
    inlines = [SubmissionReportLogInline,]
1✔
36
    readonly_fields = ('user','origin','user_ip_address','submission_date','submitted_data_pp','submission_errors_pp')
1✔
37
    exclude = ('submitted_data','submission_errors')
1✔
38

39
    def has_change_permission(self, request, obj=None):
1✔
40
        return False
×
41

42
    def has_add_permission(self, request):
1✔
43
        return False
×
44

45
    def submitted_data_pp(self, instance):
1✔
46
        # return the data as pretty-printed JSON
47
        if instance.origin == 'csv':
×
48
            return instance.submitted_data
×
49
        else:
50
            if instance.submitted_data.lstrip().startswith('{') or instance.submitted_data.lstrip().startswith('['):
×
51
                # convert dict/list repr to JSON
52
                content = json.dumps(ast.literal_eval(instance.submitted_data), indent=2)
×
53
                # highlight the data
54
                formatter = HtmlFormatter()
×
55
                response = highlight(content, JsonLexer(), formatter)
×
56
                # add the stylesheet
57
                style = "<style>" + formatter.get_style_defs() + "</style>\n"
×
58
                # return the output
59
                return mark_safe(style + response)
×
60
            else:
61
                return instance.submitted_data
×
62

63
    submitted_data_pp.short_description = 'submitted data'
1✔
64

65
    def submission_errors_pp(self, instance):
1✔
66
        # return the errors as pretty-printed JSON
NEW
67
        try:
×
NEW
68
            content = json.dumps(json.loads(instance.submission_errors), indent=2)
×
69
            # highlight the data
NEW
70
            formatter = HtmlFormatter()
×
NEW
71
            response = highlight(content, JsonLexer(), formatter)
×
72
            # add the stylesheet
NEW
73
            style = "<style>" + formatter.get_style_defs() + "</style>\n"
×
74
            # return the output
NEW
75
            return mark_safe(style + response)
×
NEW
76
        except ValueError:
×
NEW
77
            return instance.submission_errors
×
78

79
    submission_errors_pp.short_description = 'submission errors'
1✔
80

81
admin_site.register(SubmissionPackageLog, SubmissionLogAdmin)
1✔
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc