Esempio n. 1
0
 def set_filters(self, filters):
     """
     Set class filter according to filters dictionnary, almost of the time coming from url parameters.
     """
     for name, value in filters.iteritems():
         if not getattr(self, name + '_option') == FILTER_OFF:
             if type(value) == type(dict()):
                 for sub_name, sub_value in value.iteritems():
                     setattr(self, sub_name, sub_value)
             else:
                 setattr(self, name, value) 
Esempio n. 2
0
    def get_filters(self):
        """
        Create a dictionnary of filters and their values
        """
        filters_ret = {}
        for name, filt in filters.iteritems():
            if not getattr(self, name + '_option') == FILTER_OFF:
                cols = filt.get_col_def()
                if len(cols) > 1:
                    value_dict = {}
                    for col in filt.get_col_def():
                        value_dict[col.name] = getattr(self, col.name) 

                    filters_ret[filt.name] = value_dict 
                else:
                    filters_ret[filt.name] = getattr(self, cols[0].name)

        return filters_ret
Esempio n. 3
0
    def get_filters(self):
        """
        Create a dictionnary of filters and their values
        """
        filters_ret = {}
        for name, filt in filters.iteritems():
            option =  getattr(self, name + '_option')
            if option in [FILTER_SHOW, FILTER_HARD, FILTER_SHOW, FILTER_HIDE]:
                # If it is a hidden filters (linking), we consider it only if it come from an url
                if not option == FILTER_HIDE or name in self.extra_filters:
                    cols = filt.get_col_def()
                    if len(cols) > 1:
                        value_dict = {}
                        for col in filt.get_col_def():
                            value_dict[col.name] = getattr(self, col.name) 

                        filters_ret[filt.name] = value_dict 
                    else:
                        filters_ret[filt.name] = getattr(self, cols[0].name)
        return filters_ret
Esempio n. 4
0
    def set_filters(self, filters):
        """
        Set class filter according to filters dictionnary, almost of the time coming from url parameters.
        """
        self.extra_filters = []
        for name, value in filters.iteritems():
            if not getattr(self, name + '_option') == FILTER_OFF:
                self.extra_filters.append(name)
                if type(value) == type(dict()):
                    for sub_name, sub_value in value.iteritems():
                        setattr(self, sub_name, sub_value)
                else:
                    setattr(self, name, value) 
            
    def update(self, filters):
        if hasattr(filters, '_sa_instance_state'):
            del filters._sa_instance_state 
        for attribute, value in filters.__dict__.iteritems():
            setattr(self, attribute, value)


      
# Dynamically add columns to view_filters table
for name, filt in filters.iteritems():
    setattr(ViewFilters, name + '_option', Column(Enum('off','hard','show','hide'), nullable=False, info={'choices': filter_choices, 'label': filt.title}, default='off'))
    cache_columns[name + '_option'] = []
    for col in filt.get_col_def():
        cache_columns[name + '_option'].append(col.name)
        setattr(ViewFilters, col.name, col)   
Esempio n. 5
0
class ViewGrouperForm(ModelForm, TranslatedFormNoCsrf):
    class Meta:
        model = ViewGrouper

class ViewFiltersForm(ModelForm, TranslatedFormNoCsrf):
    class Meta:
        model = ViewFilters

    def get_filters(self):
        filters = ViewFilters()
        for col, value in self.data.iteritems():
            setattr(filters, col, value)
        return filters

# Override filters form fields if the filter have a custom form field definition
for filt_name, filt_obj in filters.iteritems():
    if hasattr(filt_obj, 'form_def') and filt_obj.form_def:
        cols = filt_obj.get_col_def()
        for col_id in range(0, len(cols)): 
            setattr(ViewFiltersForm, cols[col_id].name, filt_obj.form_def[col_id]) 

class ViewForm(ModelForm, TranslatedForm):
    class Meta:
        model = View

    columns = ModelFieldList(FormField(ViewColumnForm))
    groupers = ModelFieldList(FormField(ViewGrouperForm))
    sorters = ModelFieldList(FormField(ViewSorterForm))
    columns_choices = None 
    links_choices = None
    filters = ModelFormField(ViewFiltersForm)