Ejemplo n.º 1
0
def process_request(request, current_tab, template):
    """Process the request, update the context."""
    # TODO: the below can better be done by the wrapper @login_required and
    # setting the login_url (in settings, I believe), if it's not already done
    #if not request.user.is_authenticated():
    #    return redirect('%saccounts/login/' % settings.HOME_ROOT)

    logging.info("Requesting Page tab: '%s'" % current_tab)

    # TODO: this is ugly, there's a reverse_url function in django which
    # takes a name and optional arguments and returns the url. This is
    # better because if you would change your urls, nothing breaks.

    #urls for requesting data for main chart
    viz_data_url = '%s%s' % (settings.HOME_ROOT, 'ui/viz_data/')
    #urls for requesting data for filters
    filter_data_url = '%s%s' % (settings.HOME_ROOT, 'ui/filter_data/')
    #urls for requesting data for video list
    video_data_url = '%s%s' % (settings.HOME_ROOT, 'ui/video_data/')
    #urls for requesting data for user query management
    user_query_url = '%s%s' % (settings.HOME_ROOT, 'ui/user_query_data/')
    #urls for requesting data for report
    user_report = '%s%s' % (settings.HOME_ROOT, 'ui/user_report/')
    user_report_file = '%s%s' % (settings.HOME_ROOT, 'ui/user_report_file/')

    home_url = '%s%s' % (settings.HOME_ROOT, 'ui/home/')

    #update context
    c = {
        'user': request.user,
        'active_tab': current_tab,
        'active': {current_tab: 'active'},
        'viz_data_url': viz_data_url,
        'filter_data_url': filter_data_url,
        'video_data_url': video_data_url,
        'user_query_url': user_query_url,
        'user_report': user_report,
        'user_report_file': user_report_file,
        'home_url': home_url,
        }

    parameters = VisualizationParameters(request, species_names)
    c.update(parameters.status())
    c.update(video_class_names)

    c.update(csrf(request))
    response = render_to_response(template, c, context_instance=RequestContext(request))
    return response
Ejemplo n.º 2
0
    def process_request(self, request):
        parameters = VisualizationParameters(request, self.species_names)
        #? Change into: parameters = VisualizationParameters(request)
        logging.info("Requesting Chart - data: %s" % parameters)

        data = None
        t = parameters.t().lower()
        z = parameters.z().lower()
        if t == 's':
            data = self.simple(parameters)
        elif t == 't':
            if z == "c":
                data = self.stacked_cameras(parameters)
            if z == "d":
                data = self.stacked_days(parameters)
            if z == "h":
                data = self.stacked_hours(parameters)
            if z == "mood":
                data = self.stacked_moods(parameters)
            if z == "gen":
                data = self.stacked_genders(parameters)
            if z == "age":
                data = self.stacked_ages(parameters)
            if z == "hap":
                data = self.stacked_happys(parameters)
            if z == "dis":
                data = self.stacked_disgusteds(parameters)
            if z == "ang":
                data = self.stacked_angrys(parameters)
            if z == "sur":
                data = self.stacked_surpriseds(parameters)
            if z == "afr":
                data = self.stacked_afraids(parameters)
            if z == "sad":
                data = self.stacked_sads(parameters)
            
        if data is None:
            logging.warning('Dimensions t: %s, z: %s is NOT implemented.' % (t, z))

        logging.debug("Response Chart - computed.")
        return {'viz': data}
Ejemplo n.º 3
0
    def process_request(self, request):
        parameters = VisualizationParameters(request, self.species_names)
        
        logging.info("Requesting Filters - data: %s" % parameters)

        response = {}
        if 'f_c' in parameters.opened_filters():
            response['f_c'] = self.filter_cameras(parameters)
        if 'f_d' in parameters.opened_filters():
            response['f_d'] = self.filter_time('d', parameters.filter_days(), parameters)
        if 'f_h' in parameters.opened_filters():
            response['f_h'] = self.filter_time('h', parameters.filter_hours(), parameters)
        if 'f_mood' in parameters.opened_filters():
            response['f_mood'] = self.filter_moods(parameters)
        if 'f_gen' in parameters.opened_filters():
            response['f_gen'] = self.filter_genders(parameters)
        if 'f_age' in parameters.opened_filters():
            response['f_age'] = self.filter_ages(parameters)
        if 'f_hap' in parameters.opened_filters():
            response['f_hap'] = self.filter_happys(parameters)
        if 'f_dis' in parameters.opened_filters():
            response['f_dis'] = self.filter_disgusteds(parameters)
        if 'f_ang' in parameters.opened_filters():
            response['f_ang'] = self.filter_angrys(parameters)
        if 'f_sur' in parameters.opened_filters():
            response['f_sur'] = self.filter_surpriseds(parameters)
        if 'f_afr' in parameters.opened_filters():
            response['f_afr'] = self.filter_afraids(parameters)
        if 'f_sad' in parameters.opened_filters():
            response['f_sad'] = self.filter_sads(parameters)

        logging.debug("Response Filters - computed.")
        return response