Skip to content

Commit

Permalink
Cleaned up the attribute_map and added a rule for cleaning date attri…
Browse files Browse the repository at this point in the history
…butes.
  • Loading branch information
thomasw committed Apr 24, 2010
1 parent 211d0a4 commit 7b2087f
Showing 1 changed file with 13 additions and 3 deletions.
16 changes: 13 additions & 3 deletions pyposterous/models.py
@@ -1,5 +1,5 @@
from pyposterous.error import PyposterousError
from pyposterous.utils import bool_string
from pyposterous.utils import parse_date

class PosterousData(object):
def __init__(self, api):
Expand All @@ -16,6 +16,14 @@ def get_tags(self):
return self.api.get_tags(hostname=self.hostname)
except TypeError:
raise PyposterousError('No ID or hostname has been specified for this site object.')

def read_posts(self):
"""Returns a list of posts for this site using self.id."""
return self.api.read_posts(self.id)

def new_post(self, media=None, title=None, body=None, autopost=None, private=None, date=None, tags=None, source=None, sourceLink=None):
"""Posts a new blog post to this site using self.id"""
return self.api.new_post(self.id, media, title, body, autopost, private, date, tags, source, sourcelink)

class Post(PosterousData):
def update_post(self, media=None):
Expand Down Expand Up @@ -59,5 +67,7 @@ class Media(PosterousData):
# the value
attribute_map = {
('id', 'views', 'filesize', 'height', 'width', 'commentscount', 'num_posts',):int,
('private', 'commentsenabled', 'primary'):bool_string,
('body',):lambda x: x.strip()} # Hopefully whitespace will not be significant.
('private', 'commentsenabled', 'primary'):lambda x: x.upper() == 'TRUE',
('body',):lambda x: x.strip(), # Hopefully whitespace will not be significant.
('date',):lambda x: parse_date(x),}

0 comments on commit 7b2087f

Please sign in to comment.