def newman_topmenu(context): app_dict = {} req = context['request'] user = context['user'] for model, model_admin in site._registry.items(): app_label = model._meta.app_label has_module_perms = user.has_module_perms( app_label) or permission.has_model_list_permission(user, model) if has_module_perms: perms = { 'add': model_admin.has_add_permission(req), 'change': model_admin.has_change_permission(req), 'delete': model_admin.has_delete_permission(req), } # Check whether user has any perm for this module. # If so, add the module to the model_list. if True in perms.values(): model_dict = { 'model': model.__name__.lower(), 'name': capfirst(model._meta.verbose_name_plural), 'admin_url': mark_safe('%s/%s/' % (app_label, model.__name__.lower())), 'perms': perms, } if app_label in app_dict: app_dict[app_label]['models'].append(model_dict) else: app_dict[app_label] = { 'name': app_label.title(), 'has_module_perms': has_module_perms, 'models': [model_dict], } # Sort the apps alphabetically. app_list = app_dict.values() app_list.sort( lambda x, y: cz_compare(ugettext(x['name']), ugettext(y['name']))) # Sort the models alphabetically within each app. for app in app_list: app['models'].sort(lambda x, y: cz_compare(x['name'], y['name'])) return { 'NEWMAN_MEDIA_URL': context['NEWMAN_MEDIA_URL'], 'app_list': app_list }
def newman_topmenu(context): app_dict = {} req = context['request'] user = context['user'] for model, model_admin in site._registry.items(): app_label = model._meta.app_label has_module_perms = user.has_module_perms(app_label) or permission.has_model_list_permission(user, model) if has_module_perms: perms = { 'add': model_admin.has_add_permission(req), 'change': model_admin.has_change_permission(req), 'delete': model_admin.has_delete_permission(req), } # Check whether user has any perm for this module. # If so, add the module to the model_list. if True in perms.values(): model_dict = { 'model': model.__name__.lower(), 'name': capfirst(model._meta.verbose_name_plural), 'admin_url': mark_safe('%s/%s/' % (app_label, model.__name__.lower())), 'perms': perms, } if app_label in app_dict: app_dict[app_label]['models'].append(model_dict) else: app_dict[app_label] = { 'name': app_label.title(), 'has_module_perms': has_module_perms, 'models': [model_dict], } # Sort the apps alphabetically. app_list = app_dict.values() app_list.sort( lambda x, y: cz_compare( ugettext( x['name'] ), ugettext( y['name'] ) ) ) # Sort the models alphabetically within each app. for app in app_list: app['models'].sort(lambda x, y: cz_compare(x['name'], y['name'])) return { 'NEWMAN_MEDIA_URL': context['NEWMAN_MEDIA_URL'], 'app_list': app_list }
def newman_index(self, request, extra_context=None): def translate_and_upper(text): return ugettext(text).upper() """ Displays the main Newman index page, without installed apps. """ data = {'sites': []} try: data['sites'] = get_user_config(request.user, newman_settings.CATEGORY_FILTER) except KeyError: data['sites'] = [] publishable_lookup_fields = { 'day': 'publish_from__day', 'month': 'publish_from__month', 'year': 'publish_from__year' } site_filter_form = SiteFilterForm(data=data, user=request.user) if site_filter_form.sites_count == 1: site_filter_form = None cts = [] last_filters = {} for model, model_admin in self._registry.items(): if has_model_list_permission(request.user, model) and model_admin.search_fields: ct = ContentType.objects.get_for_model(model) cts.append(ct) # Load saved filter configurations for changelists key = 'filter__%s__%s' % (ct.app_label, ct.model) last_filter = AdminSetting.objects.filter(var=key, user=request.user) if last_filter: last_filters[key] = '?%s' % json_decode( last_filter[0].value) cts.sort(lambda a, b: cz_compare(translate_and_upper(a.name), translate_and_upper(b.name))) context = { 'title': _('Site administration'), 'site_filter_form': site_filter_form, 'searchable_content_types': cts, 'last_filters': last_filters, 'publishable_lookup_fields': publishable_lookup_fields, 'show_calendar': has_model_list_permission(request.user, Publishable), } context.update(extra_context or {}) return render_to_response( 'newman/newman-index.html', context, context_instance=template.RequestContext(request))
def newman_index(self, request, extra_context=None): def translate_and_upper(text): return ugettext(text).upper() """ Displays the main Newman index page, without installed apps. """ data = {'sites': []} try: data['sites'] = get_user_config(request.user, newman_settings.CATEGORY_FILTER) except KeyError: data['sites'] = [] publishable_lookup_fields = { 'day': 'publish_from__day', 'month': 'publish_from__month', 'year': 'publish_from__year' } site_filter_form = SiteFilterForm(data=data, user=request.user) if site_filter_form.sites_count == 1: site_filter_form = None cts = [] last_filters = {} for model, model_admin in self._registry.items(): if has_model_list_permission(request.user, model) and model_admin.search_fields: ct = ContentType.objects.get_for_model(model) cts.append(ct) # Load saved filter configurations for changelists key = 'filter__%s__%s' % (ct.app_label, ct.model) last_filter = AdminSetting.objects.filter(var=key, user=request.user) if last_filter: last_filters[key] = '?%s' % json_decode(last_filter[0].value) cts.sort( lambda a, b: cz_compare(translate_and_upper(a.name), translate_and_upper(b.name)) ) context = { 'title': _('Site administration'), 'site_filter_form': site_filter_form, 'searchable_content_types': cts, 'last_filters': last_filters, 'publishable_lookup_fields': publishable_lookup_fields, 'show_calendar': has_model_list_permission(request.user, Publishable), } context.update(extra_context or {}) return render_to_response('newman/newman-index.html', context, context_instance=template.RequestContext(request) )