Skip to content

Commit 91d250c

Browse files
committed
fixes for django 1.11
1 parent 85980c7 commit 91d250c

File tree

3 files changed

+39
-60
lines changed

3 files changed

+39
-60
lines changed

genericadmin/__init__.py

100644100755
File mode changed.

genericadmin/admin.py

100644100755
Lines changed: 7 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import json
22
from functools import update_wrapper
33

4-
from django.core.urlresolvers import reverse, NoReverseMatch
54
from django.contrib import admin
65
from django.conf.urls import url
76
from django.conf import settings
@@ -75,14 +74,7 @@ def get_generic_field_list(self, request, prefix=''):
7574
})
7675

7776
if hasattr(self, 'inlines') and len(self.inlines) > 0:
78-
try:
79-
# Django < 1.9
80-
formsets = zip(self.get_formsets(request), self.get_inline_instances(request))
81-
except (AttributeError, ):
82-
# Django >= 1.9
83-
formsets = self.get_formsets_with_inlines(request)
84-
85-
for FormSet, inline in formsets:
77+
for FormSet, inline in zip(self.get_formsets_with_inlines(request), self.get_inline_instances(request)):
8678
if hasattr(inline, 'get_generic_field_list'):
8779
prefix = FormSet.get_default_prefix()
8880
field_list = field_list + inline.get_generic_field_list(request, prefix)
@@ -96,33 +88,23 @@ def wrapper(*args, **kwargs):
9688
return update_wrapper(wrapper, view)
9789

9890
custom_urls = [
99-
url(r'^(.*)genericadmin-obj-data/', wrap(
100-
self.generic_lookup), name='admin_genericadmin_obj_lookup'),
101-
url(r'^(.*)genericadmin-init/', wrap(
102-
self.genericadmin_js_init), name='admin_genericadmin_init'),
91+
url(r'^obj-data/$', wrap(self.generic_lookup), name='admin_genericadmin_obj_lookup'),
92+
url(r'^genericadmin-init/$', wrap(self.genericadmin_js_init), name='admin_genericadmin_init'),
10393
]
10494
return custom_urls + super(BaseGenericModelAdmin, self).get_urls()
10595

106-
def genericadmin_js_init(self, request, *args, **kwargs):
96+
def genericadmin_js_init(self, request):
10797
if request.method == 'GET':
10898
obj_dict = {}
10999
for c in ContentType.objects.all():
110100
val = force_text('%s/%s' % (c.app_label, c.model))
111101
params = self.content_type_lookups.get('%s.%s' % (c.app_label, c.model), {})
112102
params = url_params_from_lookup_dict(params)
113-
114-
try:
115-
# Reverse the admin changelist url
116-
url = reverse('admin:%s_%s_changelist' % (
117-
c.app_label, c.model))
118-
except (NoReverseMatch, ):
119-
continue
120-
121103
if self.content_type_whitelist:
122104
if val in self.content_type_whitelist:
123-
obj_dict[c.id] = (val, url, params)
105+
obj_dict[c.id] = (val, params)
124106
elif val not in self.content_type_blacklist:
125-
obj_dict[c.id] = (val, url, params)
107+
obj_dict[c.id] = (val, params)
126108

