How to use current_user method in autotest

Best Python code snippet using autotest_python

routes.py

Source:routes.py Github

copy

Full Screen

1"""Logged-in page routes."""2from flask import Blueprint, render_template, redirect, url_for, flash, request3from flask_login import current_user, login_required, logout_user4from .forms import RequestForm5from .models import db, User, Rooms, RequestsForm6import datetime7# Blueprint Configuration8main_bp = Blueprint(9 "main_bp", __name__, template_folder="templates", static_folder="static"10)11@main_bp.route("/home", methods=["GET"])12def index():13 if current_user.is_authenticated:14 return render_template(15 "index.jinja2",16 current_user=current_user,17 items=["Request", "Information","Admin", "Logout"] if current_user.email=='admin' else ["Request", "Information", "Logout"] ,18 )19 else:20 return render_template("index.jinja2")21@main_bp.route("/about", methods=["GET"])22def about():23 if current_user.is_authenticated:24 return render_template(25 "about.jinja2",26 current_user=current_user,27 items=["Request", "Information","Admin", "Logout"] if current_user.email=='admin' else ["Request", "Information", "Logout"] ,28 )29 else:30 return render_template("about.jinja2")31@main_bp.route("/", methods=["GET"])32def dashboard():33 """Logged-in User Dashboard."""34 if current_user.is_authenticated:35 return render_template(36 "index.jinja2",37 current_user=current_user,38 items=["Request", "Information","Admin", "Logout"] if current_user.email=='admin' else ["Request", "Information", "Logout"] ,39 )40 else:41 return render_template("index.jinja2")42@main_bp.route("/logout")43@login_required44def logout():45 """User log-out logic."""46 current_user.last_login = datetime.datetime.now()47 db.session.commit()48 logout_user()49 return redirect(url_for("auth_bp.login"))50@main_bp.route("/publicSpace", methods=["GET"])51def publicSpace():52 if current_user.is_authenticated:53 return render_template(54 "publicSpace.jinja2",55 current_user=current_user,56 items=["Request", "Information","Admin", "Logout"] if current_user.email=='admin' else ["Request", "Information", "Logout"] ,57 )58 else:59 return render_template("publicSpace.jinja2")60@main_bp.route("/housing", methods=["GET"])61def housing():62 if current_user.is_authenticated:63 return render_template(64 "housing.jinja2",65 current_user=current_user,66 items=["Request", "Information","Admin", "Logout"] if current_user.email=='admin' else ["Request", "Information", "Logout"] ,67 )68 else:69 return render_template("housing.jinja2")70@main_bp.route("/sport", methods=["GET"])71def sport():72 if current_user.is_authenticated:73 return render_template(74 "sport.jinja2",75 current_user=current_user,76 items=["Request", "Information","Admin", "Logout"] if current_user.email=='admin' else ["Request", "Information", "Logout"] ,77 )78 else:79 return render_template("sport.jinja2")80@main_bp.route("/livingCost", methods=["GET"])81def livingCost():82 if current_user.is_authenticated:83 return render_template(84 "livingCost.jinja2",85 current_user=current_user,86 items=["Request", "Information","Admin", "Logout"] if current_user.email=='admin' else ["Request", "Information", "Logout"] ,87 )88 else:89 return render_template("livingCost.jinja2")90@main_bp.route("/request", methods=["GET", "POST"])91def request_user():92 """93 User sign-up page.94 GET requests serve sign-up page.95 POST requests validate form & user creation.96 """97 if not current_user.is_authenticated:98 flash("You are not login!!")99 return redirect(url_for("main_bp.dashboard"))100 if current_user.is_authenticated and request.method == "POST":101 messenger_err = []102 request_params = []103 request_params.append(current_user.email)104 request_params.append(request.form["comment"])105 if request.form["sellect"] == "yes":106 request_params.append("change room")107 if current_user.numberDomitory == "":108 messenger_err.append("You are not have room!")109 messenger_err.append("Please add new contract!")110 if current_user.room == request.form["nextroom"]:111 messenger_err += ["Next room should diffirence current room!"]112 current_user.room = request.form["nextroom"]113 else:114 request_params.append("new contract")115 if request.form["numberdom"] not in range(1, 5):116 messenger_err.append("Number domitory should in 1-4")117 if request.form["nextroom"] in Rooms.query.filter_by(118 email=request.form["numberdom"]119 ).select("room"):120 current_user.room = request.form["nextroom"]121 current_user.numberDomitory = request.form["numberdom"]122 current_user.numofcontract = "ITMO-0{}-{}-{}".format(123 request.form["numberdom"], request.form["nextroom"], current_user.id124 )125 current_user.startcontract = datetime.date.today()126 current_user.endofcontract = datetime.date(int(2020), int(6), int(30))127 if messenger_err:128 request_params.append("FALSE")129 new_request = RequestsForm(130 email=request_params[0],131 request_type=request_params[2],132 request_mess=request_params[1],133 status_request=request_params[3],134 )135 db.session.add(new_request)136 db.session.commit()137 return render_template(138 "request.jinja2",139 current_user=current_user,140 items=["Request", "Information","Admin", "Logout"] if current_user.email=='admin' else ["Request", "Information", "Logout"] ,141 error=messenger_err,142 )143 else:144 request_params.append("TRUE")145 db.session.commit()146 return render_template(147 "success.jinja2",148 current_user=current_user,149 items=["Request", "Information","Admin", "Logout"] if current_user.email=='admin' else ["Request", "Information", "Logout"] ,150 error=messenger_err,151 )152 return render_template(153 "request.jinja2",154 current_user=current_user,155 items=["Request", "Information","Admin", "Logout"] if current_user.email=='admin' else ["Request", "Information", "Logout"] ,156 )157@main_bp.route("/information", methods=["GET"])158def info():159 if current_user.is_authenticated:160 photolink = (161 "../static/img/boy.png"162 if current_user.sex == "Male"163 else "../static/img/girl.png"164 )165 act = RequestsForm.query.filter_by(email=current_user.email).all()166 if current_user.email=='admin': 167 return render_template(168 "information.jinja2",169 current_user=current_user,170 items=["Request", "Information","Admin", "Logout"] if current_user.email=='admin' else ["Request", "Information", "Logout"] ,171 username=current_user.name,172 address_user=current_user.address,173 passport_user=current_user.passport,174 numcontract=current_user.numofcontract,175 startcontract=current_user.startcontract,176 endcontract=current_user.endofcontract,177 photo_link=photolink,178 activity=act,179 )180 else: 181 return render_template(182 "information.jinja2",183 current_user=current_user,184 items=["Request", "Information","Admin", "Logout"] if current_user.email=='admin' else ["Request", "Information", "Logout"] ,185 username=current_user.name,186 address_user=current_user.address,187 passport_user=current_user.passport,188 numcontract=current_user.numofcontract,189 startcontract=current_user.startcontract,190 endcontract=current_user.endofcontract,191 photo_link=photolink,192 activity=act,193 )194 else:195 return render_template("index.jinja2")196# @main_bp.route("/admin", methods=["GET"])197# def adminview():...

