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
|
|
|
import copy |
21
|
|
|
|
22
|
|
|
from django.contrib import admin |
23
|
|
|
from django.contrib.admin import utils |
24
|
|
|
from django.utils.encoding import smart_text |
25
|
|
|
|
26
|
|
|
from dynamic_preferences.models import GlobalPreferenceModel, UserPreferenceModel |
27
|
|
|
from versionfield import VersionField |
28
|
|
|
|
29
|
|
|
from omaha.models import Channel, Platform, Application, Version, Action, PartialUpdate, Data |
30
|
|
|
from omaha.forms import ApplicationAdminForm, VersionAdminForm, ActionAdminForm, DataAdminForm |
31
|
|
|
|
32
|
|
|
|
33
|
|
|
admin.site.unregister(GlobalPreferenceModel) |
34
|
|
|
admin.site.unregister(UserPreferenceModel) |
35
|
|
|
|
36
|
|
|
@admin.register(Platform) |
37
|
|
|
class PlatformAdmin(admin.ModelAdmin): |
38
|
|
|
list_display = ('name',) |
39
|
|
|
|
40
|
|
|
|
41
|
|
|
@admin.register(Channel) |
42
|
|
|
class ChannelAdmin(admin.ModelAdmin): |
43
|
|
|
list_display = ('name',) |
44
|
|
|
|
45
|
|
|
|
46
|
|
|
class DataInline(admin.StackedInline): |
47
|
|
|
model = Data |
48
|
|
|
extra = 0 |
49
|
|
|
form = DataAdminForm |
50
|
|
|
|
51
|
|
|
|
52
|
|
|
@admin.register(Application) |
53
|
|
|
class ApplicationAdmin(admin.ModelAdmin): |
54
|
|
|
list_display = ('name', 'id',) |
55
|
|
|
form = ApplicationAdminForm |
56
|
|
|
inlines = (DataInline,) |
57
|
|
|
|
58
|
|
|
class ActionInline(admin.StackedInline): |
59
|
|
|
model = Action |
60
|
|
|
extra = 0 |
61
|
|
|
form = ActionAdminForm |
62
|
|
|
|
63
|
|
|
|
64
|
|
|
class PartialUpdateInline(admin.StackedInline): |
65
|
|
|
model = PartialUpdate |
66
|
|
|
extra = 0 |
67
|
|
|
|
68
|
|
|
|
69
|
|
|
@admin.register(Version) |
70
|
|
|
class VersionAdmin(admin.ModelAdmin): |
71
|
|
|
inlines = (ActionInline, PartialUpdateInline,) |
72
|
|
|
list_display = ('created', 'modified', 'app', 'version', 'channel', 'platform', 'is_enabled', 'is_critical',) |
73
|
|
|
list_display_links = ('created', 'modified', 'version',) |
74
|
|
|
list_filter = ('channel__name', 'platform__name', 'app__name',) |
75
|
|
|
readonly_fields = ('file_hash',) |
76
|
|
|
form = VersionAdminForm |
77
|
|
|
|
78
|
|
|
|
79
|
|
|
def my_display_for_field(value, field, *args, **kwargs): |
80
|
|
|
if isinstance(field, VersionField): |
81
|
|
|
return smart_text(value) |
82
|
|
|
return django_display_for_field(value, field, *args, **kwargs) |
83
|
|
|
|
84
|
|
|
django_display_for_field = copy.deepcopy(utils.display_for_field) |
85
|
|
|
utils.display_for_field = my_display_for_field |