127109
data = {
128110
'url_array': obj_dict,
@@ -133,7 +115,7 @@ def genericadmin_js_init(self, request, *args, **kwargs):
133115
return HttpResponse(resp, content_type='application/json')
134116
return HttpResponseNotAllowed(['GET'])
135117

136-
def generic_lookup(self, request, *args, **kwargs):
118+
def generic_lookup(self, request):
137119
if request.method != 'GET':
138120
return HttpResponseNotAllowed(['GET'])
139121

genericadmin/static/genericadmin/js/genericadmin.js

Lines changed: 32 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,10 @@
1212
var GenericAdmin = {
1313
url_array: null,
1414
fields: null,
15-
obj_url: "../genericadmin-obj-data/",
15+
obj_url: "../obj-data/",
1616
admin_media_url: window.__admin_media_prefix__,
1717
popup: '_popup',
18-
18+
1919
prepareSelect: function(select) {
2020
var that = this,
2121
opt_keys = [],
@@ -30,7 +30,7 @@
3030
if (this.value) {
3131
if (that.url_array[this.value]) {
3232
key = that.url_array[this.value][0].split('/')[0];
33-
33+
3434
opt = $(this).clone();
3535
opt.text(that.capFirst(opt.text()));
3636
if ($.inArray(key, opt_keys) < 0) {
@@ -47,7 +47,7 @@
4747
}
4848
});
4949
select.empty().append(no_value);
50-
50+
5151
opt_keys = opt_keys.sort();
5252

5353
$.each(opt_keys, function(index, key) {
@@ -61,9 +61,8 @@
6161
return select;
6262
},
6363

64-
6564
getLookupUrlParams: function(cID) {
66-
var q = this.url_array[cID][2] || {},
65+
var q = this.url_array[cID][1] || {},
6766
str = [];
6867
for(var p in q) {
6968
str.push(encodeURIComponent(p) + "=" + encodeURIComponent(q[p]));
@@ -72,54 +71,52 @@
7271
url = x ? ("?" + x) : "";
7372
return url;
7473
},
75-
76-
getLookupUrl: function(cID, with_params) {
77-
var url = this.url_array[cID][1];
78-
if(with_params){url = url + this.getLookupUrlParams(cID);}
79-
return url;
74+
75+
getLookupUrl: function(cID) {
76+
return '../../../' + this.url_array[cID][0] + '/' + this.getLookupUrlParams(cID);
8077
},
81-
78+
8279
getFkId: function() {
8380
if (this.fields.inline === false) {
8481
return 'id_' + this.fields.fk_field;
8582
} else {
8683
return ['id_', this.fields.prefix, '-', this.fields.number, '-', this.fields.fk_field].join('');
8784
}
8885
},
89-
86+
9087
getCtId: function() {
9188
if (this.fields.inline === false) {
9289
return 'id_' + this.fields.ct_field;
9390
} else {
9491
return ['id_', this.fields.prefix, '-', this.fields.number, '-', this.fields.ct_field].join('');
9592
}
9693
},
97-
94+
9895
capFirst: function(string) {
9996
return string.charAt(0).toUpperCase() + string.slice(1);
10097
},
101-
98+
10299
hideLookupLink: function() {
103100
var this_id = this.getFkId();
104101
$('#lookup_' + this_id).unbind().remove();
105102
$('#lookup_text_' + this_id + ' a').remove();
106103
$('#lookup_text_' + this_id + ' span').remove();
107104
},
108-
105+
109106
showLookupLink: function() {
110107
var that = this,
111-
url = this.getLookupUrl(this.cID, true),
108+
url = this.getLookupUrl(this.cID),
112109
id = 'lookup_' + this.getFkId(),
113110
link = '<a class="related-lookup" id="' + id + '" href="' + url + '">&nbsp;</a>';
114-
111+
115112
link = link + '<strong id="lookup_text_'+ this.getFkId() +'" margin-left: 5px"><a target="_new" href="#"></a><span></span></strong>';
116113

117114
// insert link html after input element
118115
this.object_input.after(link);
119116

120117
return id;
121118
},
122-
119+
123120
pollInputChange: function(window) {
124121
var that = this,
125122
interval_id = setInterval(function() {
@@ -131,11 +128,11 @@
131128
},
132129
150);
133130
},
134-
131+
135132
popRelatedObjectLookup: function(link) {
136133
var name = id_to_windowname(this.getFkId()),
137134
url_parts = [],
138-
href,
135+
href,
139136
win;
140137

141138
if (link.href.search(/\?/) >= 0) {
@@ -159,14 +156,14 @@
159156
win.focus();
160157
return false;
161158
},
162-
159+
163160
updateObjectData: function() {
164161
var that = this;
165162
return function() {
166163
var value = that.object_input.val();
167-
168-
if (!value) {
169-
return
164+
165+
if (!value) {
166+
return
170167
}
171168
//var this_id = that.getFkId();
172169
$('#lookup_text_' + that.getFkId() + ' span').text('loading...');
@@ -179,7 +176,7 @@
179176
},
180177
success: function(item) {
181178
if (item && item.content_type_text && item.object_text) {
182-
var url = that.getLookupUrl(that.cID, false);
179+
var url = that.getLookupUrl(that.cID);
183180
$('#lookup_text_' + that.getFkId() + ' a')
184181
.text(item.content_type_text + ': ' + item.object_text)
185182
.attr('href', url + item.object_id);
@@ -211,10 +208,10 @@
211208
this.url_array = url_array;
212209
this.fields = fields;
213210
this.popup = popup_var || this.popup;
214-
211+
215212
// store the base element
216213
this.object_input = $("#" + this.getFkId());
217-
214+
218215
// find the select we need to change
219216
this.object_select = this.prepareSelect($("#" + this.getCtId()));
220217

@@ -248,22 +245,22 @@
248245
this.updateObjectData()();
249246
}
250247
};
251-
248+
252249
var InlineAdmin = {
253250
sub_admins: null,
254251
url_array: null,
255252
fields: null,
256253
popup: '_popup',
257-
254+
258255
install: function(fields, url_array, popup_var) {
259256
var inline_count = $('#id_' + fields.prefix + '-TOTAL_FORMS').val(),
260257
admin;
261-
258+
262259
this.url_array = url_array;
263260
this.fields = fields;
264261
this.sub_admins = [];
265262
this.popup = popup_var || this.popup;
266-
263+
267264
for (var j = 0; j < inline_count; j++) {
268265
f = $.extend({}, this.fields);
269266
f.number = j;
@@ -282,7 +279,7 @@
282279
added_fields.number = ($('#id_' + that.fields.prefix + '-TOTAL_FORMS').val() - 1);
283280
admin.install(added_fields, that.url_array, that.popup);
284281
that.sub_admins.push(admin);
285-
282+
286283
$('#' + that.fields.prefix + '-' + added_fields.number + ' .inline-deletelink').click(
287284
that.removeHandler(that)
288285
);
@@ -293,7 +290,7 @@
293290
var parent_id,
294291
deleted_num,
295292
sub_admin;
296-
293+
297294
e.preventDefault();
298295
parent_id = $(e.currentTarget).parents('.dynamic-' + that.fields.prefix).first().attr('id');
299296
deleted_num = parseInt(parent_id.charAt(parent_id.length - 1), 10);
@@ -318,7 +315,7 @@
318315
ct_fields = data.fields,
319316
popup_var = data.popup_var,
320317
fields;
321-
318+
322319
for (var i = 0; i < ct_fields.length; i++) {
323320
fields = ct_fields[i];
324321
if (fields.inline === false) {

0 commit comments

Comments
 (0)