Python django.contrib.auth.mixins.LoginRequiredMixin() Examples
The following are 3
code examples of django.contrib.auth.mixins.LoginRequiredMixin().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
django.contrib.auth.mixins
, or try the search function
.
Example #1
Source File: mixins.py From website with GNU General Public License v3.0 | 6 votes |
def dispatch(self, request, *args, **kwargs): try: # Check that the logged-in user has a Comrade instance too: # even just trying to access the field will fail if not. request.user.comrade except Comrade.DoesNotExist: # If not, redirect to create one and remember to come back # here afterward. return HttpResponseRedirect( '{account_url}?{query_string}'.format( account_url=reverse('account'), query_string=urlencode({'next': request.path}))) return super(ComradeRequiredMixin, self).dispatch(request, *args, **kwargs) # If the logged-in user doesn't have an ApplicantApproval object, # redirect them to create one. # If the logged-in user has an ApplicantApproval object that isn't approved, # redirect them to the eligibility results page. # # This mixin requires a 'round_slug' view keyword argument. # # Note that LoginRequiredMixin must be to the left of this class in the # view's list of parent classes, and the base View must be to the right.
Example #2
Source File: views.py From djangochannel with BSD 3-Clause "New" or "Revised" License | 6 votes |
def post(self, request, section, pk): form = MessageForm(request.POST) if form.is_valid(): form = form.save(commit=False) form.user = request.user form.topic_id = pk form.save() return redirect("/forum/section/{}/{}/?page=last".format(section, pk)) # class MessageCreate(LoginRequiredMixin, CreateView): # """Создание темы на форуме""" # model = Message # form_class = MessageForm # template_name = 'forum/topic-detail.html' # # def form_valid(self, form): # form.instance.user = self.request.user # form.instance.topic_id = self.kwargs.get("pk") # form.save() # return super().form_valid(form)
Example #3
Source File: views.py From Food-Pantry-Inventory with MIT License | 5 votes |
def get_context_data(self, **kwargs): """ Add User Information to Manual Menu page. :param kwargs: :return: """ # get information from the database context = super().get_context_data(**kwargs) # get the current user and related profile current_user = self.request.user profile = current_user.profile # load up the context for the template context['current_user'] = current_user context['user_profile'] = profile return context # class ManualNotification(LoginRequiredMixin, TemplateView): # """ # Ask a question or notify the user of something. # """ # template_name = 'fpiweb/manual_generic_notification.html' # # def get_context_data(self, **kwargs): # """ # Get info from reqest and populate context from it. # # :param kwargs: # :return: # """ # context = super(ManualNotification, self.get_context_data(**kwargs)) # request = context.get_request() # title = request.