Exemple #1
0
    def get_json(self, tilds):
        context = { }

        try:
            n = models.get_current_tild(tilds)

            results = []

            if n:
                # RESULTS
                if n.ancestor:
                    m = n.ancestor.get()
                    results.append((m, 0))
                    results.extend([(c, 1) for c in m.children() if not n.key == c.key])

                results.append((n, 1))
                results.extend([(c, 2) for c in n.children()])

                results = [n.to_calendar_node(level=l) for (n, l) in results]

                # UNTIL DATE PLACEHOLDER
                # results.append({
                #     'start'         : results[0]['start'],
                #     'end'           : None,
                #     'group'         : None,
                #     'content'       : None,
                #     'className'     : None
                # })

                # BOUNDARIES
                # diff = max((n.end - n.start) / 10, timedelta(days=1))

                # context.update({
                #     'min'       : tools.to_json_date(n.start - diff),
                #     'max'       : tools.to_json_date(n.end + diff)
                # })

            from gviz_api import DataTable

            table = DataTable({
                'start'     : ('date', 'Start'),
                'end'       : ('date', 'End'),
                'content'   : ('string', 'Content'),
                'group'     : ('string', 'Group'),
                'className' : ('string', 'Class')
            })

            table.LoadData(results)

            context['data'] = table.ToJSon()

        except Exception as e:
            context['error'] = str(e)

        finally:
            tools.json_response(self, context)
Exemple #2
0
    def get_json(self, id):
        context = { }

        try:
            tilds_list = models.derive_tilds(id)

            context['tilds'] = tilds_list

        except Exception as e:
            context['error'] = str(e)

        finally:
            tools.json_response(self, context)
Exemple #3
0
    def get(self, rev_id):
        context = { }

        try:
            timestamp = self.request.get('timestamp')
            
            context['content'] = views_page.render(rev_id, timestamp)

        except Exception as e:
            context['error'] = str(e)

        finally:
            if self.request.get('print'):
                self.response.write(context[self.request.get('print')])

            else:
                tools.json_response(self, context)
Exemple #4
0
    def get_json(self, tilds):
        context = { }

        try:
            date = models.get_current_date(tilds)

            context = {
                'tilds'         : tilds,
                'timestamp'     : tools.to_timestamp(date) or '',
                'timestamp_v'   : tools.to_verbose(d=date) or ''
            }

        except Exception as e:
            context['error'] = str(e)

        finally:
            tools.json_response(self, context)
Exemple #5
0
    def get(self, terms=None, tilds=None):
        context = { }

        try:
            timestamp = self.request.get('timestamp')

            state = init_state(terms, tilds, timestamp)

            results = views_page.search(**state)
            result = None if not len(results) == 1 else results[0]

            if result and result.get('rev_id'):
                state['terms_v'] = result['page_title']

                state_title = 'Page: '
                state['content'] = views_page.render(result['rev_id'], timestamp),
                state['render_url'] = uri_for('Render', rev_id=result['rev_id'], timestamp=timestamp or '')

            elif result:
                state_title = 'Page Missing: '
                state['content'] = tools.render_to_string('page_non_existent.html', dict({'result' : result}, **state))

            elif terms:
                state_title = 'Results: '
                state['content'] = tools.render_to_string('page_results.html', dict({'results' : results}, **state))

            else:
                state_title = 'Home'
                state['content'] = tools.render_to_string('page_empty.html')

            context.update({
                'state'         : state,
                'state_title'   : 'Tilde - ' + state_title + str(state['terms_v']) + str(state['tilds_v']),
                'state_url'     : uri_for('Base', terms=state['terms_v'] or '', tilds=state['tilds_v'])
            })

        except Exception as e:
            context['error'] = str(e)

        finally:
            if self.request.get('print'):
                self.response.write(context['state'][self.request.get('print')])

            else:
                tools.json_response(self, context)
Exemple #6
0
    def get_json(self, tilds):
        tilds_list = models.get_next_tilds(tilds)

        context = map(lambda t: {'name' : t.verbose()}, tilds_list)

        tools.json_response(self, context)
Exemple #7
0
    def get_json(self, terms):
        terms_list = views_page.pages(terms)

        context = map(lambda (t, _): {'name' : t}, terms_list)

        tools.json_response(self, context)