Add form in admin site for AutomaticRunGroups.
Review Request #6221 — Created Aug. 12, 2014 and submitted — Latest diff uploaded
AutomaticRunGroups can now be created, modified, or deleted through the admin
site by specifying a name, file regex, profile(s), local site (optional), and
repository (optional). See the attached screenshots.
- Tried adding AutomaticRunGroups with invalid fields (a missing required
field (name, file regex, profile), an invalid file regex, and a local site
that does not exist), and saw the appropriate errors on the form. - Added AutomaticRunGroups with valid fields, and saw them listed in the admin
panel and in the database. - Displayed the list of AutomaticRunGroups.
- Modified an AutomaticRunGroup and saved the changes.
- Deleted AutomaticRunGroups, and saw them removed.
extension/reviewbotext/admin.py | |||
---|---|---|---|
Revision 68e7be7c15c4ee9b435c97ed98efe9c90f24f5ad | New Change | ||
1 |
from django.conf.urls import patterns |
1 |
from django.conf.urls import patterns |
2 |
from django.contrib import admin |
2 |
from django.contrib import admin |
3 |
from django.shortcuts import render_to_response |
3 |
from django.shortcuts import render_to_response |
4 |
from django.template.context import RequestContext |
4 |
from django.template.context import RequestContext |
5 | 5 |
from django.utils.translation import ugettext_lazy as _ |
|
6 |
from reviewboard.extensions.base import get_extension_manager |
6 |
from reviewboard.extensions.base import get_extension_manager |
7 | 7 | ||
8 |
from reviewbotext.extension import ReviewBotExtension |
8 |
from reviewbotext.extension import ReviewBotExtension |
9 |
from reviewbotext.forms import (ToolForm, |
9 |
from reviewbotext.forms import AutomaticRunGroupForm, ToolForm |
10 |
ProfileForm, |
10 |
from reviewbotext.models import AutomaticRunGroup, Profile, Tool |
11 |
ProfileFormset) |
||
12 |
from reviewbotext.models import (Tool, |
||
13 |
Profile) |
||
14 | 11 | ||
15 | 12 | ||
16 |
class ProfileInline(admin.StackedInline): |
13 |
class ProfileInline(admin.StackedInline): |
17 |
model = Profile |
14 |
model = Profile |
18 |
# formset = ProfileFormset
|
15 |
# formset = ProfileFormset
|
93 lines | |||
def get_urls(self):
|
|||
112 | 109 | ||
113 |
def has_add_permission(self, request): |
110 |
def has_add_permission(self, request): |
114 |
return False |
111 |
return False |
115 | 112 | ||
116 | 113 | ||
114 |
class AutomaticRunGroupAdmin(admin.ModelAdmin): |
||
115 |
form = AutomaticRunGroupForm |
||
116 | |||
117 |
filter_horizontal = ( |
||
118 |
'repository', |
||
119 |
'profile', |
||
120 |
)
|
||
121 |
list_display = ( |
||
122 |
'name', |
||
123 |
'file_regex', |
||
124 |
)
|
||
125 |
raw_id_fields = ( |
||
126 |
'local_site', |
||
127 |
)
|
||
128 | |||
129 |
fieldsets = ( |
||
130 |
(_('General Information'), { |
||
131 |
'fields': ( |
||
132 |
'name', |
||
133 |
'file_regex', |
||
134 |
'local_site', |
||
135 |
),
|
||
136 |
'classes': ('wide',), |
||
137 |
}),
|
||
138 |
(_('Tool Profiles'), { |
||
139 |
'description': _('<p>These tool profiles will be executed when ' |
||
140 |
'the provided file regex and repositories match '
|
||
141 |
'a review request.</p>'), |
||
142 |
'fields': ( |
||
143 |
'profile', |
||
144 |
),
|
||
145 |
}),
|
||
146 |
(_('Repositories'), { |
||
147 |
'description': _('<p>An AutomaticRunGroup will only cover the ' |
||
148 |
'repositories specified below.</p>'), |
||
149 |
'fields': ( |
||
150 |
'repository', |
||
151 |
),
|
||
152 |
}),
|
||
153 |
)
|
||
154 | |||
155 | |||
117 |
# Get the ReviewBotExtension instance. We can assume it exists because
|
156 |
# Get the ReviewBotExtension instance. We can assume it exists because
|
118 |
# this code is executed after the extension has been registered with
|
157 |
# this code is executed after the extension has been registered with
|
119 |
# the manager.
|
158 |
# the manager.
|
120 |
extension_manager = get_extension_manager() |
159 |
extension_manager = get_extension_manager() |
121 |
extension = extension_manager.get_enabled_extension(ReviewBotExtension.id) |
160 |
extension = extension_manager.get_enabled_extension(ReviewBotExtension.id) |
122 | 161 | ||
123 |
# Register with the extension's, not Review Board's, admin site.
|
162 |
# Register with the extension's, not Review Board's, admin site.
|
124 |
extension.admin_site.register(Tool, ToolAdmin) |
163 |
extension.admin_site.register(Tool, ToolAdmin) |
125 | 164 |
extension.admin_site.register(AutomaticRunGroup, AutomaticRunGroupAdmin) |
extension/reviewbotext/forms.py |
---|
extension/reviewbotext/models.py |
---|