From 13853488e33741f550d062af19cd41270c97f306 Mon Sep 17 00:00:00 2001 From: Flancian <0@flancia.org> Date: Tue, 22 Dec 2020 01:08:47 +0100 Subject: [PATCH] Some hacks to do push/pull, but enable only back/forward. --- app/agora.py | 18 ++++++++++++--- app/db.py | 41 ++++++++++++++++++++++++++++++---- app/static/css/screen-dark.css | 18 ++++++--------- app/templates/links.html | 28 +++++++++-------------- 4 files changed, 70 insertions(+), 35 deletions(-) diff --git a/app/agora.py b/app/agora.py index 3f9adc8..350322d 100644 --- a/app/agora.py +++ b/app/agora.py @@ -96,14 +96,26 @@ def pull(node): @bp.route('/node/') @bp.route('/wikilink/') # alias for now def wikilink(node): + + try: + n = db.nodes_by_wikilink(node) + except KeyError: + # We'll handle 404 in the template, as we want to show backlinks to non-existent nodes. + pass + + try: + n = n[0] + except IndexError: + pass + return render_template( 'node_rendered.html', wikilink=node, subnodes=db.subnodes_by_wikilink(node), backlinks=db.subnodes_by_outlink(node), - # pushlinks=db.subnodes_by_pushlink(node), - # pulllinks=db.subnodes_by_pulllink(node), - # forwardlinks=db.subnodes_by_outlink(node) + pushlinks=n.push_links() if n else [], + pulllinks=n.pull_links() if n else [], + forwardlinks=n.forward_links() if n else [], ) @bp.route('/subnode/') diff --git a/app/db.py b/app/db.py index 22ea12a..08330d0 100644 --- a/app/db.py +++ b/app/db.py @@ -70,11 +70,29 @@ class Node: def go(self): # There's surely a much better way to do this. Alas :) - go = [] + links = [] for subnode in self.subnodes: - go.extend(subnode.go()) + links.extend(subnode.go()) return go + def forward_links(self): + links = [] + for subnode in self.subnodes: + links.extend(subnode.outlinks) + return sorted(set(links)) + + def pull_links(self): + links = [] + for subnode in self.subnodes: + links.extend(subnode.pull_links()) + return sorted(set(links)) + + def push_links(self): + links = [] + for subnode in self.subnodes: + links.extend(subnode.push_links()) + return sorted(set(links)) + class Subnode: """A subnode is a note or media resource volunteered by a user of the Agora. @@ -129,7 +147,7 @@ class Subnode: sanitized_golinks.append('https://' + golink) return sanitized_golinks - def pull(self): + def pull_links(self): """ returns a set of pull links contained in this subnode pull links are blocks of the form: @@ -138,9 +156,24 @@ class Subnode: # TODO: test. pull_links = subnode_to_actions(self, 'pull') - entities = content_to_outlinks(pull_links) + entities = content_to_outlinks("\n".join(pull_links)) return entities + def push_links(self): + """ + returns a set of push links contained in this subnode + push links are blocks of the form: + - [[push]] [[node]] + + TODO: refactor with the above. + """ + + # TODO: test. + push_links = subnode_to_actions(self, 'push') + entities = content_to_outlinks("\n".join(push_links)) + return entities + + def subnode_to_actions(subnode, action): # hack hack. diff --git a/app/static/css/screen-dark.css b/app/static/css/screen-dark.css index dcebf4c..9d488ec 100644 --- a/app/static/css/screen-dark.css +++ b/app/static/css/screen-dark.css @@ -92,29 +92,25 @@ h2 { font-size: 1.2em; } } .backlinks { - /*background: #1f1f2f; */ float: left; width: 50%; } .pushlinks { - /*background: #1f1f2f; */ width: 20%; background: #161616; color: #cfcfcf; - padding: 0.5em; - margin-bottom: 10px; - border-radius: 10px; } -.pulllinks, .forwardlinks { - /*background: #1f1f2f; */ - background: #161616; +.pulllinks { width: 20%; + background: #161616; color: #cfcfcf; - padding: 0.5em; - margin-bottom: 10px; - border-radius: 10px; +} + +.forwardlinks { + background: #161616; + width: 50%; } .backlinks-header, .pushlinks-header, .pulllinks-header, .forwardlinks-header { diff --git a/app/templates/links.html b/app/templates/links.html index 376bd02..2b9c0ed 100644 --- a/app/templates/links.html +++ b/app/templates/links.html @@ -16,7 +16,6 @@ Links