From 5e63d4d1fc37d2bcddbd86a8f88897d1d7883f1a Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Odin=20H=C3=B8rthe=20Omdal?= <odinho@opera.com>
Date: Mon, 11 Aug 2014 23:52:23 +0200
Subject: [PATCH] Add __repr__ for Collection and CollectionItem
---
mediagoblin/db/models.py | 20 +++++++++++++++++---
1 file changed, 17 insertions(+), 3 deletions(-)
diff --git a/mediagoblin/db/models.py b/mediagoblin/db/models.py
index 932ba07..a07d676 100644
a
|
b
|
TODO: indexes on foreignkeys, where useful.
|
20 | 20 | |
21 | 21 | import logging |
22 | 22 | import datetime |
23 | | import base64 |
24 | 23 | |
25 | 24 | from sqlalchemy import Column, Integer, Unicode, UnicodeText, DateTime, \ |
26 | 25 | Boolean, ForeignKey, UniqueConstraint, PrimaryKeyConstraint, \ |
… |
… |
class MediaComment(Base, MediaCommentMixin):
|
683 | 682 | # Validate inReplyTo has ID |
684 | 683 | if "id" not in data["inReplyTo"]: |
685 | 684 | return False |
686 | | |
| 685 | |
687 | 686 | # Validate that the ID is correct |
688 | 687 | try: |
689 | 688 | media_id = int(data["inReplyTo"]["id"]) |
690 | 689 | except ValueError: |
691 | 690 | return False |
692 | | |
| 691 | |
693 | 692 | media = MediaEntry.query.filter_by(id=media_id).first() |
694 | 693 | if media is None: |
695 | 694 | return False |
… |
… |
class Collection(Base, CollectionMixin):
|
734 | 733 | return CollectionItem.query.filter_by( |
735 | 734 | collection=self.id).order_by(order_col) |
736 | 735 | |
| 736 | def __repr__(self): |
| 737 | safe_title = self.title.encode('ascii', 'replace') |
| 738 | return (u'<{classname} #{id}: {title} by {creator}>').format( |
| 739 | id=self.id, |
| 740 | classname=self.__class__.__name__, |
| 741 | creator=self.creator, |
| 742 | title=safe_title) |
| 743 | |
737 | 744 | |
738 | 745 | class CollectionItem(Base, CollectionItemMixin): |
739 | 746 | __tablename__ = "core__collection_items" |
… |
… |
class CollectionItem(Base, CollectionItemMixin):
|
763 | 770 | """A dict like view on this object""" |
764 | 771 | return DictReadAttrProxy(self) |
765 | 772 | |
| 773 | def __repr__(self): |
| 774 | return '<{classname} #{id}: Entry {entry} in {collection}>'.format( |
| 775 | id=self.id, |
| 776 | classname=self.__class__.__name__, |
| 777 | collection=self.collection, |
| 778 | entry=self.media_entry) |
| 779 | |
766 | 780 | |
767 | 781 | class ProcessingMetaData(Base): |
768 | 782 | __tablename__ = 'core__processing_metadata' |