try {
Class pc = options.getClassMapping(model);
if (pc == null) {
throw new Http404("Class not found");
}
ModelAdmin ma = options.getModelAdmin(pc);
if (!ma.isReader(request.getUser())) {
throw new Http404("Class not found, or not authorized");
}
Manager<?> manager = findManager(pc, ma);
String[] property_list = ma.getListDisplay();
List<String> header_list = new ArrayList<String>();
for(String property : property_list) {
header_list.add(getChangeListLabel(pc, ma, property));
}
Map<String, String> searchParams = new HashMap<String, String>();
for(Entry<String, String[]> e : request.getParameterMap().entrySet()) {
if (e.getKey().contains("__")) {
String value = e.getValue() == null ? null : e.getValue().length == 0 ? null : e.getValue()[0];
searchParams.put(e.getKey(), value);
}
}
QuerySet<?> qs = manager.filter(searchParams);
String[] orderBy = ma.getOrderBy();
if (orderBy == null) {
qs = qs.orderBy(manager.getPkProperty());
} else {
qs = qs.orderBy();
}
String tool = request.getParameter("tool");
// an action has been selected or clicked
if (tool != null) {
for (AdminAction action : ma.getListTools()) {
if (tool.equals(action.getClass().getName())) {
return action.execute(ma, request, qs);
}
}
}
QuerySetPaginator<?> paginator = new QuerySetPaginator(qs, 30);
String query_string = generateSearchParams(request, searchParams);
QuerySetPage<?> page = paginator.getPage(getPageNumber(request));
List<?> object_list = page.getObjectList();
Map<String, Object> context = new HashMap<String, Object>();
context.put("header_list", header_list);
context.put("property_list", property_list);
context.put("object_list", object_list);
context.put("key_property", manager.getPkProperty());
context.put("link_property", ma.getListDisplayLinks() == null ? property_list[0] : ma.getListDisplayLinks());
context.put("paginator", new PaginatorWidget(paginator, getPageNumber(request), query_string));
context.put("query_string", query_string);
context.put("list_tools", ma.getListTools());
updateContext(context, pc, ma);
context.put("page_title", String.format("Select %s to change", findVerboseName(pc, ma)));
return renderToResponse(ma.getChangeListTemplate(), context);
} catch (ManagerException e) {
throw new HttpException(e);
}
}