def get_public(self, feed_id=False, feed_type="combined-feed", start=0, stop=50): if True: order_type = 'user' if order_type == "user": order_type = storage.get_feed_setting(feed_id, 'ordering') if not order_type: storage.set_feed_setting(feed_id, 'ordering', 'unreaded') order_type = 'unreaded' else: order_type = order_type['value'] # Get stories if not feed_id: if feed_type == "combined-feed": stories = storage.all_stories(order_type, start, stop) elif feed_type == "stared-feed": stories = storage.all_stared(order_type, start, stop) else: raise Exception('Unknown feed type (%s)' % feed_type) else: stories = storage.get_stories(feed_id, order_type, start, stop) #length = storage.get_feed_unread_count(feed_id) length = 1 res = [] for story in stories: story.pop('read') story['last_update'] = get_dicttime(story['last_update']) story['published'] = get_dicttime(story['published']) res.append(story) return {'entries': res, 'detail': {'start': start, 'stop': stop, 'length': length}}
def unread(self, story_id): story = storage.get_story_by_id(story_id) if not story['read']: story['published'] = get_dicttime(story['published']) story['last_update'] = get_dicttime(story['last_update']) return {'success': False, 'output': 'Story already unreaded'} story['read'] = False storage.update_story(story['_id'], copy.copy(story)) story['published'] = get_dicttime(story['published']) story['last_update'] = get_dicttime(story['last_update']) return {'success': True, 'content': story}
def read_public(self, story_id): """ Return story content, do not set it at read state and give previous read state for counter """ story = storage.get_story_by_id(story_id) story['read'] = False story.pop('read') # Save read state before update it for javascript counter in UI #storage.update_story(story['_id'], copy.copy(story)) copy.copy(story) story['published'] = get_dicttime(story['published']) story['last_update'] = get_dicttime(story['last_update']) return {'success': True, 'content': story}
def read(self, story_id): """ Return story content, set it at readed state and give previous read state for counter """ story = storage.get_story_by_id(story_id) if story['read']: story['published'] = get_dicttime(story['published']) story['last_update'] = get_dicttime(story['last_update']) return {'success': False, 'output': 'Story already readed', 'content': story} # Save read state before update it for javascript counter in UI story['read'] = True storage.update_story(story['_id'], copy.copy(story)) story['published'] = get_dicttime(story['published']) story['last_update'] = get_dicttime(story['last_update']) return {'success': True, 'content': story}