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) future_qs = Placement.objects.select_related().filter( publish_from__gt=datetime.datetime.now()).order_by( 'publish_from', 'category__tree_path') future_qs_perm = permission_filtered_model_qs(future_qs, request.user) future_placements = user_category_filter(future_qs_perm, request.user) 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, 'future_placements': future_placements, '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 index(self, request, extra_context=None): """ Displays the main Newman index page, without installed apps. """ data = {'sites': []} try: data['sites'] = get_user_config(request.user, CATEGORY_FILTER) except KeyError: data['sites'] = [] site_filter_form = SiteFilterForm(data=data, user=request.user) cts = [] last_filters = {} for model, model_admin in self._registry.items(): if has_model_list_permission(request.user, model): 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) context = { 'title': _('Site administration'), 'site_filter_form': site_filter_form, 'searchable_content_types': cts, 'last_filters': last_filters } context.update(extra_context or {}) return render_to_response(self.index_template or 'admin/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) future_qs = Placement.objects.select_related().filter(publish_from__gt=datetime.datetime.now()).order_by('publish_from', 'category__tree_path') future_qs_perm = permission_filtered_model_qs(future_qs, request.user) future_placements = user_category_filter(future_qs_perm, request.user) 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, 'future_placements': future_placements, '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) )