def serialize(self):
        data = ControlBase.serialize(self)
        items = []
        for key, value in self._items.items():
            items.append({
                'text': str(key),
                'value': str(value),
                'name': str(key)
            })

        #value = str(self._value) if self._value is not None else None
        if isinstance(self._value, list) and len(self._value) > 0:
            value = list(map(str, sorted(self._value)))
        else:
            value = None

        data.update({
            'items': items,
            'value': value,
            'mode': self.mode,
            'update_items': self._update_items
        })

        self._update_items = False
        return data
Example #2
0
	def serialize(self):
		data  = ControlBase.serialize(self)
		data.update({ 
			'legend': 	self.legend, 
			'value': 	self._value 
		})
		return data
Example #3
0
	def serialize(self):
		data = ControlBase.serialize(self)
		items = []
		for key, value in self.queryset:
			items.append({'label': key, 'value': value }) 
		data.update({ 'items': items, 'value': self._value })
		return data
    def serialize(self):
        data = ControlBase.serialize(self)

        items = []
        for row in (self.queryset if self.queryset else []):
            items.append({
                'text': str(row),
                'value': str(row.pk),
                'name': str(row)
            })

        if self.value:
            value = list(sorted(map(str, self.value)))
        else:
            value = None

        data.update({
            'items': items,
            'value': value,
            'mode': self.mode,
            'update_items': self._update_items
        })

        self._update_items = False
        return data
Example #5
0
    def serialize(self):
        data = ControlBase.serialize(self)

        data.update({
            'headers':        self.headers,
            'selected_index': self._selected_index,
        })
        return data
Example #6
0
 def serialize(self):
     data = ControlBase.serialize(self)
     if isinstance(self.value, BaseWidget):
         data.update({'value': self.value.uid})
         self.value.parent = self.parent.uid
     else:
         data.update({'value': None})
     return data
Example #7
0
    def serialize(self):
        data = ControlBase.serialize(self)

        data.update({
            'horizontal_headers': self.horizontal_headers,
            'read_only': 1 if self._read_only else 0,
            'selected_index': self._selected_index,
            'select_entire_row': 1 if self._select_entire_row else 0,
        })
        return data
Example #8
0
 def serialize(self):
     res = ControlBase.serialize(self)
     res.update({
         'clear': self._clear,
         'has_more': self.has_more,
         'mode': self.mode
     })
     self._clear = False
     self.value = []
     return res
Example #9
0
    def serialize(self):
        data = ControlBase.serialize(self)
        queryset = self.value

        rows = []
        filters_list = []
        headers = []

        if queryset:
            model = queryset.model

            row_start = self.rows_per_page * (self._current_page - 1)
            row_end = self.rows_per_page * (self._current_page)

            for sort in self.sort_by:
                direction = '-' if sort['desc'] else ''
                queryset = queryset.order_by(direction + sort['column'])

            rows = self.queryset_to_list(queryset, self.list_display,
                                         row_start, row_end)

            if self.list_display:
                #configure the headers titles
                for column_name in self.list_display:
                    headers.append({
                        'label':
                        get_verbose_name(model, column_name),
                        'column':
                        column_name
                    })

            filters_list = self.serialize_filters(self.list_filter, queryset)

        if len(self.search_fields) > 0: data.update({'search_field_key': ''})

        data.update({
            'filters_list': filters_list,
            'filter_by': self.filter_by,
            'sort_by': self.sort_by,
            'pages': {
                'current_page': self._current_page,
                'pages_list': self.__get_pages_2_show(queryset)
            },
            'value': '',
            'values': rows,
            'horizontal_headers': headers,
            'selected_row_id': self._selected_row_id
        })

        if self._selected_row_id:
            data.update({})

        return data
Example #10
0
    def serialize(self):
        data = ControlBase.serialize(self)
        items = []
        for key, value in self._items.items():
            items.append({'text': key, 'value': value, 'name': key})

        value = self._value
        if value == True: value = 'true'
        if value == False: value = 'false'
        if value == None: value = 'null'

        data.update({'items': items, 'value': value})
        return data
Example #11
0
    def serialize(self):
        data = ControlBase.serialize(self)
        items = []

        if self.allow_none:
             items.append({'label': '---', 'value': None})

        for obj in self.queryset:
            if self._column:
                items.append({'label': str(getattr(obj,self._column)), 'value': obj.pk })
            else:
                items.append({'label': str(obj), 'value': obj.pk })

        data.update({ 'items': items, 'value': self._value })
        return data
Example #12
0
    def serialize(self):
        data = ControlBase.serialize(self)
        image = self.value
        if isinstance(image, np.ndarray):
            if len(image.shape) > 2:
                image = cv2.cvtColor(image, cv2.COLOR_BGR2RGB)
            image = Image.fromarray(image)
            buff = StringIO.StringIO()
            image.save(buff, format="PNG")
            content = buff.getvalue()
            buff.close()

            data.update({'base64content': base64.b64encode(content)})
        data.update({'filename': self._filename})
        return data
Example #13
0
    def serialize(self):
        data = ControlBase.serialize(self)

        values = []
        for obj in (self.value if self.value else []):
            pk = obj.pk
            row = self.obj2list(obj) + [obj.pk]
            row[0] = self._checked.get(pk, False)
            values.append(row)

        data.update({
            'value': values,
            'headers': self.headers,
            'selected_index': self._selected_index,
            'add_button': self.add_func is not None,
            'remove_button': self.remove_func is not None
        })
        return data
Example #14
0
    def serialize(self):
        data = ControlBase.serialize(self)

        if self.value:
            data.update({'value': self.value.isoformat()})
        return data
Example #15
0
    def serialize(self, init_form=False):
        data = ControlBase.serialize(self)
        queryset = self.value

        rows = []

        if self._update_list and queryset:
            row_start = self.rows_per_page * (self._current_page - 1)
            row_end = self.rows_per_page * (self._current_page)
            model = queryset.model

            if len(self.sort_by) > 0:
                for sort in self.sort_by:
                    direction = '-' if sort['desc'] else ''
                    queryset = queryset.order_by(direction + sort['column'])

            # if no order by exists add one, to avoid the values to be show randomly in the list
            order_by = list(queryset.query.order_by)
            if 'pk' not in order_by or '-pk' not in order_by:
                order_by.append('-pk')
                queryset = queryset.order_by(*order_by)

            rows = self.queryset_to_list(queryset, self.list_display,
                                         row_start, row_end)

            if init_form:
                filters_list = self.serialize_filters(self.list_filter,
                                                      queryset)
                data.update({'filters_list': filters_list})

        if init_form and self.list_display:
            #configure the headers titles
            headers = []
            for column_name in self.list_display:
                label = get_lookup_verbose_name(queryset.model, column_name)

                headers.append({'label': label, 'column': column_name})
            data.update({
                'horizontal_headers': headers,
            })

        if len(self.search_fields) > 0:
            data.update({
                'search_field_key':
                self.search_field_key
                if self.search_field_key is not None else ''
            })

        total_rows = queryset.count()
        total_n_pages = (total_rows / self.rows_per_page) + (0 if (
            total_rows % self.rows_per_page) == 0 else 1)

        data.update({
            'filter_by': self.filter_by,
            'sort_by': self.sort_by,
            'pages': {
                'current_page': self._current_page,
                'pages_list': self.__get_pages_2_show(queryset)
            },
            'pages_total': total_n_pages,
            'value': '',
            'values': rows,
            'values_total': total_rows,
            'selected_row_id': self._selected_row_id
        })

        return data