Ejemplo n.º 1
0
 def get_index_file(self):    
     domain_without_ports = self.request.host.split(":")[0]
     domain = domain_without_ports.replace("www.", "")
     domain_setup = db.get_domain_setup(domain)
     index_file = 'index.html'
     if domain_setup and domain_setup.index_file:
         index_file = domain_setup.index_file
         
     return index_file
Ejemplo n.º 2
0
    def get_index_file(self):
        domain_without_ports = self.request.host.split(":")[0]
        domain = domain_without_ports.replace("www.", "")
        domain_setup = db.get_domain_setup(domain)
        index_file = 'index.html'
        if domain_setup and domain_setup.index_file:
            index_file = domain_setup.index_file

        return index_file
Ejemplo n.º 3
0
 def post(self, domain = None):
     form = DomainSetupForm().get_form(self.request.POST)
     
     if form.validate():
         domain_setup = db.get_domain_setup(domain)
         
         form.populate_obj(domain_setup)
         domain_setup.put()
         
         self.redirect('/admin/domain/' + domain)
     else:
         self.render_template('admin/domain-setup.html', domain=domain, form=form)
Ejemplo n.º 4
0
 def get(self, domain = None):
     if not domain:
         self.render_template('admin/domain-setup.html', domain_list = util.DOMAINS)
     else:
         domain_setup = db.get_domain_setup(domain)
         if not domain_setup:
             domain_setup = DomainSetup()
             domain_setup.domain_name = domain
             domain_setup.put()
             
         domain_setup_form = DomainSetupForm().get_form(obj=domain_setup)
         
         self.render_template('admin/domain-setup.html', domain=domain, form=domain_setup_form)
Ejemplo n.º 5
0
    def post(self, domain=None):
        form = DomainSetupForm().get_form(self.request.POST)

        if form.validate():
            domain_setup = db.get_domain_setup(domain)

            form.populate_obj(domain_setup)
            domain_setup.put()

            self.redirect('/admin/domain/' + domain)
        else:
            self.render_template('admin/domain-setup.html',
                                 domain=domain,
                                 form=form)
Ejemplo n.º 6
0
    def get(self, domain=None):
        if not domain:
            self.render_template('admin/domain-setup.html',
                                 domain_list=util.DOMAINS)
        else:
            domain_setup = db.get_domain_setup(domain)
            if not domain_setup:
                domain_setup = DomainSetup()
                domain_setup.domain_name = domain
                domain_setup.put()

            domain_setup_form = DomainSetupForm().get_form(obj=domain_setup)

            self.render_template('admin/domain-setup.html',
                                 domain=domain,
                                 form=domain_setup_form)
Ejemplo n.º 7
0
    def render_template(self, filename, provider=None, **kw):
        '''
            Common template rendering function
        '''
                
        # domain setup
        domain_without_ports = self.request.host.split(":")[0]
        domain = domain_without_www = domain_without_ports.replace("www.", "")
        kw['domain_setup'] = db.get_domain_setup(domain_without_www)
        
        kw['valid_domains'] = util.DOMAINS
        
        # add template arguments common to all templates
        user = self.get_current_user()
        roles = []
        
        # hack for providers 
        # (allows provider pages to be accessed without a user logged in but knowing the provider key)
        kw['provider'] = provider
        kw['provider_from_user'] = None

        # somebody is logged in
        if user:
            logging.info('(BaseHandler.render_template) User logged in: %s with roles %s' % (user.get_email(), user.roles))
            kw['user'] = user
                        
            # extend roles
            roles.extend(user.roles)
            
            # is it a provider?
            if handler.auth.PROVIDER_ROLE in roles:
                provider_from_user = data.db.get_provider_from_user(user)
                logging.info('(BaseHandler.render_template) Provider logged in: ' + user.get_email())
                
                # overwrite for menu from logged in user
                kw['provider_from_user'] = provider_from_user


                # verify user->provider matches request->provider passed as paramater (ie. from request key)
                if provider: 
                    if not provider_from_user == provider:
                        logging.error("(BaseHandler.render_template) Logged in user does not match provider_key. We have a problem.")
                        
          
            if handler.auth.PATIENT_ROLE in roles:
                patient = data.db.get_patient_from_user(user)
                logging.info('(BaseHandler.render_template) Patient logged in: ' + user.get_email())
                if patient:
                    kw['patient'] = patient

        
        google_user = users.get_current_user()
        if google_user:
            logging.info('(BaseHandler.render_template) Google User also logged in: ' + str(google_user))
            kw['google_user'] = google_user

            # check google account for admin, add to roles
            if users.is_current_user_admin():
                roles.append(handler.auth.ADMIN_ROLE)
                
                # add fake login for current user
                kw['provider_from_user'] = kw['provider']

        
        # set the roles
        kw['roles'] = roles
            
        # set the language
        lang = self.get_language()
        logging.debug('(BaseHandler.render_template) Language is %s' % lang)
        kw['lang'] = lang
        kw['other_languages'] = filter(lambda l: l not in lang, util.LANGUAGE_LABELS.keys())

        # Login and logout URLs (why is this coded here? : Beacause historically for google users you had to call a method to get the login and logout urls)
        kw['login_url'] = '/' + lang + '/login'
        kw['logout_url'] = '/logout'
        kw['admin_logout_url'] = users.create_logout_url('/')
        
        kw['language_labels'] = util.LANGUAGE_LABELS
        kw['is_url_translatable'] = language.is_url_translatable(self.request.url)
        if kw['is_url_translatable']:
            kw['url_post_language'] = language.get_url_post_language(self.request.url)
        
        
        # make all session variables available to templates
        kw['session'] = self.session
        kw['host'] = self.request.host
        
        # ---------------
        # Site config
        # ---------------
        
        site_config = db.get_site_config()
        if site_config:
            kw['site_config'] = site_config
            kw['booking_enabled'] = site_config.booking_enabled
            kw['google_analytics_enabled'] = site_config.google_analytics_enabled
            kw['facebook_like_enabled'] = site_config.facebook_like_enabled

        else:
            # no site configuration exists in database, create one
            site_config = SiteConfig()
            
            # take defaul state for booking enabled from util 
            # (so it can be set before the handler is called in unit tests)
            site_config.booking_enabled = util.BOOKING_ENABLED
            
            site_config.put()
            kw['site_config'] = site_config
            kw['booking_enabled'] = site_config.booking_enabled
            kw['google_analytics_enabled'] = site_config.google_analytics_enabled
            kw['facebook_like_enabled'] = site_config.facebook_like_enabled

        # render
                
        # check if we have internet exploder
        kw['internet_explorer_old'] = False
        user_agent = self.request.headers.get('User-Agent')
        if user_agent:
            is_msie = re.search("MSIE ([0-9]{1,}[\.0-9]{0,})", user_agent);
            logging.debug("Browser User-Agent: %s" % user_agent)
    
            if is_msie:
                msie_str = is_msie.group()
                version_str = re.search("([0-9]{1,}[\.0-9]{0,})", msie_str)
    
                if version_str:
                    version = float(version_str.group())
                    if version < 9:
                        kw['internet_explorer_old'] = True
                        
                        #self.response.write(self.jinja2.render_template('internet_explorer.html', **kw))
                        site_counter = db.get_site_counter()
                        site_counter.internet_explorer_hits += 1
                        site_counter.put_async()
                else:
                    logging.error("Unable to parse version string for Internet Explorer: %s" % is_msie.group())
                    
        else:
            logging.error("Unable to parse empty user agent")
        
        self.response.write(self.jinja2.render_template(filename, **kw))
        
        self.log_entry()