Using Django 1.9.7.

I have the following class:

class AddView(LoginRequiredMixin, CreateView):
    template_name = "entry.html"
    model = Property
    form_class = AddPropertyForm
    success_url = "/buy/"
    login_url = '/account/login/'

    def dispatch(self, request, *args, **kwargs):
        print request.user
        print request.user.is_authenticated()
        return super(AddView, self).post(request, *args, **kwargs)

    def form_valid(self, form):
        ls_property = form.save(commit=False)
        ls_property.user = get_user(self.request)
        ls_property.latitude = form.cleaned_data['latitude']
        ls_property.longitude = form.cleaned_data['longitude']
        submit =  form.cleaned_data['submit']
        ls_property.visible = (submit != 'draft')
        ls_property.save()
        return super(AddView, self).form_valid(form)


The LoginRequiredMixin is ignored, i.e, I can get to the page without
being logged in.

request.user reports: AnonymousUserrequest.user.is_authenticated()
reports: False

If I wrap the url:

url(r'^sell', user_passes_test(user_is_active)(AddView.as_view()), name="add"),

the page is protected, so I have a work around.

This seems basic and I don't find other reports of LoginRequiredMixin
not working, so I assume it's me.

What am I missing?

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CA%2BePoMzApQGdzZ9AW47CjF3yhT0Smnc1AZw%2BOQ8uTcH1G3%3Dasg%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to