def dispatch(self, request, *args, **kwargs): request.session[ 'Message'] = 'Logged out successfully.' if request.user.is_authenticated( ) else None return authviews.logout(request, next_page='/') if request.user.is_authenticated()\ else redirect_with_msg(request, 'You are already logged out.', 'home')
def dispatch(self, request, *args, **kwargs): request.session["Message"] = "Logged out successfully." if request.user.is_authenticated() else None return ( authviews.logout(request, next_page="/") if request.user.is_authenticated() else redirect_with_msg(request, "You are already logged out.", "home") )
def post(self, request, *args, **kwargs): post = { "subject": request.POST.get("subject"), "content": request.POST.get("content"), "recipient": request.POST.get("recipient"), "sender": str(models.UserProfile.get(request.user).id), } msg_form = self.message_form(post) if msg_form.is_valid(): msg = msg_form.save(commit=False) print(msg) msg.save() return redirect_with_msg(request, "Message sent.", reverse_lazy("home")) else: print(msg_form.errors) return redirect_with_msg( request, "The following errors were found: \n{0}".format(msg_form.errors), reverse_lazy("compose") )
def dispatch(self, request, *args, **kwargs): return ( redirect_with_msg(request, "You are already logged in.", "home", permanent=False, *args, **kwargs) if request.user.is_authenticated() else authviews.login( request, template_name="loginpage.html", extra_context={"user": models.UserProfile.get(self.request.user)}, ) )
def post(self, request, *args, **kwargs): post = { 'subject': request.POST.get('subject'), 'content': request.POST.get('content'), 'recipient': request.POST.get('recipient'), 'sender': str(models.UserProfile.get(request.user).id) } msg_form = self.message_form(post) if msg_form.is_valid(): msg = msg_form.save(commit=False) print(msg) msg.save() return redirect_with_msg(request, 'Message sent.', reverse_lazy('home')) else: print(msg_form.errors) return redirect_with_msg( request, 'The following errors were found: \n{0}'.format( msg_form.errors), reverse_lazy('compose'))
def post(self, request, *args, **kwargs): user_form = self.user_form(data=request.POST) profile_form = self.profile_form(data=request.POST) if user_form.is_valid() and profile_form.is_valid(): u = user_form.save() p = profile_form.save(commit=False) p.user = u p.save() """ user = authenticate(username=request.POST.get('username'), password=request.POST.get('password1')) login(request, user) """ return redirect_with_msg(request, 'Welcome!', 'home') else: return redirect_with_msg( request, 'The following errors were found: \n{0}'.format( user_form.errors), reverse_lazy('register'))
def post(self, request, *args, **kwargs): location_form = self.location_form(data=request.POST) match_form = self.match_form(data=request.POST) if location_form.is_valid() and match_form.is_valid(): location = location_form.save() match = match_form.save(commit=False) match.owner = acc.models.UserProfile.get(self.request.user) match.location = location match.save() return redirect_with_msg(request, 'Match created.', reverse_lazy('match.index'))
def post(self, request, *args, **kwargs): user_form = self.user_form(data=request.POST) profile_form = self.profile_form(data=request.POST) if user_form.is_valid() and profile_form.is_valid(): u = user_form.save() p = profile_form.save(commit=False) p.user = u p.save() """ user = authenticate(username=request.POST.get('username'), password=request.POST.get('password1')) login(request, user) """ return redirect_with_msg(request, "Welcome!", "home") else: return redirect_with_msg( request, "The following errors were found: \n{0}".format(user_form.errors), reverse_lazy("register") )
def post(self, request, *args, **kwargs): location_form = self.location_form(data=request.POST, instance=models.Location.objects.get(pk=self.kwargs['pk'])) match_form = self.match_form(data=request.POST, instance=models.Match.objects.get(pk=self.kwargs['pk'])) if location_form.is_valid() and match_form.is_valid(): location = location_form.save() match = match_form.save(commit=False) match.owner = acc.models.UserProfile.get(self.request.user) match.location = location match.save() match_form.save_m2m() return redirect_with_msg(request, 'Match updated.', reverse_lazy('match.index'))
def dispatch(self, request, *args, **kwargs): return redirect_with_msg(request, 'You are already logged in.', 'home', permanent=False, *args, **kwargs) \ if request.user.is_authenticated() else authviews.login(request, template_name='loginpage.html', extra_context={'user': models.UserProfile.get(self.request.user)})