Ejemplo n.º 1
0
 def to_dict(self, admin=False):
     base_url = '{}/galleries/{}'.format(config.AWS_IMAGES_BASE, self.uuid)
     gallery_categories = GalleryCategory.get_list(gallery_uuid=self.uuid, to_json=True)
     attr_dict = BaseModelObject.to_dict(self)
     attr_dict.update({'cover_photo_url': '{}/{}'.format(base_url, self.cover_photo),
                       'base_url': base_url,
                       'url_title': self.latest_url_title(),
                       'description': self.description(),
                       'created_ago': relative_time(self.created_at),
                       'published_at_raw': format_date(self.published_at, format='%Y-%m-%dT%H:%M:%S') if self.published_at else '',
                       'published_ago': relative_time(self.published_at) if self.published_at else '',
                       'gallery_categories': gallery_categories,
                       'items': GalleryItem.get_items(gallery_uuid=self.uuid, sort_by='position', desc=False, to_json=True, admin=admin),
                       'prev': Gallery.prev(self, attrs=['uuid', 'url_title'], sort_by='published_at', published=True, desc=False),
                       'next': Gallery.next(self, attrs=['uuid', 'url_title'], sort_by='published_at', published=True, desc=False)})
     return attr_dict
Ejemplo n.º 2
0
 def to_dict(self):
     items = [item.to_dict() for item in get_list(GalleryItem, gallery_uuid=self.uuid)]
     items.sort(key=lambda x: x['position'])
     data = {'uuid': self.uuid,
             'name': self.name,
             'author': self.author,
             'cover_photo': self.cover_photo,
             'created_ago': relative_time(self.created_at),
             'created_at': format_date(self.created_at, format='%B %d, %Y'),
             'published_ago': relative_time(self.published_at) if self.published_at else '',
             'published': self.published,
             'items': items,
             'next_uuid': next_uuid(Gallery, self, sort_by='created_at', published=True),
             'prev_uuid': prev_uuid(Gallery, self, sort_by='created_at', published=True),
             }
     return data
Ejemplo n.º 3
0
 def to_dict(self, admin=False):
     attr_dict = BaseModelObject.to_dict(self)
     base_url = '{}/galleries/{}'.format(config.AWS_IMAGES_BASE, self.uuid)
     gallery_categories = GalleryCategory.get_list(gallery_uuid=self.uuid, to_json=True)
     gallery_dict = {'cover_photo_url': '{}/{}'.format(base_url, self.cover_photo),
                     'base_url': base_url,
                     'url_title': self.latest_url_title(),
                     'description': self.description(),
                     'created_ago': relative_time(self.created_at),
                     'published_at_raw': format_date(self.published_at, format='%Y-%m-%dT%H:%M:%S'),
                     'published_ago': relative_time(self.published_at) if self.published_at else '',
                     'gallery_categories': gallery_categories,
                     'items': [item.to_dict() for item in self.items(admin=admin)],
                     'prev': Gallery.prev(self, attrs=['uuid', 'url_title'], sort_by='published_at',
                                          published=True, desc=False),
                     'next': Gallery.next(self, attrs=['uuid', 'url_title'], sort_by='published_at',
                                          published=True, desc=False)}
     attr_dict.update(gallery_dict)
     return attr_dict
Ejemplo n.º 4
0
 def to_dict(self):
     # get images
     images = AsanaImage.get_asana_images(self.uuid)
     # get attributes
     attributes = AsanaAttribute.get_asana_attributes(self.uuid)
     print self.created_at
     data = {'uuid': self.uuid,
             'name': self.name,
             'created_ago': relative_time(self.created_at),
             'created_at': format_date(self.created_at, format='%B %d, %Y'),
             'image_url': get(AsanaImage, asana_uuid=self.uuid, primary_image=True).image_url,
             'images': images,
             'description': get(AsanaAttribute, asana_uuid=self.uuid, name='description').value,
             'attributes': attributes
             }
     return data
