| Line | |
|---|
| 1 | from datetime import datetime |
|---|
| 2 | |
|---|
| 3 | |
|---|
| 4 | class Link(object): |
|---|
| 5 | |
|---|
| 6 | def __init__(self, username, url, title): |
|---|
| 7 | self.username = username |
|---|
| 8 | self.url = url |
|---|
| 9 | self.title = title |
|---|
| 10 | self.time = datetime.utcnow() |
|---|
| 11 | self.id = hex(hash(tuple([username, url, title, self.time])))[2:] |
|---|
| 12 | self.comments = [] |
|---|
| 13 | |
|---|
| 14 | def __repr__(self): |
|---|
| 15 | return '<%s %r>' % (type(self).__name__, self.title) |
|---|
| 16 | |
|---|
| 17 | def add_comment(self, username, content): |
|---|
| 18 | comment = Comment(username, content) |
|---|
| 19 | self.comments.append(comment) |
|---|
| 20 | return comment |
|---|
| 21 | |
|---|
| 22 | |
|---|
| 23 | class Comment(object): |
|---|
| 24 | |
|---|
| 25 | def __init__(self, username, content): |
|---|
| 26 | self.username = username |
|---|
| 27 | self.content = content |
|---|
| 28 | self.time = datetime.utcnow() |
|---|
| 29 | |
|---|
| 30 | def __repr__(self): |
|---|
| 31 | return '<%s by %r>' % (type(self).__name__, self.username) |
|---|
Note: See
TracBrowser
for help on using the repository browser.