Example #1
0
    def changelist_view(self, request, extra_context=None):
        self.register_newman_variables(request)

        context = super(NewmanModelAdmin, self).get_changelist_context(request)
        if type(context) != dict:
            return context

        if context['media']:
            raw_media = self.prepare_media(context['media'])
            context['media'] = raw_media

        # save per user filtered content type.
        req_path = request.get_full_path()
        ct = ContentType.objects.get_for_model(self.model)
        # persistent filter for non-popupped changelists only
        key = 'filter__%s__%s' % (ct.app_label, ct.model)
        if req_path.find('pop') < 0:
            if req_path.find('?') > 0:
                url_args = req_path.split('?', 1)[1]
                utils.set_user_config_db(request.user, key, url_args)
            else:
                user_filter = utils.get_user_config(request.user, key)
                if user_filter:
                    redirect_to = '%s?%s' % (request.path, user_filter)
                    return utils.JsonResponseRedirect(redirect_to)

        context['is_filtered'] = context['cl'].is_filtered()
        context['is_user_category_filtered'] = utils.is_user_category_filtered( self.queryset(request) )
        context.update(extra_context or {})
        return render_to_response(self.change_list_template, context, context_instance=template.RequestContext(request))
Example #2
0
    def changelist_view(self, request, extra_context=None):
        self.register_newman_variables(request)
        opts = self.model._meta
        app_label = opts.app_label

        context = super(NewmanModelAdmin, self).get_changelist_context(request)
        if type(context) != dict:
            return context

        if context['media']:
            raw_media = self.prepare_media(context['media'])
            context['media'] = raw_media

        # save per user filtered content type.
        req_path = request.get_full_path()
        ct = ContentType.objects.get_for_model(self.model)
        # persistent filter for non-popupped changelists only
        if req_path.find('?') > 0 and req_path.find('pop') < 0:
            url_args = req_path.split('?', 1)[1]
            key = 'filter__%s__%s' % (ct.app_label, ct.model)
            utils.set_user_config_db(request.user, key, url_args)

        context['is_filtered'] = context['cl'].is_filtered()
        context['is_user_category_filtered'] = utils.is_user_category_filtered( self.queryset(request) )
        context.update(extra_context or {})
        return render_to_response(self.change_list_template or [
            'admin/%s/%s/change_list.html' % (app_label, opts.object_name.lower()),
            'admin/%s/change_list.html' % app_label,
            'admin/change_list.html'
        ], context, context_instance=template.RequestContext(request))
Example #3
0
File: sites.py Project: joskid/ella
 def filter_by_main_categories_save(self, request, extra_content=None):
     site_filter_form = SiteFilterForm(user=request.user, data=request.POST)
     if site_filter_form.is_valid():
         set_user_config_db(request.user, newman_settings.CATEGORY_FILTER, site_filter_form.cleaned_data['sites'])
         set_user_config_session(request.session, newman_settings.CATEGORY_FILTER, site_filter_form.cleaned_data['sites'])
         return JsonResponse(ugettext('Your settings were saved.'))
     else:
         return JsonResponseError(ugettext('Error in form.'), status=newman_settings.STATUS_FORM_ERROR)
Example #4
0
 def filter_by_main_categories_save(self, request, extra_content=None):
     site_filter_form = SiteFilterForm(user=request.user, data=request.POST)
     if site_filter_form.is_valid():
         set_user_config_db(request.user, newman_settings.CATEGORY_FILTER,
                            site_filter_form.cleaned_data['sites'])
         set_user_config_session(request.session,
                                 newman_settings.CATEGORY_FILTER,
                                 site_filter_form.cleaned_data['sites'])
         return JsonResponse(ugettext('Your settings were saved.'))
     else:
         return JsonResponseError(ugettext('Error in form.'),
                                  status=newman_settings.STATUS_FORM_ERROR)
Example #5
0
File: options.py Project: whit/ella
    def changelist_view(self, request, extra_context=None):
        self.register_newman_variables(request)

        # save per user filtered content type.
        is_popup = False
        req_path = request.get_full_path()
        ct = ContentType.objects.get_for_model(self.model)
        # persistent filter for non-popupped changelists only
        key = 'filter__%s__%s' % (ct.app_label, ct.model)
        if req_path.find(
                'pop'
        ) >= 0:  # if popup is displayed, remove pop string from request path
            is_popup = True
            req_path = re.sub(r'(.*)(pop=&|&pop=|pop=|pop&|&pop|pop)(.*)',
                              r'\1\3', req_path)
        if req_path.endswith('?') and is_popup:
            req_path = ''  # if popup with no active filters is displayed, do not save empty filter settings
        if req_path.find('?') > 0:
            url_args = req_path.split('?', 1)[1]
            utils.set_user_config_db(request.user, key, url_args)
            log.debug('SAVING FILTERS %s' % url_args)
        else:
            user_filter = utils.get_user_config(request.user, key)
            if user_filter:
                if is_popup:
                    user_filter = 'pop&%s' % user_filter
                redirect_to = '%s?%s' % (request.path, user_filter)
                if not redirect_to.endswith('?q='):
                    log.debug('REDIRECTING TO %s' % redirect_to)
                    return utils.JsonResponseRedirect(redirect_to)

        context = super(NewmanModelAdmin, self).get_changelist_context(request)
        if type(context) != dict:
            return context

        if context['media']:
            raw_media = self.prepare_media(context['media'])
            context['media'] = raw_media

        context['is_filtered'] = context['cl'].is_filtered()
        context['is_user_category_filtered'] = utils.is_user_category_filtered(
            self.queryset(request))
        context.update(extra_context or {})
        return render_to_response(
            self.change_list_template,
            context,
            context_instance=template.RequestContext(request))
Example #6
0
    def changelist_view(self, request, extra_context=None):
        self.register_newman_variables(request)

        # save per user filtered content type.
        is_popup = False
        req_path = request.get_full_path()
        ct = ContentType.objects.get_for_model(self.model)
        # persistent filter for non-popupped changelists only
        key = 'filter__%s__%s' % (ct.app_label, ct.model)
        if req_path.find('pop') >= 0: # if popup is displayed, remove pop string from request path
            is_popup = True
            req_path = re.sub(r'(.*)(pop=&|&pop=|pop=|pop&|&pop|pop)(.*)', r'\1\3', req_path)
        if req_path.endswith('?') and is_popup:
            req_path = '' # if popup with no active filters is displayed, do not save empty filter settings
        if req_path.find('?') > 0:
            url_args = req_path.split('?', 1)[1]
            utils.set_user_config_db(request.user, key, url_args)
            log.debug('SAVING FILTERS %s' % url_args)
        else:
            user_filter = utils.get_user_config(request.user, key)
            if user_filter:
                if is_popup:
                    user_filter = 'pop&%s' % user_filter
                redirect_to = '%s?%s' % (request.path, user_filter)
                if not redirect_to.endswith('?q='):
                    log.debug('REDIRECTING TO %s' % redirect_to)
                    return utils.JsonResponseRedirect(redirect_to)

        context = super(NewmanModelAdmin, self).get_changelist_context(request)
        if type(context) != dict:
            return context

        if context['media']:
            raw_media = self.prepare_media(context['media'])
            context['media'] = raw_media

        context['is_filtered'] = context['cl'].is_filtered()
        context['is_user_category_filtered'] = utils.is_user_category_filtered( self.queryset(request) )
        context.update(extra_context or {})
        return render_to_response(self.change_list_template, context, context_instance=template.RequestContext(request))