Full Screen

Full Screen

capstone_kv_impl.py

Source:capstone_kv_impl.py Github

copy

Full Screen

1import kivy2kivy.require('1.9.0')34from kivy.config import Config5Config.set('graphics', 'width', '375')#configure a file6Config.set('graphics', 'height', '667')7from kivy.app import App8from kivymd.app import MDApp9from kivy.lang import Builder10from kivy.uix.widget import Widget11from kivy.uix.screenmanager import ScreenManager, Screen12import db1314global current_user15current_user = object()16global kivy_app17kivy_app = object()181920def check_email(email):21 import re22 regex = '^[a-z0-9\._]+[@]\w+[.]\w{2,3}$' # regular expression pattern to check email validation2324 if(re.search(regex,email)):25 print("Valid Email")26 return True27 else:28 print("Invalid Email")29 return False303132class UserData:33 def __init__(self,un =""):34 self.UserName=un35 self.FirstName=""36 self.LastName=""37 self.ZipCode=""38 self.DateOfBirth=""39 self.Email=""40 self.Interests=""41 pass4243 def update(self,data):44 self.UserName = data[1]45 self.FirstName= data[3]46 self.LastName= data[4]47 self.ZipCode= data[5]48 self.DateOfBirth= data[6]49 self.Email= data[7]50 self.Interests= data[8]51 pass525354 pass555657class LoginWindow(Screen):#58 def login_released(self,usnm, passw):59 print(f"user name = {usnm.text}")60 print(f"password = {passw.text}")61 userNameExists = db.un_exists(usnm.text)62 if userNameExists == True:63 result = db.un_login(usnm.text,passw.text)64 if result == True:65 global current_user66 current_user = UserData(usnm.text)67 # clear text fields68 usnm.text =""69 passw.text =""70 #set window to profile71 kivy_app.root.current = "profile"72 pass73 else:74 kivy_app.root.current = "login_wrong_password"75 else:76 # give users feedback that they are not able to log in due to invalid credentials77 kivy_app.root.current = "login_no_username"78 pass7980 self.manager.transition.direction = "left"8182 pass8384 pass8586 pass8788class LoginNoUsernameWindow(Screen):89 pass9091class LoginEmailUsernameWindow(Screen):92 def email_username(self, email, message, email_button, cancel_button):93 kivy_app.root.current = "login_email_username_confirmation"94 self.manager.transition.direction = "left"9596 pass97 pass98class LoginEmailUsernameConfirmationWindow(Screen):99 pass100101class LoginWrongPasswordWindow(Screen):102 pass103104class LoginResetPasswordWindow(Screen):105 def email_password_reset(self,email, message, email_button, cancel_button):106 kivy_app.root.current = "login_reset_password_confirmation"107 self.manager.transition.direction = "left"108109 pass110 pass111class LoginResetPasswordConfirmationWindow(Screen):112 pass113114115class ProfileView(Widget):116 pass117118class ProfileWindow(Screen):119 def display_userdata(self,usnm,first_name,last_name,zip_code,date_of_birth,email,interests):120 user_profiles = db.profile_get(current_user.UserName)121 assert len(user_profiles) > 0122123 user_data = user_profiles[0]124 current_user.update(user_data)125126 usnm.text = current_user.UserName127 first_name.text = current_user.FirstName128 last_name.text = current_user.LastName129 zip_code.text = current_user.ZipCode130 date_of_birth.text = current_user.DateOfBirth131 email.text = current_user.Email132 interests.text = current_user.Interests133134135 pass136137 pass138139140class ProfileCreateWindow(Screen):141 def create_profile_released(self,usnm,passw,passw2,first_name,last_name,zip_code,date_of_birth,email,interests):142 all_required_info = True143 required_fields = [usnm,passw,passw2,first_name,last_name,zip_code,date_of_birth,email]144 for field in required_fields:145 if field.text == "":146 all_required_info = False147 field.background_color = [1, 0.5, 0.5, 1]148 else:149 field.background_color = [1, 1, 1, 1]150 pass151152 if passw2.text != passw.text:153 all_required_info = False154 passw2.background_color = [1, 0.5, 0.5, 1]155156 # if not check_email(email.text):157 # all_required_info = False158 # email.background_color = [1, 0.5, 0.5, 1]159160 if not all_required_info:161 return162163 global current_user164165 user_name_already_in_use = db.un_exists(usnm.text)166 if user_name_already_in_use:167 usnm.background_color = [1, 0.5, 0.5, 1]168 current_user = UserData(usnm.text)169 kivy_app.root.current = "profile_username_already_in_use"170 self.manager.transition.direction = "left"171 else:172173 db.profile_new(usnm.text,passw.text,first_name.text,last_name.text,zip_code.text, date_of_birth.text,email.text,interests.text)174 current_user.UserName = usnm.text175 current_user.FirstName = first_name.text176 current_user.LastName = last_name.text177 current_user.ZipCode = zip_code.text178 current_user.DateOfBirth = date_of_birth.text179 current_user.Email = email.text180 current_user.Interests = interests.text181182 kivy_app.root.current = "profile"183 self.manager.transition.direction = "left"184185 pass186187 pass188189class ProfileUserNameAlreadyInUseWindow(Screen):190 message_base = None191192193 def update_message(self):194 if self.message_base == None:195 self.message_base = self.message.text196 self.message.text = current_user.UserName + self.message_base197 pass198 pass199200class WindowManager(ScreenManager):201202 def get_username(self):203 global current_user204205 return current_user.UserName206207 def update_username(self,newusername ):208209 global current_user210 current_user.UserName = newusername211212 pass213214 def clear_released(self,* args):215 for element in args:216 element.text = ""217 pass218 pass219220221 pass222223224current_user = UserData()225226227228class MyMainApp(MDApp):229 def build(self):230 return Builder.load_file("my.kv")231232233234def main():235 db.init()236 pass237238239if __name__ == "__main__":240 kivy_app = MyMainApp()241242 main() ...

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run autotest automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful