NormalizationRuleAdmin   A
last analyzed

Complexity

Total Complexity 0

Size/Duplication

Total Lines 5
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 0
c 0
b 0
f 0
dl 0
loc 5
rs 10
1
# -*- coding: utf-8 -*-
2
# Copyright 2013 Mathias WOLFF
3
# This file is part of pyfreebilling.
4
#
5
# pyfreebilling is free software: you can redistribute it and/or modify
6
# it under the terms of the GNU General Public License as published by
7
# the Free Software Foundation, either version 3 of the License, or
8
# (at your option) any later version.
9
#
10
# pyfreebilling is distributed in the hope that it will be useful,
11
# but WITHOUT ANY WARRANTY; without even the implied warranty of
12
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13
# GNU General Public License for more details.
14
#
15
# You should have received a copy of the GNU General Public License
16
# along with pyfreebilling.  If not, see <http://www.gnu.org/licenses/>
17
18
from django.contrib import admin
19
from django.contrib.admin import TabularInline
20
from django.utils.translation import ugettext_lazy as _
21
22
from .models import NormalizationRule, NormalizationGroup, NormalizationRuleGroup, CallMappingRule
23
24
25
class NormalizationRuleGroupInline(TabularInline):
26
    model = NormalizationRuleGroup
27
    extra = 0
28
    collapse = True
29
    modal = True
30
31
32
class NormalizationRuleAdmin(admin.ModelAdmin):
33
    ordering = ['name', 'match_exp']
34
    list_filter = ['match_op', ]
35
    search_filter = ['^name']
36
    save_on_top = True
37
38
39
class NormalizationGroupAdmin(admin.ModelAdmin):
40
    inlines = [NormalizationRuleGroupInline, ]
41
    list_display = ['id', 'name', 'date_modified']
42
    ordering = ['name', ]
43
    search_filter = ['^name']
44
    save_on_top = True
45
46
47
class NormalizationRuleGroupAdmin(admin.ModelAdmin):
48
    ordering = ['dpid', 'pr']
49
    save_on_top = True
50
51
52
class CallMappingRuleAdmin(admin.ModelAdmin):
53
    ordering = ['dpid', 'pr']
54
    list_filter = ['attrs', ]
55
    search_filter = ['^name']
56
    save_on_top = True
57
58
    def get_readonly_fields(self, request, obj=None):
59
        if obj:  # This is the case when obj is already created. it's an edit
60
            return ['dpid', ]
61
        else:
62
            return ['dpid', ]
63
64
65
admin.site.register(NormalizationGroup, NormalizationGroupAdmin)
66
admin.site.register(NormalizationRuleGroup, NormalizationRuleGroupAdmin)
67
admin.site.register(NormalizationRule, NormalizationRuleAdmin)
68
admin.site.register(CallMappingRule, CallMappingRuleAdmin)
69