def get(self):
        '''
        The class serving the page for the earnings
        '''
        selectable=[j[0] for j in TopJobs]
        selectable.sort(key=lambda x: x.lower())

        # Get the selected selected_jobs
        selected_jobs = self.request.get_all("job")
        selected_jobs = [j for j in selected_jobs if j in selectable]
        log.info("Earnings for selected jobs: " + str(selected_jobs))
        
        
        if len(selected_jobs)>0:
            # Read patterns from database
            earnings_db = Earnings.all()
            earnings1, earnings2 = earnings_db.fetch(2)
            earnings1.expand()
            earnings2.expand()
        else:
            # Read patterns from database
            earnings_db = Earnings.all()
            earnings1 = earnings_db.get()
            earnings1.expand()
        
        #Build top ten
        top_paid=[(int(count), jobs.split(';')) for count, jobs in earnings1.data_expanded[:10]]

        #Build the list of matching patterns    
        matching=None
        searched=False
        if len(selected_jobs)>0:
            searched=True
            # Find out matching patterns
            matching_temp=[]
            for data in earnings1.data_expanded:
                valid=True
                for j in selected_jobs:
                    if not j in data[1]:
                        valid=False;
                        break;
                if valid:
                    matching_temp.append(data)
            #Split and prepare the matching elements
            if len(matching_temp)>0:
                matching=[(int(count), jobs.split(';')) for count, jobs in matching_temp]
                log.info("Found %d matches: %s" %(len(matching),str(matching)))
            else:
                log.info("No matches found...")
                    
        #Generate the page
        template_values = { 'selectable': selectable, 'selected_jobs':selected_jobs, 'matching':matching, 'searched':searched,'top_paid':top_paid}
            
        template = jinja_environment.get_template('templates/earnings.html')
        self.response.out.write(template.render(template_values))
    def get(self):
        '''
        The class serving the page for the earnings
        '''
        selectable = [j[0] for j in TopJobs]
        selectable.sort(key=lambda x: x.lower())

        # Get the selected selected_jobs
        selected_jobs = self.request.get_all("job")
        selected_jobs = [j for j in selected_jobs if j in selectable]
        log.info("Earnings for selected jobs: " + str(selected_jobs))

        if len(selected_jobs) > 0:
            # Read patterns from database
            earnings_db = Earnings.all()
            earnings1, earnings2 = earnings_db.fetch(2)
            earnings1.expand()
            earnings2.expand()
        else:
            # Read patterns from database
            earnings_db = Earnings.all()
            earnings1 = earnings_db.get()
            earnings1.expand()

        #Build top ten
        top_paid = [(int(count), jobs.split(';'))
                    for count, jobs in earnings1.data_expanded[:10]]

        #Build the list of matching patterns
        matching = None
        searched = False
        if len(selected_jobs) > 0:
            searched = True
            # Find out matching patterns
            matching_temp = []
            for data in earnings1.data_expanded:
                valid = True
                for j in selected_jobs:
                    if not j in data[1]:
                        valid = False
                        break
                if valid:
                    matching_temp.append(data)
            #Split and prepare the matching elements
            if len(matching_temp) > 0:
                matching = [(int(count), jobs.split(';'))
                            for count, jobs in matching_temp]
                log.info("Found %d matches: %s" %
                         (len(matching), str(matching)))
            else:
                log.info("No matches found...")

        #Generate the page
        template_values = {
            'selectable': selectable,
            'selected_jobs': selected_jobs,
            'matching': matching,
            'searched': searched,
            'top_paid': top_paid
        }

        template = jinja_environment.get_template('templates/earnings.html')
        self.response.out.write(template.render(template_values))