def signup(request, u_type): if request.user.is_authenticated: return HttpResponseRedirect(reverse('root')) # if this is a POST request we need to process the form data if request.method == 'POST': form = forms.RegisterForm(request.POST, type=u_type) if form.is_valid() and request.recaptcha_is_valid: email = form.cleaned_data['email'] password = form.cleaned_data['password'] name = form.cleaned_data['name'] if models.User.objects.filter(email=email).first() is not None: form.add_error(None, 'An account with this email already exists') else: models.User.objects.create_user(email=email, password=password, name=name, u_type=u_type) user = auth.authenticate(email=email, password=password) auth.login(request, user) next_url = request.GET.get('next', reverse('root')) return HttpResponseRedirect(next_url) if not request.recaptcha_is_valid: form.add_error(None, 'Invalid reCAPTCHA. Please try again.') else: form = forms.RegisterForm() return render(request, 'signup.html', {'form': form})
def organizer_tabs(user): t = [('Reimbursements', reverse('reimbursement_list'), False), ('Receipts', reverse('receipt_review'), 'new' if models.Reimbursement.objects.filter( status=models.RE_PEND_APPROVAL).count() else False), ] if user.is_director: t.append(('Send', reverse('send_reimbursement'), False)) return t
def post(self, request, *args, **kwargs): if request.POST.get('create', None): team = models.Team() team.user = request.user team.save() return HttpResponseRedirect(reverse('teams')) if request.POST.get('leave', None): team = getattr(request.user, 'team', None) if team: team.delete() return HttpResponseRedirect(reverse('teams')) else: form = forms.JoinTeamForm(request.POST, request.FILES) if form.is_valid(): team = form.save(commit=False) team.user = request.user team.save() messages.success(request, 'Team joined successfully!') return HttpResponseRedirect(reverse('teams')) else: c = self.get_context_data() c.update({'form': form}) return render(request, self.template_name, c)
def organizer_tabs(user): t = [('Rooms', reverse('project_list'), False), ] if hasattr(user, 'room'): t.append(('Judge', reverse('judge_projects'), False)) if user.is_director: t.append(('Import', reverse('import_projects'), False)) return t
def signup(request): if request.user.is_authenticated: return HttpResponseRedirect(reverse('root')) # if this is a POST request we need to process the form data if request.method == 'POST': form = forms.RegisterForm(request.POST) if form.is_valid(): email = form.cleaned_data['email'] password = form.cleaned_data['password'] name = form.cleaned_data['name'] if models.User.objects.filter(email=email).first() is not None: messages.error(request, 'An account with this email already exists') else: user = models.User.objects.create_user(email=email, password=password, name=name) user = auth.authenticate(email=email, password=password) auth.login(request, user) return HttpResponseRedirect(reverse('root')) else: form = forms.RegisterForm() return render(request, 'signup.html', {'form': form})
def create_invite_email(application, request): c = { 'name': application.user.get_full_name, 'reimb': getattr(application.user, 'reimbursement', None), 'confirm_url': str( reverse('confirm_app', request=request, kwargs={'id': application.uuid_str})), 'cancel_url': str( reverse('cancel_app', request=request, kwargs={'id': application.uuid_str})), 'hybrid_option': 'Online' if getattr(application, 'online', False) else 'Live', } if application.user.is_hacker(): return emails.render_mail('mails/invitation_hacker', application.user.email, c) if application.user.is_mentor(): return emails.render_mail('mails/invitation_mentor', application.user.email, c) return emails.render_mail('mails/invitation_volunteer', application.user.email, c)
def send_email_verification(request): if request.user.email_verified: messages.warning(request, "Your email has already been verified") return HttpResponseRedirect(reverse('root')) msg = tokens.generate_verify_email(request.user) msg.send() messages.success(request, "Verification email successfully sent") return HttpResponseRedirect(reverse('root'))
def _get_context(app, reimb, request): return { 'app': app, 'reimb': reimb, 'confirm_url': str(reverse('confirm_app', kwargs={'id': app.uuid_str}, request=request)), 'form_url': str(reverse('reimbursement_dashboard', request=request)), 'cancel_url': str(reverse('cancel_app', kwargs={'id': app.uuid_str}, request=request)) }
def create_online_invite_email(application, request): c = { 'name': application.user.get_full_name, 'confirm_url': str(reverse('confirm_app', request=request, kwargs={'id': application.uuid_str})), 'cancel_url': str(reverse('cancel_app', request=request, kwargs={'id': application.uuid_str})) } return emails.render_mail('mails/invitation_online', application.user.email, c)
def callback(request, provider=None): if not provider: messages.error(request, 'Invalid URL') return HttpResponseRedirect(reverse('root')) if request.user.is_authenticated: return HttpResponseRedirect(reverse('root')) code = request.GET.get('code', '') if not code: messages.error(request, 'Invalid URL') return HttpResponseRedirect(reverse('root')) try: access_token = providers.auth_mlh(code, request) mlhuser = providers.get_mlh_user(access_token) except ValueError as e: messages.error(request, str(e)) return HttpResponseRedirect(reverse('root')) user = User.objects.filter(mlh_id=mlhuser.get('id', -1)).first() if user: auth.login(request, user) elif User.objects.filter(email=mlhuser.get('email', None)).first(): messages.error( request, 'An account with this email already exists. Sign in using your password.' ) else: user = User.objects.create_mlhuser( email=mlhuser.get('email', None), name=mlhuser.get('first_name', '') + ' ' + mlhuser.get('last_name', None), mlh_id=mlhuser.get('id', None), ) auth.login(request, user) # Save extra info draft = a_models.DraftApplication() draft.user = user mlhdiet = mlhuser.get('dietary_restrictions', '') diet = mlhdiet if mlhdiet in dict(a_models.DIETS).keys() else 'Others' draft.save_dict({ 'degree': mlhuser.get('major', ''), 'university': mlhuser.get('school', {}).get('name', ''), 'phone_number': mlhuser.get('phone_number', ''), 'tshirt_size': [ k for k, v in a_models.TSHIRT_SIZES if v == mlhuser.get('shirt_size', '') ][0], 'diet': mlhdiet, 'other_diet': mlhdiet if diet == 'Others' else '', }) draft.save() return HttpResponseRedirect(reverse('root'))
def create_invite_email(application, request): c = { 'name': application.user.get_full_name, 'reimb': getattr(application.user, 'reimbursement', None), 'confirm_url': str(reverse('confirm_app', request=request, kwargs={'id': application.uuid_str})), 'cancel_url': str(reverse('cancel_app', request=request, kwargs={'id': application.uuid_str})) } return emails.render_mail('mails/invitation', application.user.email, c)
def get(self, request, *args, **kwargs): try: DiscordUser.objects.get(user=request.user) return redirect(reverse('alreadyConnected')) except DiscordUser.DoesNotExist: url = request.build_absolute_uri(reverse('discord_redirect')) redirect_uri = quote(url, safe='') client_id = getattr(settings, 'DISCORD_CLIENT_ID', '') return redirect('%s/oauth2/authorize?client_id=%s&redirect_uri=%s&response_type=code&scope=identify' % (DISCORD_URL, client_id, redirect_uri))
def create_invite_email(application, request): c = { 'name': application.user.get_full_name, 'reimb': getattr(application.user, 'reimbursement', None), 'visas': application.visas, 'confirm_url': str(reverse('confirm_app', request=request, kwargs={'id': application.uuid_str})), 'cancel_url': str(reverse('cancel_app', request=request, kwargs={'id': application.uuid_str})) } return emails.render_mail('mails/invitation', application.user.email, c)
def create_lastreminder_email(application): c = { 'name': application.user.get_full_name, # We need to make sure to redirect HTTP to HTTPS in production 'confirm_url': 'http://%s%s' % (settings.HACKATHON_DOMAIN, reverse('confirm_app', kwargs={'id': application.uuid_str})), 'cancel_url': 'http://%s%s' % (settings.HACKATHON_DOMAIN, reverse('cancel_app', kwargs={'id': application.uuid_str})), } return emails.render_mail('mails/last_reminder', application.user.email, c, action_required=True)
def callback(request, provider=None): if not provider: messages.error(request, 'Invalid URL') return HttpResponseRedirect(reverse('root')) if request.user.is_authenticated: return HttpResponseRedirect(reverse('root')) code = request.GET.get('code', '') if not code: messages.error(request, 'Invalid URL') return HttpResponseRedirect(reverse('root')) try: access_token = providers.auth_mlh(code, request) mlhuser = providers.get_mlh_user(access_token) except ValueError as e: messages.error(request, str(e)) return HttpResponseRedirect(reverse('root')) user = User.objects.filter(mlh_id=mlhuser.get('id', -1)).first() if user: auth.login(request, user, backend="django.contrib.auth.backends.ModelBackend") elif User.objects.filter(email=mlhuser.get('email', None)).first(): messages.error(request, 'An account with this email already exists. Sign in using your password.') else: user = User.objects.create_mlhuser( email=mlhuser.get('email', None), name=mlhuser.get('first_name', '') + ' ' + mlhuser.get('last_name', None), mlh_id=mlhuser.get('id', None), ) auth.login(request, user, backend="django.contrib.auth.backends.ModelBackend") # Save extra info draft = DraftApplication() draft.user = user mlhgender = mlhuser.get('gender','') if mlhgender == "I prefer not to say" or mlhgender not in dict(Application.GENDERS).values(): mlhgender = "Prefer not to answer" mlhyear = mlhuser.get('level_of_study','') if mlhyear == "Not Currently a Student": mlhyear = Application.C_GRADUATED elif mlhyear == "University (Master's / Doctoral)": mlhyear = Application.C_GRAD else: mlhyear = Application.C_FRESHMAN draft.save_dict({ 'degree': mlhuser.get('major', ''), 'university': mlhuser.get('school', {}).get('name', ''), 'class_status': mlhyear, 'phone_number': '(' + mlhuser.get('phone_number', '')[2:5] + ') ' + mlhuser.get('phone_number', '')[5:8] + '-' + mlhuser.get('phone_number', '')[8:], 'gender': [k for k, v in Application.GENDERS if v == mlhgender][0], }) draft.save() return HttpResponseRedirect(reverse('root'))
def set_password(request): if request.user.has_usable_password(): return HttpResponseRedirect(reverse('root')) if request.method == 'GET': return TemplateResponse(request, 'callback.html', {'form': SetPasswordForm(), 'email': request.user.email}) else: form = SetPasswordForm(request.POST) if form.is_valid(): user = request.user form.save(user) auth.login(request, user) messages.success(request, 'Password correctly set') return HttpResponseRedirect(reverse('root')) return TemplateResponse(request, 'callback.html', {'form': form, 'email': request.user.email})
def login(request): if request.user.is_authenticated: return HttpResponseRedirect(reverse('root')) # if this is a POST request we need to process the form data if request.method == 'POST': form = forms.LoginForm(request.POST) next_ = request.GET.get('next', '/') if form.is_valid(): email = form.cleaned_data['email'] password = form.cleaned_data['password'] user = auth.authenticate(email=email, password=password) if user and user.is_active: auth.login(request, user) resp = HttpResponseRedirect(next_) c_domain = getattr(settings, 'LOGGED_IN_COOKIE_DOMAIN', getattr(settings, 'HACKATHON_DOMAIN', None)) c_key = getattr(settings, 'LOGGED_IN_COOKIE_KEY', None) if c_domain and c_key: try: resp.set_cookie(c_key, 'biene', domain=c_domain, max_age=settings.SESSION_COOKIE_AGE) except: # We don't care if this is not set, we are being cool here! pass return resp else: form.add_error(None, 'Incorrect username or password. Please try again.') else: form = forms.LoginForm() return render(request, 'login.html', {'form': form})
def post(self, request, *args, **kwargs): form = forms.RegisterSponsorForm(request.POST) if form.is_valid(): email = form.cleaned_data['email'] name = form.cleaned_data['name'] n_max = form.cleaned_data['n_max'] password = ''.join( random.choice(string.ascii_uppercase + string.digits) for _ in range(10)) if models.User.objects.filter(email=email).first() is not None: messages.error(request, 'An account with this email already exists') else: user = models.User.objects.create_sponsor(email=email, password=password, name=name, n_max=n_max) msg = tokens.generate_sponsor_link_email(user, request) msg.send() messages.success(request, "Sponsor link email successfully sent") return HttpResponseRedirect(reverse('sponsor_user_list')) context = self.get_context_data() context.update({'form': form}) return TemplateResponse(request, self.template_name, context)
def post(self, request, *args, **kwargs): new_application = False try: form = forms.ApplicationForm(request.POST, request.FILES, instance=request.user.application) new_application = ('submit' in request.POST) and ( request.user.application.status == models.APP_SAVED) except: form = forms.ApplicationForm(request.POST, request.FILES) if form.is_valid(): application = form.save(commit=False) application.user = request.user if 'submit' in request.POST: application.status = models.APP_PENDING application.save() if new_application: m = emails.create_application_email(application) m.send() messages.success( request, 'We have now received your application. ' 'Processing your application will take some time, so please be patient.' ) else: messages.success(request, 'Application changes saved successfully!') return HttpResponseRedirect(reverse('application')) else: c = self.get_context_data() c.update({'form': form}) return render(request, self.template_name, c)
def password_reset_confirm(request, uid, token): """ View that checks the hash in a password reset link and presents a form for entering a new password. """ try: uid = force_text(urlsafe_base64_decode(uid)) user = User.objects.get(pk=uid) except (TypeError, ValueError, OverflowError, User.DoesNotExist): return TemplateResponse(request, 'password_reset_confirm.html', {'validlink': False}) if password_reset_token.check_token(user, token): if request.method == 'POST': form = SetPasswordForm(request.POST) if form.is_valid(): form.save(user) return HttpResponseRedirect(reverse('password_reset_complete')) form = SetPasswordForm() else: return TemplateResponse(request, 'password_reset_confirm.html', {'validlink': False}) return TemplateResponse(request, 'password_reset_confirm.html', { 'validlink': True, 'form': form })
def post(self, request, *args, **kwargs): id_ = request.POST.get('id', None) reimb = models.Reimbursement.objects.get(pk=id_) a_form = forms.AcceptReceiptForm(instance=reimb) r_form = forms.RejectReceiptForm(instance=reimb) if request.POST.get('accept', None): a_form = forms.AcceptReceiptForm(request.POST, instance=reimb) if a_form.is_valid(): a_form.save(commit=False) a_form.instance.accept_receipt(request.user) a_form.save() messages.success(request, 'Receipt accepted') else: c = self.get_context_data() c.update({'reject_form': r_form, 'accept_form': a_form}) return render(request, self.template_name, c) elif request.POST.get('reject', None): r_form = forms.RejectReceiptForm(request.POST, instance=reimb) if r_form.is_valid(): r_form.save(commit=False) m = r_form.instance.reject_receipt(request.user, request) m.send() r_form.save() messages.success(request, 'Receipt rejected') else: c = self.get_context_data() c.update({'reject_form': r_form, 'accept_form': a_form}) return render(request, self.template_name, c) return HttpResponseRedirect(reverse('receipt_review'))
def post(self, request, *args, **kwargs): if not request.user.is_authenticated or not hasattr(self.request.user, 'room'): return redirect_to_login(self.request.get_full_path()) presentation_id = request.POST.get('presentation_id') presentation = Presentation.objects.get(pk=presentation_id) judge_aliases = ['A', 'B', 'C'] for judge in judge_aliases: tech = int(request.POST.get('tech_score_{}'.format(judge), None)) design = int(request.POST.get('design_score_{}'.format(judge), None)) completion = int(request.POST.get('completion_score_{}'.format(judge), None)) learning = int(request.POST.get('learning_score_{}'.format(judge), None)) try: if request.POST.get('skip'): skip_presentation(presentation) elif request.POST.get('send'): PresentationEvaluation.objects.get_or_create( presentation=presentation, judge_alias=judge, tech=tech, design=design, completion=completion, learning=learning ) presentation.done = True presentation.save() # If application has already been voted -> Skip and bring next # application except IntegrityError: pass return HttpResponseRedirect(reverse('judge_projects'))
def post(self, request, *args, **kwargs): ids = request.POST.getlist('selected') no_reimb = request.POST.get('no_reimb', False) reimbs = models.Reimbursement.objects.filter(pk__in=ids).all() mails = [] errors = 0 for reimb in reimbs: try: if not no_reimb: assigned_money = request.POST.get('am_' + str(reimb.pk)) reimb.assigned_money = assigned_money reimb.send(request.user) m = emails.create_reimbursement_email(reimb, request) else: reimb.no_reimb(request.user) m = emails.create_no_reimbursement_email(reimb, request) mails.append(m) except ValidationError: errors += 1 if mails: send_batch_emails(mails) if no_reimb: msg = "%s no reimbursements message sent" else: msg = "%s reimbursements sent" messages.success(request, msg % len(mails)) else: messages.error(request, "%s reimbursements not sent" % errors) return HttpResponseRedirect(reverse('send_reimbursement'))
def post(self, request, *args, **kwargs): new_application = True try: form = forms.ApplicationForm(request.POST, request.FILES, instance=request.user.application) new_application = False except: form = forms.ApplicationForm(request.POST, request.FILES) if form.is_valid(): application = form.save(commit=False) application.user = request.user application.save() if new_application: messages.success( request, 'We have now received your application. ' 'Processing your application will take some time, so please be patient.' ) else: messages.success(request, 'Application changes saved successfully!') return HttpResponseRedirect(reverse('root')) else: c = self.get_context_data() c.update({'form': form}) return render(request, self.template_name, c)
def post(self, request, *args, **kwargs): application = models.Application.objects.get(user=self.request.user) try: application.cancel() except ValidationError: pass return http.HttpResponseRedirect(reverse('dashboard'))
def post(self, request, *args, **kwargs): if request.user.application.is_invalid(): request.user.set_mentor() request.user.save() messages.success(request, 'Thanks for coming as mentor!') else: messages.error(request, 'You have no permissions to do this') return HttpResponseRedirect(reverse('dashboard'))
def get_redirect_url(self, **kwargs): check_type = kwargs['type'] for s in SUBJECTS: if check_type in s: self.request.session['check_type'] = check_type self.request.session['type_time'] = str(time.time()) return reverse('check_in_qr')
def callback(request, provider=None): if not provider: messages.error(request, 'Invalid URL') return HttpResponseRedirect(reverse('root')) if request.user.is_authenticated: return HttpResponseRedirect(reverse('root')) code = request.GET.get('code', '') if not code: messages.error(request, 'Invalid URL') return HttpResponseRedirect(reverse('root')) try: access_token = providers.auth_mlh(code, request) mlhuser = providers.get_mlh_user(access_token) except ValueError as e: messages.error(request, str(e)) return HttpResponseRedirect(reverse('root')) user = User.objects.filter(mlh_id=mlhuser.get('id', -1)).first() if user: auth.login(request, user) elif User.objects.filter(email=mlhuser.get('email', None)).first(): messages.error(request, 'An account with this email already exists. Sign in using your password.') else: user = User.objects.create_mlhuser( email=mlhuser.get('email', None), name=mlhuser.get('first_name', '') + ' ' + mlhuser.get('last_name', None), mlh_id=mlhuser.get('id', None), ) auth.login(request, user) # Save extra info draft = a_models.DraftApplication() draft.user = user mlhdiet = mlhuser.get('dietary_restrictions', '') diet = mlhdiet if mlhdiet in dict(a_models.DIETS).keys() else 'Other' draft.save_dict({ 'degree': mlhuser.get('major', ''), 'university': mlhuser.get('school', {}).get('name', ''), 'phone_number': mlhuser.get('phone_number', ''), 'tshirt_size': [k for k, v in a_models.TSHIRT_SIZES if v == mlhuser.get('shirt_size', '')][0], 'diet': mlhdiet, 'other_diet': mlhdiet if diet == 'Others' else '', }) draft.save() return HttpResponseRedirect(reverse('root'))
def create_confirmation_email(application, request): c = { 'name': application.user.get_full_name, 'token': application.uuid_str, 'qr_url': 'http://chart.googleapis.com/chart?cht=qr&chs=350x350&chl=%s' % application.uuid_str, 'cancel_url': str(reverse('cancel_app', request=request, kwargs={'id': application.uuid_str})), } return emails.render_mail('mails/confirmation', application.user.email, c)
def post(self, request, *args, **kwargs): Application = VIEW_APPLICATION_TYPE.get(self.request.user.type, models.HackerApplication) application = Application.objects.get(user=self.request.user) try: application.cancel() except ValidationError: pass return http.HttpResponseRedirect(reverse('dashboard'))
def get(self, request, *args, **kwargs): error = request.GET.get('error', None) if not error: code = request.GET.get('code', None) url = request.build_absolute_uri(reverse('discord_redirect')) token = get_token(code, url) discord_json = get_user_id(token) discord_id = discord_json.get('id') discord_username = discord_json.get('username') discord = DiscordUser(user=request.user, discord_id=discord_id, discord_username=discord_username) try: team = Team.objects.get(user=request.user) discord.team_name = team.team_code except Team.DoesNotExist: pass try: discord.save() except IntegrityError: return redirect(reverse('alreadyConnected')) return redirect(reverse('dashboard'))
def post(self, request, *args, **kwargs): form = forms.ProjectImportForm(request.POST, request.FILES) if form.is_valid(): handle_uploaded_projects(request.FILES['projects_file'].file) messages.success(self.request, 'Your project file was successfully uploaded.') else: c = self.get_context_data() c.update({'form': form}) return render(request, self.template_name, c) return HttpResponseRedirect(reverse('import_projects'))
def post(self, request, *args, **kwargs): id_ = kwargs.get('id', None) reimb = models.Reimbursement.objects.get(pk=id_) form = forms.EditReimbursementForm(request.POST, instance=reimb) if form.is_valid(): form.save() messages.success(self.request, "Changes in reimbursement successfully saved!") else: return render(request, self.template_name, {'reimb': reimb, 'edit_form': form}) return HttpResponseRedirect(reverse('reimbursement_detail', kwargs={'id': reimb.pk}))
def logout(request): auth.logout(request) messages.success(request, 'Successfully logged out!') resp = HttpResponseRedirect(reverse('account_login')) c_domain = getattr(settings, 'LOGGED_IN_COOKIE_DOMAIN', None) or getattr(settings, 'HACKATHON_DOMAIN', None) c_key = getattr(settings, 'LOGGED_IN_COOKIE_KEY', None) if c_domain and c_key: try: resp.delete_cookie(c_key, domain=c_domain) except: # We don't care if this is not deleted, we are being cool here! pass return resp
def post(self, request, *args, **kwargs): try: form = forms.ApplicationForm(request.POST, request.FILES, instance=request.user.application) except: form = forms.ApplicationForm(request.POST, request.FILES) if form.is_valid(): application = form.save(commit=False) application.user = request.user application.save() messages.success(request, 'Application changes saved successfully!') return HttpResponseRedirect(reverse('application')) else: c = self.get_context_data() c.update({'form': form}) return render(request, self.template_name, c)
def post(self, request, *args, **kwargs): try: form = forms.ReceiptSubmissionReceipt(request.POST, request.FILES, instance=request.user.reimbursement) except: form = forms.ReceiptSubmissionReceipt(request.POST, request.FILES) if form.is_valid(): reimb = form.save(commit=False) reimb.hacker = request.user reimb.save() messages.success(request, 'We have now received your reimbursement. ' 'Processing will take some time, so please be patient.') return HttpResponseRedirect(reverse('reimbursement_dashboard')) else: c = self.get_context_data() c.update({'form': form}) return render(request, self.template_name, c)
def password_reset(request): if request.method == "POST": form = PasswordResetForm(request.POST, ) if form.is_valid(): email = form.cleaned_data.get('email') user = User.objects.get(email=email) msg = tokens.generate_pw_reset_email(user, request) msg.send() return HttpResponseRedirect(reverse('password_reset_done')) else: return TemplateResponse(request, 'password_reset_form.html', {'form': form}) else: form = PasswordResetForm() context = { 'form': form, } return TemplateResponse(request, 'password_reset_form.html', context)
def get(self, request, *args, **kwargs): application = models.Application.objects.get(user=request.user) msg = None if application.can_confirm(): msg = emails.create_confirmation_email(application, self.request) try: application.confirm() except: raise Http404 if msg: msg.send() try: slack.send_slack_invite(request.user.email) # Ignore if we can't send, it's only optional except SlackInvitationException as e: logging.error(e) return http.HttpResponseRedirect(reverse('dashboard'))
def password_reset_confirm(request, uid, token): """ View that checks the hash in a password reset link and presents a form for entering a new password. """ try: uid = force_text(urlsafe_base64_decode(uid)) user = User.objects.get(pk=uid) except (TypeError, ValueError, OverflowError, User.DoesNotExist): return TemplateResponse(request, 'password_reset_confirm.html', {'validlink': False}) if password_reset_token.check_token(user, token): if request.method == 'POST': form = SetPasswordForm(request.POST) if form.is_valid(): form.save(user) return HttpResponseRedirect(reverse('password_reset_complete')) form = SetPasswordForm() else: return TemplateResponse(request, 'password_reset_confirm.html', {'validlink': False}) return TemplateResponse(request, 'password_reset_confirm.html', {'validlink': True, 'form': form})
def post(self, request, *args, **kwargs): new_application = True try: form = forms.ApplicationForm(request.POST, request.FILES, instance=request.user.application) new_application = False except: form = forms.ApplicationForm(request.POST, request.FILES) if form.is_valid(): application = form.save(commit=False) application.user = request.user application.save() if new_application: messages.success(request, 'We have now received your application. ' 'Processing your application will take some time, so please be patient.') else: messages.success(request, 'Application changes saved successfully!') return HttpResponseRedirect(reverse('root')) else: c = self.get_context_data() c.update({'form': form}) return render(request, self.template_name, c)
def user_tabs(user): return [('List', reverse('check_in_list'), False), ('QR', reverse('check_in_qr'), False), ('Ranking', reverse('check_in_ranking'), False)]
def get_back_url(self): return reverse('dashboard')
def get_back_url(self): return reverse('reimbursement_list')
def verify_email_required(request): if request.user.email_verified: messages.warning(request, "Your email has already been verified") return HttpResponseRedirect(reverse('root')) return TemplateResponse(request, 'verify_email_required.html', None)