def buy_single(product): # Check if user is signed in and has the info filled out. Only allow to join team if both conditions are satisfied. can_order = auth_logic.check_can_order() signed_in = can_order['signed_in'] info_completed = can_order['info_completed'] # If the user is not signed in, simply requires him/her to sign in and reopen the form if signed_in and info_completed: # Initialize single order. new_order = { 'user': server.get_user(), 'product': product, 'team_purchase': None } # Open order confirmation. order = anvil.alert(content=Buy_single_confimration(item=product), title="Comprar solo", buttons=[("COMPRAR", True), ("AHORA NO", False)], dismissible=False) # If user confirms order, create a new order. if order: server.create_pending_order(new_order) anvil.Notification( "You have successfully ordered. Please check Mis pedidos to review your order.", timeout=3).show() elif signed_in is False: anvil.users.login_with_form(allow_cancel=True) if anvil.users.get_user(): buy_single(product)
def link_my_direction_click(self, **event_args): """This method is called when the button is clicked""" # Initialize a copy of user to store new user input user_copy=self.user # For user just sign up with no address object, initiate the address object. if self.item['address']: user_copy['address']=self.item['address'] else: user_copy['address']={ 'street': "", 'colony': "", 'city': "", 'state': "", 'zip': "" } # Open edit form save=alert( content=My_address_edit(item=user_copy), title="Editar mi direccion", buttons=[("GUARDAR", True), ("CANCELAR", False)] ) # If user clicks save, update the user address. if save: server.update_user(user_copy) self.item=server.get_user() self.refresh_data_bindings(self.label_my_address.text)
def __init__(self, **properties): # Set Form properties and Data Bindings. self.init_components(**properties) # Any code you write here will run when the form opens. self.user = dict(list(server.get_user())) self.item = self.user
def join_private_team(member, code=None): # Check if user is signed in and has the info filled out. Only allow to join team if both conditions are satisfied. can_order = auth_logic.check_can_order() signed_in = can_order['signed_in'] info_completed = can_order['info_completed'] # If the user is not signed in, simply requires him/her to sign in and reopen the form. if signed_in and info_completed: # This is in case if the user exist the team form. completed_team = {} # User can either user the direct link (with URL hash) or input team code to join team. if code is None: # Input team code and bind it to an empty team object. team = {} join = anvil.alert(content=Join_private_team(item=team), title="Tengo un equipo", buttons=[("UNIRSE A ESTE EQUIPO", True), ("NO TENGO UN EQUIPO", False)]) # If user clicks Join button. if join: # Get team by team code. completed_team = server.get_team_by_team_code(team['code']) else: completed_team = server.get_team_by_team_code(code) # Check if there is a team with the currrent code. if completed_team is None: anvil.Notification( "This team doesn't exist. Please re-enter the right team code.", timeout=3).show() # This is in case if the user exit the Join_private_team form. elif completed_team == {}: pass # Carry on to create team orders. else: # Don't allow user to join his/her own team. if completed_team['creator'] == member: anvil.Notification("You cannot join your own team!", timeout=3).show() else: create_team_orders(completed_team, member) elif signed_in is False: anvil.users.login_with_form(allow_cancel=True) if server.get_user(): url_hash = anvil.get_url_hash() if url_hash: join_private_team(member, code=url_hash['code']) else: join_private_team(member, code=None)
def __init__(self, **properties): # Set Form properties and Data Bindings. self.init_components(**properties) # Any code you write here will run when the form opens. self.item=server.get_user() # Bind profile picture. If there is no profile picture, set the default profile picture once. if self.item['profile_picture']: self.image_profile.source=self.item['profile_picture'] else: self.image_profile.source=anvil.URLMedia("https://res.cloudinary.com/teepublic/image/private/s--1K1z6ZkG--/t_Preview/b_rgb:8bc0d0,c_limit,f_jpg,h_630,q_90,w_630/v1517191886/production/designs/2317478_0.jpg") auth_logic.default_profile(self.item)
def link_my_info_click(self, **event_args): """This method is called when the button is clicked""" # Initialize a copy of user to store new user input. user_copy=self.user user_copy['name']=self.item['name'] user_copy['phone']=self.item['phone'] # Open edit form. save=alert( content=My_info_edit(item=user_copy), title="Editar mi informacion", buttons=[("GUARDAR", True), ("CANCELAR", False)] ) # If user clicks save, update the user info. if save: server.update_user(user_copy) self.item=server.get_user() self.refresh_data_bindings()
def join_public_team(public_team, member): print('join team') # Check if user is signed in and has the info filled out. Only allow to join team if both conditions are satisfied. can_order = auth_logic.check_can_order() signed_in = can_order['signed_in'] info_completed = can_order['info_completed'] # If the user is not signed in, simply requires him/her to sign in and reopen the form if signed_in and info_completed: # Don't allow user to join his/her own team. if public_team['creator'] == member: anvil.Notification("You cannot join your own team!", timeout=3).show() else: return create_team_orders(public_team, member) elif signed_in is False: anvil.users.login_with_form(allow_cancel=True) if server.get_user(): join_public_team(public_team, member)
def check_can_order(): print('check can order') user = server.get_user() can_order = {'signed_in': False, 'info_completed': False} # Check if user is signed in; if not requires signing in to order. if user: can_order['signed_in'] = True # Check if user has all the information to order profile_completed = check_missing_user_info(user) if profile_completed: can_order['info_completed'] = True else: anvil.Notification( "Please complete your information to create an order.", timeout=5).show() nav_logic.go_to_my_profile() else: anvil.Notification("Please sign in to create an order.", timeout=3).show() return can_order
def link_have_team_click(self, **event_args): """This method is called when the button is clicked""" Purchase_logic.join_private_team(server.get_user())