Skip to content

Commit

Permalink
Add __repr__ for Collection and CollectionItem
Browse files Browse the repository at this point in the history
  • Loading branch information
odinho committed Sep 1, 2014
1 parent 6907027 commit c809d88
Showing 1 changed file with 15 additions and 1 deletion.
16 changes: 15 additions & 1 deletion mediagoblin/db/models.py
Expand Up @@ -20,7 +20,6 @@

import logging
import datetime
import base64

from sqlalchemy import Column, Integer, Unicode, UnicodeText, DateTime, \
Boolean, ForeignKey, UniqueConstraint, PrimaryKeyConstraint, \
Expand Down Expand Up @@ -727,6 +726,14 @@ def get_collection_items(self, ascending=False):
return CollectionItem.query.filter_by(
collection=self.id).order_by(order_col)

def __repr__(self):
safe_title = self.title.encode('ascii', 'replace')
return (u'<{classname} #{id}: {title} by {creator}>').format(
id=self.id,
classname=self.__class__.__name__,
creator=self.creator,
title=safe_title)


class CollectionItem(Base, CollectionItemMixin):
__tablename__ = "core__collection_items"
Expand Down Expand Up @@ -756,6 +763,13 @@ def dict_view(self):
"""A dict like view on this object"""
return DictReadAttrProxy(self)

def __repr__(self):
return '<{classname} #{id}: Entry {entry} in {collection}>'.format(
id=self.id,
classname=self.__class__.__name__,
collection=self.collection,
entry=self.media_entry)


class ProcessingMetaData(Base):
__tablename__ = 'core__processing_metadata'
Expand Down

0 comments on commit c809d88

Please sign in to comment.