Fixed #21564 -- Use local request object when possible in generic views.

Thanks to trac user adepue for the report and original patch.