Completed
Pull Request — master (#204)
by
unknown
01:36
created

my_display_for_field()   A

Complexity

Conditions 2

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 2
c 1
b 0
f 0
dl 0
loc 4
rs 10
1
# coding: utf8
2
3
"""
4
This software is licensed under the Apache 2 license, quoted below.
5
6
Copyright 2014 Crystalnix Limited
7
8
Licensed under the Apache License, Version 2.0 (the "License"); you may not
9
use this file except in compliance with the License. You may obtain a copy of
10
the License at
11
12
    http://www.apache.org/licenses/LICENSE-2.0
13
14
Unless required by applicable law or agreed to in writing, software
15
distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
16
WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
17
License for the specific language governing permissions and limitations under
18
the License.
19
"""
20
21
from django.contrib import admin
22
from django.contrib.admin import utils
23
from django.utils.encoding import smart_text
24
25
from omaha.models import Channel, Platform, Application, Version, Action, PartialUpdate, Data
26
from omaha.forms import ApplicationAdminForm, VersionAdminForm, ActionAdminForm, DataAdminForm
27
from dynamic_preferences.models import GlobalPreferenceModel, UserPreferenceModel
28
29
from versionfield import VersionField
30
31
admin.site.unregister(GlobalPreferenceModel)
32
admin.site.unregister(UserPreferenceModel)
33
34
@admin.register(Platform)
35
class PlatformAdmin(admin.ModelAdmin):
36
    list_display = ('name',)
37
38
39
@admin.register(Channel)
40
class ChannelAdmin(admin.ModelAdmin):
41
    list_display = ('name',)
42
43
44
class DataInline(admin.StackedInline):
45
    model = Data
46
    extra = 0
47
    form = DataAdminForm
48
49
50
@admin.register(Application)
51
class ApplicationAdmin(admin.ModelAdmin):
52
    list_display = ('name', 'id',)
53
    form = ApplicationAdminForm
54
    inlines = (DataInline,)
55
56
57
class ActionInline(admin.StackedInline):
58
    model = Action
59
    extra = 0
60
    form = ActionAdminForm
61
62
63
class PartialUpdateInline(admin.StackedInline):
64
    model = PartialUpdate
65
    extra = 0
66
67
68
@admin.register(Version)
69
class VersionAdmin(admin.ModelAdmin):
70
    inlines = (ActionInline, PartialUpdateInline,)
71
    list_display = ('created', 'modified', 'app', 'version', 'channel', 'platform', 'is_enabled')
72
    list_display_links = ('created', 'modified', 'version',)
73
    list_filter = ('channel__name', 'platform__name', 'app__name',)
74
    readonly_fields = ('file_hash',)
75
    form = VersionAdminForm
76
77
78
def my_display_for_field(value, field, *args, **kwargs):
79
    if isinstance(field, VersionField):
80
        return smart_text(value)
81
    return django_display_for_field(value, field, *args, **kwargs)
82
83
import copy
84
django_display_for_field = copy.deepcopy(utils.display_for_field)
85
utils.display_for_field = my_display_for_field