1
1
# -*- coding: utf-8 -*-
2
2
3
- """Django administration interface for `projects.models`"""
3
+ """Django administration interface for `projects.models`. """
4
4
5
5
from django .contrib import admin , messages
6
6
from django .contrib .admin .actions import delete_selected
9
9
10
10
from readthedocs .builds .models import Version
11
11
from readthedocs .core .models import UserProfile
12
- from readthedocs .core .utils import broadcast
12
+ from readthedocs .core .utils import broadcast , trigger_build
13
13
from readthedocs .notifications .views import SendNotificationView
14
14
from readthedocs .redirects .models import Redirect
15
15
@@ -47,7 +47,7 @@ def get_object_recipients(self, obj):
47
47
48
48
class ProjectRelationshipInline (admin .TabularInline ):
49
49
50
- """Project inline relationship view for :py:class:`ProjectAdmin`"""
50
+ """Project inline relationship view for :py:class:`ProjectAdmin`. """
51
51
52
52
model = ProjectRelationship
53
53
fk_name = 'parent'
@@ -56,14 +56,14 @@ class ProjectRelationshipInline(admin.TabularInline):
56
56
57
57
class VersionInline (admin .TabularInline ):
58
58
59
- """Version inline relationship view for :py:class:`ProjectAdmin`"""
59
+ """Version inline relationship view for :py:class:`ProjectAdmin`. """
60
60
61
61
model = Version
62
62
63
63
64
64
class RedirectInline (admin .TabularInline ):
65
65
66
- """Redirect inline relationship view for :py:class:`ProjectAdmin`"""
66
+ """Redirect inline relationship view for :py:class:`ProjectAdmin`. """
67
67
68
68
model = Redirect
69
69
@@ -77,7 +77,15 @@ class DomainInline(admin.TabularInline):
77
77
# class ImpressionInline(admin.TabularInline):
78
78
# from readthedocs.donate.models import ProjectImpressions
79
79
# model = ProjectImpressions
80
- # readonly_fields = ('date', 'promo', 'offers', 'views', 'clicks', 'view_ratio', 'click_ratio')
80
+ # readonly_fields = (
81
+ # 'date',
82
+ # 'promo',
83
+ # 'offers',
84
+ # 'views',
85
+ # 'clicks',
86
+ # 'view_ratio',
87
+ # 'click_ratio',
88
+ # )
81
89
# extra = 0
82
90
# can_delete = False
83
91
# max_num = 15
@@ -137,7 +145,7 @@ class ProjectAdmin(GuardedModelAdmin):
137
145
]
138
146
readonly_fields = ('feature_flags' ,)
139
147
raw_id_fields = ('users' , 'main_language_project' )
140
- actions = ['send_owner_email' , 'ban_owner' ]
148
+ actions = ['send_owner_email' , 'ban_owner' , 'build_default_version' ]
141
149
142
150
def feature_flags (self , obj ):
143
151
return ', ' .join ([str (f .get_feature_display ()) for f in obj .features ])
@@ -162,8 +170,9 @@ def ban_owner(self, request, queryset):
162
170
for project in queryset :
163
171
if project .users .count () == 1 :
164
172
count = (
165
- UserProfile .objects .filter (user__projects = project
166
- ).update (banned = True )
173
+ UserProfile .objects .filter (
174
+ user__projects = project ,
175
+ ).update (banned = True )
167
176
) # yapf: disabled
168
177
total += count
169
178
else :
@@ -199,6 +208,20 @@ def delete_selected_and_artifacts(self, request, queryset):
199
208
)
200
209
return delete_selected (self , request , queryset )
201
210
211
+ def build_default_version (self , request , queryset ):
212
+ """Trigger a build for the project version."""
213
+ total = 0
214
+ for project in queryset :
215
+ trigger_build (project = project )
216
+ total += 1
217
+ messages .add_message (
218
+ request ,
219
+ messages .INFO ,
220
+ 'Triggered builds for {} project(s).' .format (total ),
221
+ )
222
+
223
+ build_default_version .short_description = 'Build default version'
224
+
202
225
def get_actions (self , request ):
203
226
actions = super ().get_actions (request )
204
227
actions ['delete_selected' ] = (
@@ -211,7 +234,7 @@ def get_actions(self, request):
211
234
212
235
class ImportedFileAdmin (admin .ModelAdmin ):
213
236
214
- """Admin view for :py:class:`ImportedFile`"""
237
+ """Admin view for :py:class:`ImportedFile`. """
215
238
216
239
raw_id_fields = ('project' , 'version' )
217
240
list_display = ('path' , 'name' , 'version' )
0 commit comments