Exemplo n.º 1
0
    def render_listing(self, dataset):
        storedir = self.config.marv.storedir
        setdir = os.path.join(storedir, str(dataset.setid))
        store = Store(storedir, self.nodes)
        funcs = make_funcs(dataset, setdir, store)

        values = []
        for col, functree in self.listing_functions:
            value = calltree(functree, funcs)
            transform = FORMATTER_MAP[col.formatter +
                                      ('[]' if col.islist else '')]
            value = transform(value)
            values.append(value)
        row = {
            'id': dataset.id,
            'setid': str(dataset.setid),
            'tags': ['#TAGS#'],
            'values': values
        }

        fields = {}
        relfields = {}
        relations = self.model.relations
        for filter_spec, functree in self.filter_functions:
            value = calltree(functree, funcs)
            transform = FILTER_MAP[filter_spec.value_type]
            value = transform(value)
            target = relfields if filter_spec.name in relations else fields
            target[filter_spec.name] = value

        return row, fields, relfields
Exemplo n.º 2
0
    def render_detail(self, dataset):
        storedir = self.config.marv.storedir
        setdir = os.path.join(storedir, str(dataset.setid))
        try:
            os.mkdir(setdir)
        except OSError:
            pass
        assert os.path.isdir(setdir), setdir
        store = Store(storedir, self.nodes)
        funcs = make_funcs(dataset, setdir, store)

        summary_widgets = [
            x[0]._reader for x in  # pylint: disable=protected-access
            [
                store.load(setdir, node, default=None)
                for node in self.detail_summary_widgets
            ] if x
        ]

        sections = [
            x[0]._reader for x in  # pylint: disable=protected-access
            [
                store.load(setdir, node, default=None)
                for node in self.detail_sections
            ] if x
        ]

        dct = {
            'title': calltree(self.detail_title, funcs),
            'sections': sections,
            'summary': {
                'widgets': summary_widgets
            }
        }
        detail = Detail.new_message(**dct).as_reader()
        dct = detail_to_dict(detail)
        fd = os.open(os.path.join(setdir, '.detail.json'),
                     os.O_CREAT | os.O_EXCL | os.O_WRONLY, 0o666)
        jsonfile = os.fdopen(fd, 'w')
        json.dump(dct, jsonfile, sort_keys=True)
        jsonfile.close()
        os.rename(os.path.join(setdir, '.detail.json'),
                  os.path.join(setdir, 'detail.json'))
        self._check_outdated(dataset)