Пример #1
0
class BaseSavedExportSchema(Document):
    # signature: filter(doc)
    filter_function = SerializableFunctionProperty()

    @property
    def default_format(self):
        return Format.XLS_2007

    def transform(self, doc):
        return doc

    @property
    def filter(self):
        return self.filter_function

    @property
    def is_bulk(self):
        return False

    @property
    def table_name(self):
        if len(self.index) > 2:
            return self.index[2]
        else:
            return "Form"

    def parse_headers(self, headers):
        return headers

    def parse_tables(self, tables):
        """
        :param tables: [('table_name', [rows...])]
        """
        first_row = tables[0][1]
        return [(self.table_name, first_row)]
Пример #2
0
class BaseSavedExportSchema(Document):
    # signature: filter(doc)
    filter_function = SerializableFunctionProperty()

    @property
    def default_format(self):
        return Format.XLS_2007

    def transform(self, doc):
        return doc

    @property
    def filter(self):
        return self.filter_function

    @property
    def is_bulk(self):
        return False

    def get_download_task(self, format=None, **kwargs):
        format = format or self.default_format
        download = DownloadBase()
        download.set_task(couchexport.tasks.export_async.delay(
            self,
            download.download_id,
            format=format,
            **kwargs
        ))
        return download

    def export_data_async(self, format=None, **kwargs):
        download = self.get_download_task(format=format, **kwargs)
        return download.get_start_response()

    @property
    def table_name(self):
        if len(self.index) > 2:
            return self.index[2]
        else:
            return "Form"

    def parse_headers(self, headers):
        return headers

    def parse_tables(self, tables):
        """
        :param tables: [('table_name', [rows...])]
        """
        first_row = tables[0][1]
        return [(self.table_name, first_row)]
Пример #3
0
class ExportColumn(DocumentSchema):
    """
    A column configuration, for export
    """
    index = StringProperty()
    display = StringProperty()
    # signature: transform(val, doc) -> val
    transform = SerializableFunctionProperty(default=None)
    tag = StringProperty()
    is_sensitive = BooleanProperty(default=False)
    show = BooleanProperty(default=False)

    @classmethod
    def wrap(self, data):
        if 'is_sensitive' not in data and data.get('transform', None):
            data['is_sensitive'] = True

        if 'doc_type' in data and \
           self.__name__ == ExportColumn.__name__ and \
           self.__name__ != data['doc_type']:
            if data['doc_type'] in column_types:
                return column_types[data['doc_type']].wrap(data)
            else:
                raise ResourceNotFound('Unknown column type: %s', data)
        else:
            return super(ExportColumn, self).wrap(data)

    def get_display(self):
        return u'{primary}{extra}'.format(
            primary=self.display,
            extra=" [sensitive]" if self.is_sensitive else ''
        )

    def to_config_format(self, selected=True):
        return {
            "index": self.index,
            "display": self.display,
            "transform": self.transform.dumps() if self.transform else None,
            "is_sensitive": self.is_sensitive,
            "selected": selected,
            "tag": self.tag,
            "show": self.show,
            "doc_type": self.doc_type,
            "options": [],
            "allOptions": None,
        }