As it turns out this is not just an AJAX issue. I have looked at the
decorators in both Django 1.1 and 1.2.1 and the one in 1.2.1 now looks
for the request.user object where the older one did not. I also do
something that I think most developers don't do and that is write most
of my views in classes. See below:

class ProcessRegion(ViewBase):
    __MODELS_MAP = {'distributor': Distributor, 'manufacturer':
Manufacturer}


    def __init__(self, log):
        super(ProcessRegion, self).__init__(log)

    @login_required(redirect_field_name='/login/')
    def __call__(self, request, *args, **kwargs):
        response = {'valid': True}

        try:
            country, delimitor, code = \
                     request.POST.get('country').partition('(')
            selected = None
            pathname = request.POST.get('pathname', None)

            if pathname:
                path = pathname.strip('/').split('/')
                model = self.__MODELS_MAP.get(path[-2])
                pk = path[-1]
                region =   model.objects.get(pk=int(pk))
                selected = region.state_id

            code = code.strip(')')
            record = Country.objects.get(country_code_2__iexact=code)
            response['regions'] = [
                ("%s (%s: %s)" %
                (m['region'], m['region_code'], m['primary_level']),
m['id'])
                for m in record.region_set.values()]
            response['selected'] = selected
        except Exception, e:
            msg = "Failed to find region records"
            self._log.error(msg + ": %s", e)
            response['valid'] = False
            response['message'] = msg + "."

        self._log.debug("Context dump for %s: %s", self.__module__,
response)
        return HttpResponse(simplejson.dumps(response))


processRegion = ProcessRegion(log)

Could the new code not work with a class. I'm still looking into this
and may discover the answer myself, but if anybody knows or has an
idea I'd be much appreciative.

~Carl

On Jun 2, 9:44 am, Daniel Roseman <dan...@roseman.org.uk> wrote:
> On Jun 2, 2:35 pm, Carl Nobile <carl.nob...@gmail.com> wrote:
>
> > Nothing has changed at all. I was just going through the steps to
> > migrate my code base to Django 1.2.1 and this stopped working. If I
> > comment out the decorator everything works just fine minus the
> > protection of cause. The internal wrapper (closure) in the decorator
> > is failing when it tries to get 'request.user'.  Also I see that
> > Django 1.2.1 now comes with jQuery 1.4.2 by default. I'm now including
> > it twice, so I need to fix this also and move my JavaScript to later
> > in the <script> tags.
>
> > I was also thinking about the session cookie, but I was doing nothing
> > with it before and everything worked fine.
>
> > ~Carl
>
> Do you get the request.user inside a normal view, ie is it justAjax
> requests that are the problem? If not, that would imply there's
> something wrong with your middleware settings.
> --
> DR.

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.

Reply via email to