def create_test_provider(**args): ''' Create a test provider with an open schedule ''' p = Provider(**args) p_key = p.put() return (p_key, p)
def display_general_provider_universe_stats(booking): # unpack booking request request_category = booking.request_category # ignore location for now #request_location = booking.request_location # general debug stats providerUniverseCount = Provider.query().count() logging.info('Total provider universe: %s' % providerUniverseCount) broadMatchCount = Provider.query(Provider.category==request_category).count() logging.info('Found %s providers offering %s (ignoring enable and terms agreement)' % (broadMatchCount, request_category))
def get(self): stats_map = {} # get hits to any page stats_map['page_hit_count'] = SiteLog.query(SiteLog.page == '/', SiteLog.admin_email == None).count() # get hits to home page stats_map['homepage_hit_count'] = SiteLog.query(SiteLog.page == '/', SiteLog.admin_email == None).count() # get hits to provider signup page stats_map['provider_signup_hit_count'] = SiteLog.query(SiteLog.page == '/signup/provider', SiteLog.admin_email == None).count() # get total # of providers stats_map['provider_total_count'] = Provider.query().count() # get hits from Internet Explorer stats_map['internet_explorer_count'] = db.get_site_counter().internet_explorer_hits # number of times exiting site to blog stats_map['blog_clicks'] = db.get_site_counter().blog_clicks stats_map['click_full_button'] = db.get_site_counter().click_full_button stats_map['click_preview_button'] = db.get_site_counter().click_preview_button stats_map['signup_full_button'] = db.get_signup_from_origin('full') stats_map['signup_preview_button'] = db.get_signup_from_origin('preview') stats_map['paid_full_button'] = db.get_paid_from_origin('full') stats_map['paid_preview_button'] = db.get_paid_from_origin('preview') self.render_template('admin/dashboard.html', stats_map=stats_map)
def get_paid_from_origin(origin): if origin: provider_keys = Provider.query(Provider.signup_origin == origin).fetch(keys_only=True) if provider_keys: provider_account_count = ProviderAccount.query(ProviderAccount.provider.IN(provider_keys)).count() return provider_account_count else: return 0
def get(self): #vanity_url_list = db.get_all_vanity_urls() categories = [] domain_setup = self.get_domain_setup() if domain_setup and domain_setup.categories_json: categories_json = domain_setup.categories_json categories_from_json = json.loads(categories_json) for (key, english_string) in categories_from_json: categories.append(key) vanity_url_list = [] if categories: vanity_url_list = Provider.query(Provider.category.IN(categories)).fetch(projection=['vanity_url']) self.render_template("sitemap.xml", vanity_url_list=vanity_url_list)
def get(self): #vanity_url_list = db.get_all_vanity_urls() categories = [] domain_setup = self.get_domain_setup() if domain_setup and domain_setup.categories_json: categories_json = domain_setup.categories_json categories_from_json = json.loads(categories_json) for (key, english_string) in categories_from_json: categories.append(key) vanity_url_list = [] if categories: vanity_url_list = Provider.query( Provider.category.IN(categories)).fetch( projection=['vanity_url']) self.render_template("sitemap.xml", vanity_url_list=vanity_url_list)
def provider_search(booking): ''' 1. Select the closest available timeslot per provider 2. Sorts all booking responses by proximity to requested time Returns list of BookingResponse ''' display_general_provider_universe_stats(booking) # unpack booking request request_category = booking.request_category #request_location = booking.request_location # match on location and category, sort by experience (ascending start_year) providers_wide_query = Provider.query(Provider.category==request_category).order(Provider.start_year, Provider.created_on) # remove disabled providers (ie. keep only enabled) providers_wide_query = providers_wide_query.filter(Provider.status.IN(['prospect', 'contacted_phone', 'contacted_meeting', 'client_enabled'])) #if booking.request_homecare: # providers_wide_query = providers_wide_query.filter(Provider.practice_sites=='onsite') logging.info('Found %s providers offering %s (enabled and with terms)' % (providers_wide_query.count(), request_category)) # sort by best available timeslot and filter out booking conflicts booking_responses = filter_and_sort_providers_based_on_schedule(booking, providers_wide_query) logging.info('Returning %s booking-responses offering %s at requested date and time' % (len(booking_responses), request_category)) return booking_responses
def fetch_providers(): return Provider.query().order(Provider.last_name)
def get_signup_from_origin(origin): if origin: return Provider.query(Provider.signup_origin == origin).count()
def get_provider_from_domain(domain): '''returns the first provider profile liked to domain. Returns None if domain is not provided ''' if domain: return Provider.query(Provider.vanity_domain == domain).get() else: return None
def get_provider_from_vanity_url(vanity_url): '''returns the first provider profile liked to vanity_url. Returns None if vanity_url is not provided ''' if vanity_url: return Provider.query(Provider.vanity_url == vanity_url).get() else: return None
def get_provider_from_user(user): '''returns the first provider profile liked to user. Returns None if user is not a provider''' if user: return Provider.query(Provider.user == user.key).get() else: return None
def get_all_vanity_urls(): return Provider.query().fetch(projection=['vanity_url'])
def get_provider_from_email(email): provider = Provider.query(Provider.email == email).get() logging.debug('Provider for email %s is %s' % (email, provider)) return provider
def post(self): provider_signup_form2 = forms.user.ProviderSignupForm2().get_form( self.request.POST, request_webob=self.request) # check for double submit # if the first submit worked, a user should have been created and logged in user = self.get_current_user() if user: provider = db.get_provider_from_user(user) if provider: email = provider_signup_form2['email'].data if email == provider.email == user.get_email(): # someone is already logged in with the address being submitted # probably a double submit... self.redirect('/provider/welcome/' + provider.vanity_url) return if provider_signup_form2.validate(): # init the provider provider = Provider() provider_signup_form2.populate_obj(provider) # pre-populate vanity_url with first name + last name + number if collision first_name = provider.first_name last_name = provider.last_name vanity_url = first_name + last_name provider.vanity_url = validate_vanity_url(vanity_url) provider.domain = self.get_domain() # set location info from request if "X-AppEngine-Country" in self.request.headers: provider.gae_country = self.request.headers[ "X-AppEngine-Country"] if "X-AppEngine-Region" in self.request.headers: provider.gae_region = self.request.headers[ "X-AppEngine-Region"] if "X-AppEngine-City" in self.request.headers: provider.gae_city = self.request.headers["X-AppEngine-City"] if "X-AppEngine-CityLatLong" in self.request.headers: provider.gae_city_lat_long = self.request.headers[ "X-AppEngine-CityLatLong"] # save provider provider.put() # check if an invitation was associated to this invite = db.get_invite_from_email(provider.email) if invite: invite.profile_created = True invite.token = None invite.put() # connect this provider to invite_provider provider_network_connection = ProviderNetworkConnection() provider_network_connection.invite = invite.key provider_network_connection.source_provider = invite.provider provider_network_connection.target_provider = provider.key provider_network_connection.confirmed = True provider_network_connection.put() # now create an empty user for the provider user = self.create_empty_user_for_provider(provider) user.language = self.get_language() user.last_login = datetime.datetime.now() provider.profile_language = user.language provider.put() # set the password for the user password = provider_signup_form2.password.data password_hash = security.generate_password_hash(password, length=12) user.password = password_hash user.put() # login with new password self.login_user(user.get_email(), password) # new user logging.info( '(PasswordHandler.post) New user just set their password: %s' % user.get_email()) self.redirect('/provider/welcome/' + provider.vanity_url) self.log_event(user, "New account created for user" ) # create a signup token for new user # remove partial provider partial_provider = db.get_partial_provider_from_email( provider.email) if partial_provider: partial_provider.key.delete() # Send welcome email to provider welcome_email_enabled = db.get_site_config().welcome_email_enabled if welcome_email_enabled: mail.email_provider_welcome(self.jinja2, provider) else: self.render_template('user/signup_provider_2.html', provider_signup_form2=provider_signup_form2)
def get_provider(self): return Provider.query(Provider.email == self.email).get()
def post(self): provider_signup_form2 = forms.user.ProviderSignupForm2().get_form(self.request.POST, request_webob=self.request) # check for double submit # if the first submit worked, a user should have been created and logged in user = self.get_current_user() if user: provider = db.get_provider_from_user(user) if provider: email = provider_signup_form2['email'].data if email == provider.email == user.get_email(): # someone is already logged in with the address being submitted # probably a double submit... self.redirect('/provider/welcome/' + provider.vanity_url) return if provider_signup_form2.validate(): # init the provider provider = Provider() provider_signup_form2.populate_obj(provider) # pre-populate vanity_url with first name + last name + number if collision first_name = provider.first_name last_name = provider.last_name vanity_url = first_name + last_name provider.vanity_url = validate_vanity_url(vanity_url) provider.domain = self.get_domain() # set location info from request if "X-AppEngine-Country" in self.request.headers: provider.gae_country = self.request.headers["X-AppEngine-Country"] if "X-AppEngine-Region" in self.request.headers: provider.gae_region = self.request.headers["X-AppEngine-Region"] if "X-AppEngine-City" in self.request.headers: provider.gae_city = self.request.headers["X-AppEngine-City"] if "X-AppEngine-CityLatLong" in self.request.headers: provider.gae_city_lat_long = self.request.headers["X-AppEngine-CityLatLong"] # save provider provider.put() # check if an invitation was associated to this invite = db.get_invite_from_email(provider.email) if invite: invite.profile_created = True invite.token = None invite.put() # connect this provider to invite_provider provider_network_connection = ProviderNetworkConnection() provider_network_connection.invite = invite.key provider_network_connection.source_provider = invite.provider provider_network_connection.target_provider = provider.key provider_network_connection.confirmed = True provider_network_connection.put() # now create an empty user for the provider user = self.create_empty_user_for_provider(provider) user.language = self.get_language() user.last_login = datetime.datetime.now() provider.profile_language = user.language provider.put() # set the password for the user password = provider_signup_form2.password.data password_hash = security.generate_password_hash(password, length=12) user.password = password_hash user.put() # login with new password self.login_user(user.get_email(), password) # new user logging.info('(PasswordHandler.post) New user just set their password: %s' % user.get_email()) self.redirect('/provider/welcome/' + provider.vanity_url) self.log_event(user, "New account created for user") # create a signup token for new user # remove partial provider partial_provider = db.get_partial_provider_from_email(provider.email) if partial_provider: partial_provider.key.delete() # Send welcome email to provider welcome_email_enabled = db.get_site_config().welcome_email_enabled if welcome_email_enabled: mail.email_provider_welcome(self.jinja2, provider) else: self.render_template('user/signup_provider_2.html', provider_signup_form2=provider_signup_form2)