Mercurial > code > home > repos > href
comparison link.py @ 41:293a694304b8
reformat
author | drewp@bigasterisk.com |
---|---|
date | Sat, 19 Nov 2022 17:18:55 -0800 |
parents | f3a15a724483 |
children |
comparison
equal
deleted
inserted
replaced
40:94181d521d6d | 41:293a694304b8 |
---|---|
1 import urllib.error | |
1 import urllib.parse | 2 import urllib.parse |
2 import urllib.request | 3 import urllib.request |
3 import urllib.parse | 4 |
4 import urllib.error | |
5 from dateutil.tz import tzlocal | 5 from dateutil.tz import tzlocal |
6 | 6 |
7 | 7 |
8 class NotFound(ValueError): | 8 class NotFound(ValueError): |
9 pass | 9 pass |
10 | 10 |
11 | 11 |
12 class Links(object): | 12 class Links(object): |
13 | |
13 def __init__(self, db): | 14 def __init__(self, db): |
14 self.coll = db['links'] | 15 self.coll = db['links'] |
15 | 16 |
16 def insertOrUpdate(self, doc): | 17 def insertOrUpdate(self, doc): |
17 if not doc['href']: | 18 if not doc['href']: |
51 else: | 52 else: |
52 out['displayDescription'] = out['description'] | 53 out['displayDescription'] = out['description'] |
53 | 54 |
54 out['tagWords'] = [{'word': w} for w in out['tag'].split(None)] | 55 out['tagWords'] = [{'word': w} for w in out['tag'].split(None)] |
55 out['domain'] = urllib.parse.urlparse(out['href']).netloc | 56 out['domain'] = urllib.parse.urlparse(out['href']).netloc |
56 out['editLink'] = 'addLink?' + urllib.parse.urlencode( | 57 out['editLink'] = 'addLink?' + urllib.parse.urlencode([('url', out['href'])]) |
57 [('url', out['href'])]) | |
58 out['shareWith'] = [{'label': uri} for uri in doc.get('shareWith', [])] | 58 out['shareWith'] = [{'label': uri} for uri in doc.get('shareWith', [])] |
59 return out | 59 return out |
60 | 60 |
61 def fromPostdata(self, data, user, t): | 61 def fromPostdata(self, data, user, t): |
62 if not user or not data.href: | 62 if not user or not data.href: |