def dispatch(self): # Get a session store for this request. #self.session_store = sessions.get_store(request=self.request) #url=self.request.url #base_url=urlparse.urlparse(self.request.url) #self.redirect_url="http%3A%2F%2F"+self.request.host+config.GOOGLE_CALLBACK_URI_APPEND self.redirect_url="http://"+self.request.host+'/auth/google/callback' self.user=get_current_user(self.request) if self.user: self.lang=self.request.get('lang') or self.request.cookies.get("lang") or self.user.locale else: self.lang=self.request.get('lang') or self.request.cookies.get("lang") if not (languages.validate(self.lang)): self.lang = 'en' other_languages_list= languages.get_languages_list() other_languages_list.remove(self.lang) self.destination=self.request.get('destination') or self.request.cookies.get("destination") self.provider_id = self.request.get('provider_id') self.pars = { #"logged_in" : self.logged_in, 'user':self.user, 'language_dict' : languages.current_lang_dict(self.lang), 'selected_language' : self.lang, 'languages_list' : languages.get_languages_list(), 'other_languages': other_languages_list, 'provider_types' : Provider.get_provider_types(), "login_url" : config.GOOGLE_LOGIN_URL + "&redirect_uri="+ self.redirect_url, 'destination' : self.destination } webapp2.RequestHandler.dispatch(self)
def validate_provider_form(self): error_list=[] warning_list=[] provider=Provider() destination = weddings.verify_destination(self.request.get('destination')) if destination: provider.destination=destination else: error_list.append({'destination': "Incorrect destination"}) provider_type = Provider.validate_type(self.request.get('provider_type')) if provider_type: provider.provider_type=provider_type else: error_list.append({'provider_type': "Incorrect provider_type"}) #logging.error (self.request.get('provider_id')) provider_id = Provider.validate_ID(self.request.get('provider_id')) if provider_id: provider.provider_id=provider_id else: error_list.append({'provider-ID': "Incorrect provider_id"}) names={} description={} for language in languages.get_languages_list(): name=Provider.validate_name(self.request.get('name__'+language)) if name: names.update({language : name}) else: warning_list.append({'name_'+language: "Missing or Incorrect name"}) description.update({language : cgi.escape(self.request.get('description__'+language))}) provider.name = names provider.description = description #TODO manage error lists provider.contact_email = Provider.validate_email(self.request.get('contact_email')) provider.url = Provider.validate_url(self.request.get('url')) provider.phone = Provider.validate_phone(self.request.get('phone')) provider.address, provider.location = Provider.validate_address(self.request.get('address'), self.request.get('x-coord'), self.request.get('y-coord')) provider.phone = Provider.validate_rating(self.request.get('rating')) provider.phone = Provider.validate_price_range(self.request.get('pricerangetext')) provider.phone = Provider.validate_price_class(self.request.get('price_class')) logging.error(self.request.get('pictures')) logging.error(str(self.request.get('pictures'))) logging.error(str.split(str(self.request.get('pictures')),'\r\n')) provider.pictures = Provider.validate_pictures(str.split(str(self.request.get('pictures')),'\r\n')) if error_list: logging.error("validation error" + str(error_list)) else: logging.error("validation warnings" + str(warning_list)) logging.error(provider) return provider, error_list, warning_list pass