Ejemplo n.º 5
0
def process_fb_comment(comment, post_link, graph):
    fb_dict = {}
    fb_dict['id'] = comment.get('id')
    fb_dict['name'] = comment.get('from').get('name')
    fb_dict['screen_name'] = comment.get('from').get('name')
    fb_dict['user'] = comment.get('from')
    fb_dict['author'] = comment.get('from')
    fb_dict['user_url'] = 'https://www.facebook.com/{}'.format(comment.get('from').get('id'))
    fb_dict['entities'] = []
    fb_dict['created_time'] = comment.get('created_time')
    created_time = datetime.datetime.strptime(comment.get('created_time').split('+')[0], '%Y-%m-%dT%H:%M:%S')
    fb_dict['created_at'] = relative_time(created_time)
    fb_dict['link'] = post_link
    fb_dict['text'] = add_target_blank(urlize(comment.get('message')))
    fb_dict['source'] = 'facebook'

    user = graph.request('{}/picture'.format(comment.get('from').get('id')))
    fb_dict['profile_image'] = user.get('url')
    return fb_dict
Ejemplo n.º 6
0
def process_tweet(tweet):
    '''
    Return dict of items we actually need from the tweet.
    '''
    tweet_dict = {}
    tweet_dict['id'] = tweet.id
    tweet_dict['entity_uuid'] = tweet.entity_uuid
    tweet_dict['profile_image'] = tweet.user._json.get('profile_image_url_https')
    tweet_dict['name'] = tweet.author._json.get('name')
    tweet_dict['screen_name'] = tweet.author._json.get('screen_name')
    tweet_dict['user_url'] = 'https://www.twitter.com/{}'.format(tweet.author.screen_name)
    tweet_dict['entities'] = tweet.entities
    tweet_dict['created_time'] = datetime.datetime.strftime(tweet.created_at, '%Y-%m-%dT%H:%M:%S')
    tweet_dict['created_at'] = relative_time(tweet.created_at)
    link = "https://www.twitter.com/{}/status/{}".format(tweet.author._json.get('screen_name'), tweet.id)
    tweet_dict['link'] = link
    tweet_dict['text'] = tweet.text
    tweet_dict['in_reply_to_status_id'] = tweet.in_reply_to_status_id
    tweet_dict['source'] = 'twitter'
    return tweet_dict
Ejemplo n.º 7
0
def process_fb_comment(comment, post_link, graph):
    fb_dict = {}
    fb_dict['id'] = comment.get('id')
    fb_dict['name'] = comment.get('from').get('name')
    fb_dict['screen_name'] = comment.get('from').get('name')
    fb_dict['user'] = comment.get('from')
    fb_dict['author'] = comment.get('from')
    fb_dict['user_url'] = 'https://www.facebook.com/{}'.format(
        comment.get('from').get('id'))
    fb_dict['entities'] = []
    fb_dict['created_time'] = comment.get('created_time')
    created_time = datetime.datetime.strptime(
        comment.get('created_time').split('+')[0], '%Y-%m-%dT%H:%M:%S')
    fb_dict['created_at'] = relative_time(created_time)
    fb_dict['link'] = post_link
    fb_dict['text'] = add_target_blank(urlize(comment.get('message')))
    fb_dict['source'] = 'facebook'

    user = graph.request('{}/picture'.format(comment.get('from').get('id')))
    fb_dict['profile_image'] = user.get('url')
    return fb_dict
Ejemplo n.º 8
0
def process_tweet(tweet):
    '''
    Return dict of items we actually need from the tweet.
    '''
    tweet_dict = {}
    tweet_dict['id'] = tweet.id
    tweet_dict['entity_uuid'] = tweet.entity_uuid
    tweet_dict['profile_image'] = tweet.user._json.get(
        'profile_image_url_https')
    tweet_dict['name'] = tweet.author._json.get('name')
    tweet_dict['screen_name'] = tweet.author._json.get('screen_name')
    tweet_dict['user_url'] = 'https://www.twitter.com/{}'.format(
        tweet.author.screen_name)
    tweet_dict['entities'] = tweet.entities
    tweet_dict['created_time'] = datetime.datetime.strftime(
        tweet.created_at, '%Y-%m-%dT%H:%M:%S')
    tweet_dict['created_at'] = relative_time(tweet.created_at)
    link = "https://www.twitter.com/{}/status/{}".format(
        tweet.author._json.get('screen_name'), tweet.id)
    tweet_dict['link'] = link
    tweet_dict['text'] = tweet.text
    tweet_dict['in_reply_to_status_id'] = tweet.in_reply_to_status_id
    tweet_dict['source'] = 'twitter'
    return tweet_dict
Ejemplo n.º 9
0
 def to_dict(self, admin=False):
     attr_dict = BaseModelObject.to_dict(self)
     attr_dict.update({'author_email': self.author_name(),
                       'created_ago': relative_time(self.created_at)})
     return attr_dict