def send_subscription_email(subscription, gallery): description = u'{}...'.format( gallery.description()[:400]) if gallery.description() else '' category = gallery.latest_category() template = env.get_template('subscription_email.txt') body_text = template.render(user_name=subscription.name, blog_url=gallery.url(), cancel_url=subscription.cancel_url(), published_at=format_date(gallery.published_at), category=category, unsubscribe_url=subscription.url()) template = env.get_template('subscription_email.html') body_html = template.render(user_name=subscription.name, blog_url=gallery.url(), gallery_title=gallery.name, subtitle=gallery.subtitle, published_at=format_date(gallery.published_at), author=gallery.author, description=description, category=category, cancel_url=subscription.cancel_url(), unsubscribe_url=subscription.url()) send_email(subscription.email, gallery.name, body_text=body_text, body_html=body_html)
def to_dict(self): attr_dict = copy.deepcopy(self.__dict__) if hasattr(self, 'created_at'): attr_dict['created_at'] = format_date(self.created_at) if attr_dict.get('_sa_instance_state'): del attr_dict['_sa_instance_state'] return attr_dict
def to_dict(self): attr_dict = BaseModelObject.to_dict(self) attr_dict.update({'base_url': '{}/talks/{}'.format(config.AWS_IMAGES_BASE, self.uuid), 'formatted_date': format_date(self.date, format='%B %d, %Y'), 'next': Talk.next(self, attrs=['uuid'], sort_by='date', published=True, desc=False), 'prev': Talk.prev(self, attrs=['uuid'], sort_by='date', published=True, desc=False)}) return attr_dict
def to_dict(self): return {'uuid': self.uuid, 'asana_uuid': self.asana_uuid, 'name': self.name, 'value': self.value, 'created_at': format_date(self.created_at, format='%B %d, %Y') }
def to_dict(self): return {'uuid': self.uuid, 'asana_uuid': self.asana_uuid, 'image_url': self.image_url, 'primary_image': self.primary_image, 'created_at': format_date(self.created_at, format='%B %d, %Y') }
def to_dict(self): attr_dict = copy.deepcopy(self.__dict__) for key, value in attr_dict.items(): if isinstance(value, datetime.datetime): attr_dict[key] = format_date(value) if attr_dict.get('_sa_instance_state'): del attr_dict['_sa_instance_state'] return attr_dict
def to_dict(self): attr_dict = copy.deepcopy(self.__dict__) for key, value in attr_dict.iteritems(): if isinstance(value, datetime.datetime): attr_dict[key] = format_date(value) if attr_dict.get('_sa_instance_state'): del attr_dict['_sa_instance_state'] return attr_dict
def email_message(): data = json.loads(request.data) email = data.get("email") subject = data.get("subject") body = data.get("body") if not email or not body: return_data = {"message": "An email and body are required."} return json.dumps(return_data), 500, {"Content-Type": "application/json"} data = {"ip": request.remote_addr, "time": format_date(now_utc(), "%H:%M:%S, %B %d, %Y")} send_contact_email(email, subject, body, data=data) return json.dumps(data), 200, {"Content-Type": "application/json"}
def send_subscription_email(subscription, gallery): description = u'{}...'.format(gallery.description()[:400]) if gallery.description() else '' category = gallery.latest_category() template = env.get_template('subscription_email.txt') body_text = template.render(user_name=subscription.name, blog_url=gallery.url(), cancel_url=subscription.cancel_url(), published_at=format_date(gallery.published_at), category=category, unsubscribe_url=subscription.url()) template = env.get_template('subscription_email.html') body_html = template.render(user_name=subscription.name, blog_url=gallery.url(), gallery_title=gallery.name, subtitle=gallery.subtitle, published_at=format_date(gallery.published_at), author=gallery.author, description=description, category=category, cancel_url=subscription.cancel_url(), unsubscribe_url=subscription.url()) send_email(subscription.email, gallery.name, body_text=body_text, body_html=body_html)
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
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
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
def email_message(): data = json.loads(request.data) email = data.get('email') subject = data.get('subject') body = data.get('body') if not email or not body: return_data = {'message': 'An email and body are required.'} return json.dumps(return_data), 500, { 'Content-Type': 'application/json' } data = { 'ip': request.remote_addr, 'time': format_date(now_utc(), '%H:%M:%S, %B %d, %Y') } send_contact_email(email, subject, body, data=data) return json.dumps(data), 200, {'Content-Type': 'application/json'}
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
def process_tweet(tweet): ''' Return dict of items we actually need from the tweet. ''' tweet_dict = {} fields = dir(tweet) for field in fields: if '_' not in field: tweet_dict[field] = getattr(tweet, field) tweet_dict['user'] = json.dumps(tweet.user._json) tweet_dict['author'] = json.dumps(tweet.author._json) tweet_dict['created_at'] = format_date(tweet.created_at, '%B %d, %Y') link = "https://www.twitter.com/{}/status/{}".format(tweet.author._json.get('screen_name'), tweet_dict.get('id')) tweet_dict['link'] = link tweet_dict.pop('retweets') tweet_dict.pop('favorite') tweet_dict.pop('retweet') tweet_dict.pop('parse') tweet_dict.pop('destroy') tweet_dict.pop('place') return tweet_dict