def user_followed(self, follow): """ :param follow: UserFollow object which has just been created """ mixpanel_track(self.request, "Followed User", {"followed_user": follow.target.username}) mixpanel_engage(self.request, get_mixpanel_info(follow.user), follow.user.id) mixpanel_engage(self.request, get_mixpanel_info(follow.target, ignore_time=True), follow.target.id) template_name = 'new-follower-notification' context = { 'USER_USERNAME': follow.user.username, 'USER_PROFILE_URL': absolute_uri(follow.user.get_profile().get_absolute_url()), 'TARGET_USER_USERNAME': follow.target.username, 'TARGET_USER_PROFILE_URL': absolute_uri(follow.target.get_profile().get_absolute_url()) } print absolute_uri(follow.user.get_profile().get_absolute_url()), \ absolute_uri(follow.target.get_profile().get_absolute_url()) email_notification = follow.target.email_notification if email_notification.follower_notifications: self._sendmail(template_name, follow.target.email, context) else: LOG.info( "Email not send to %s, since follower_notifications is set to OFF", follow.target.email)
def generate_image_links(self): first = True for image in self.product.images[:10]: if first: first = False yield self._gen("image_link", absolute_uri(image.url)) else: yield self._gen("additional_image_link", absolute_uri(image.url))
def get_context(self, user): profile_url = reverse("public_profile", args=(self.commenter, )) update_profile = reverse("account_email_notifications") return { "COMMENT": self.comment.comment, "COMMENT_REPLY_URL": absolute_uri(self.comment.get_reply_url()), "COMMENTER_USERNAME": self.commenter.username, "COMMENTER_PROFILE_URL": absolute_uri(profile_url), "FNAME": user.first_name, "UPDATE_PROFILE": absolute_uri(update_profile), }
def get_context(self, user): context = super(ProductCommentNotifier, self).get_context(user) context.update({ "PRODUCT_TITLE": self.product.title, "PRODUCT_URL": absolute_uri(self.product.get_absolute_url()) }) return context
def get_context(self, user): context = super(LoveListCommentNotifier, self).get_context(user) context.update({ "LOVELIST_TITLE": self.love_list.title, "LOVELIST_URL": absolute_uri(self.love_list.get_absolute_url()), }) return context
def user_signup(self, user, requires_activation=True): """ Welcomes the user to the site Includes URL for them to activate their account / verify their e-mail. """ if requires_activation: user_profile = user.user_profile verify_url = absolute_uri( reverse("verify", args=[user_profile.activation_key])) ctx = dict(ACTIVATION_URL=verify_url) self._sendmail('regular-user-welcome-email', user.email, ctx) profile = user.get_profile() # Fix up their MailingLists objects from mailing_lists.models import MailingListSignup mls = MailingListSignup.objects.create_from_user(user) mls.marketing_optin = profile.send_newsletters if self.request is not None: mls.set_ip_address(self.request) mls.save() # Apply defaults to EmailNotification preferences email_notification = user.email_notification email_notification.site_updates_features = profile.send_newsletters email_notification.stall_owner_tips = True email_notification.product_inspirations = profile.send_newsletters email_notification.blogs_you_might_like = profile.send_newsletters email_notification.save() # Integration with sailthru if self.sailthru.enabled(): self.sailthru.signup(user=user)
def get_context(self, user): context = super(ArticleCommentNotifier, self).get_context(user) context.update({ "BLOG_POST_TITLE": self.article.title, "BLOG_POST_URL": absolute_uri(self.article.get_absolute_url()) }) return context
def notify_directors_of_paypal_error(request, info): context = { 'pe_error_id': info['pe'].error_id, 'pe_error': repr(info['pe']), 'payment_attempt_id': info['payment_attempt'].id, 'payment_id': info['payment'].id, 'purchaser_email': request.user.email, 'purchaser_id': request.user.id, 'seller_notified': "Yes" if info['seller_notified'] else "No", 'stall_user_email': info['cart_stall'].stall.user.email, 'stall_phone_landline': info['cart_stall'].stall.phone_landline, 'stall_phone_mobile': info['cart_stall'].stall.phone_mobile, "FNAME": info['payment_attempt'].cart_stall.stall.user.first_name, "ORDER_DATE": info['payment_attempt'].created.strftime("%d-%m-%Y"), "STALL_TITLE": info['payment_attempt'].cart_stall.stall.title, "STALL_URL": absolute_uri( reverse( "my_stall", kwargs={"slug": info['payment_attempt'].cart_stall.stall.slug})), "CUSTOMER_USERNAME": info['payment_attempt'].cart_stall.cart.user.username, "CUSTOMER_PROFILE_URL": absolute_uri( reverse("public_profile", kwargs={ "username": info['payment_attempt'].cart_stall.cart.user.username })), } to_email = '*****@*****.**' Sailthru(request).send_template('directors-paypal-error', to_email, context)
def generate_link(self): path = reverse('product_page', kwargs={ "stall_identifier": self.product.stall.identifier, "product_name": self.product.slug, }) uri = absolute_uri(path) link_str = "%s" % (uri,) return self._gen('link', link_str)
def stall_suspended(self, stall): user = stall.user context = { "STALL_URL": absolute_uri(reverse("my_stall", kwargs={ "slug": stall.slug, })) } self._sendmail("stock-check-suspension-notice", user.email, context)
def stall_stockcheck_urgent(self, stall): user = stall.user context = { "STALL_URL": absolute_uri(reverse("my_stall", kwargs={ "slug": stall.slug, })), "DAYS_LEFT": stall.days_to_next_stockcheck } self._sendmail("stock-check-reminder-2", user.email, context)
def stall_opened(self, stall): """ A new stall has been opened, welcome the user to the site and give them information about how to add products & optimize their stuff. """ user = stall.user context = { "STALL_URL": absolute_uri(reverse("my_stall", kwargs={ "slug": stall.slug, })) } self._sendmail("stall-owner-welcome", user.email, context)
def _order_item_context(self, item): """ XXX: move somewhere else? """ product = item.product return { 'qty': item.quantity, 'title': product.title, 'price': str(item.price), 'total': str(item.price * item.quantity), 'id': product.id, 'url': absolute_uri(product.get_absolute_url()) }
def generate_link(self): path = reverse('product_page', kwargs={ "stall_identifier": self.product.stall.identifier, "product_name": self.product.slug, }) uri = absolute_uri(path) link_str = "%s" % (uri, ) utm_data = { "utm_source": "become", "utm_medium": "cpc", } return "%s?%s" % (self._gen('link', link_str), urlencode( dict(utm_data)))
def seller_paypal_error(self, payment_attempt): """ The payment attempt failed because the Seller has an invalid Paypal address :param payment_attempt: PaymentAttempt object """ try: stall = payment_attempt.cart_stall.stall stall_url = reverse("my_stall", kwargs={"slug": stall.slug}) settings_url = reverse("account_email_notifications") context = { 'stall': { 'title': stall.title, 'url': absolute_uri(stall_url), }, 'PAYPAL_SETTINGS_URL': absolute_uri(settings_url) } to_email = stall.user.email self._sendmail("seller-erroneous-paypal-account", to_email, context) except: LOG.error('seller_paypal_error failed', exc_info=True)
def _generate_link(self): if self.currency == 'USD': # In the case of US feeds we are using product URLs # which show product price in USD path = reverse('product_page_fixed_currency', kwargs={ "stall_identifier": self.product.stall.identifier, "product_name": self.product.slug, "currency": self.currency, }) else: path = reverse('product_page', kwargs={ "stall_identifier": self.product.stall.identifier, "product_name": self.product.slug, }) return absolute_uri(path)
def forgot_password(self, user, token_generator=None): """ Sends 'Forgot Username or Password?' with their username and a link to the password reset form. """ from django.utils.http import int_to_base36 if token_generator is None: from django.contrib.auth.tokens import default_token_generator token_generator = default_token_generator token = token_generator.make_token(user) uid = int_to_base36(user.id) ctx = dict(PASSWORD_RESET_URL=absolute_uri( reverse("password_reset_confirm", kwargs={ "uidb36": uid, "token": token }))) self._sendmail('forgot-username-or-password', user.email, ctx)
def message_sent(self, msg): """ A new message has been sent, notify the recipient via e-mail :param msg: Message object """ if not msg.parent_msg: template_name = "new-message-received" else: template_name = "message-reply-received" # TODO: notification settings context = { "SENDER_USERNAME": msg.sender.username, "MESSAGE_SUBJECT": msg.subject, "MESSAGE_BODY": msg.body, 'MESSAGE_VIEW_URL': absolute_uri(reverse('messaging_inbox')) } # send mail to hipchat template_context = Context({ 'request': self.request, 'message': msg, }) template = loader.get_template( "messaging/fragments/hipchat_message.html") output = template.render(template_context) send_to_hipchat( output, room_id=settings.HIPCHAT_MAIL_ROOM, notify=1, ) mixpanel_track(self.request, "Sent Message", {}) mixpanel_engage(self.request, {'$add': {'Messages Sent': 1}}) self._sendmail(template_name, msg.recipient.email, context)
def generate_image(self): first = True image = self.product.images[0] return self._gen("image", absolute_uri(image.url))
def _order_context(self, order): """ XXX: move somewhere else? """ items = [ self._order_item_context(line_item) for line_item in order.line_items.all() ] address = order.address delta = datetime.datetime.now().date() - order.created context = { 'ORDER': { 'items': items, 'subtotal': str(order.subtotal()), 'shipping': str(order.delivery_charge), 'total': str(order.total()), 'note': order.note, 'address': { 'name': address.name, 'city': address.city, 'country': address.country.title, 'line1': address.line1, 'line2': address.line2, 'postal_code': address.postal_code, 'state': address.state, }, }, "FNAME": order.user.first_name, "ORDER_DATE": custom_strftime('{S} %B %Y', order.created), "CUSTOMER_FIRST_NAME": order.user.first_name, "CUSTOMER_FULL_NAME": order.user.get_profile().full_name, "CUSTOMER_USERNAME": order.user.username, "CUSTOMER_PROFILE_URL": absolute_uri( reverse("public_profile", kwargs={"username": order.user.username})), "ORDER_ID": order.id, "INVOICE_URL": absolute_uri(reverse("invoice", kwargs={"order_id": order.id})), "STALL_TITLE": order.stall.title, "STALL_URL": absolute_uri(reverse("my_stall", kwargs={"slug": order.stall.slug})), "STALL_OWNER_USERNAME": order.stall.user.username, 'STALL_OWNER_URL': order.stall.user.get_profile().get_absolute_url(), "NUMBER_OF_DAYS_SINCE_ORDER": delta.days, "MESSAGE_CUSTOMER_URL": absolute_uri( reverse("messaging_compose_to", kwargs={ "recipient": order.user.username, })), "MESSAGE_STALL_URL": absolute_uri( reverse("messaging_compose_to", kwargs={ "recipient": order.stall.user.username, })), "UPDATE_PROFILE": absolute_uri(reverse("account_email_notifications")), } return context
class ShareNode(template.Node): SHARRRE_LIB_PATH = settings.STATIC_URL + 'js/vendor/jquery.sharrre-1.3.2.min.js' SHARRRE_SCRIPT = '<script type="text/javascript" src="%s"></script>' % SHARRRE_LIB_PATH SCRIPT = ''' <script type="text/javascript"> $(function() { $('#').sharrre(%s); }); </script> ''' DEFAULT_MEDIA = settings.STATIC_URL + 'images/ecomarket.png' DEFAULT_OPTIONS = { 'share': { 'twitter': True, 'facebook': True, 'googlePlus': True, 'pinterest': True, }, 'enableHover': False, 'enableCounter': False, 'enableTracking': True, 'className': 'sharrre vertical', 'url': 'http://www.ecomarket.com', 'buttons': { 'googlePlus': { 'size': 'medium', 'annotation': 'none', }, 'facebook': { 'layout': 'button_count', 'faces': False, }, 'twitter': { 'via': 'ecomarket', }, 'pinterest': { 'media': absolute_uri(DEFAULT_MEDIA), } } } def __init__(self, incl_script, obj=None, style='vertical', ele_id='#shareme'): self.incl_script = incl_script if obj is not None: self.obj = template.Variable(obj) else: self.obj = obj self.style = style self.ele_id = ele_id def render(self, context): script = self.SCRIPT script = script.replace('#', self.ele_id) options = self.get_defaults() if self.incl_script: script = self.SHARRRE_SCRIPT + script if self.obj is None: # like facebook page if there is no content to share options['buttons']['facebook'][ 'url'] = 'http://www.facebook.com/ecomarketdotcom' return script % json.dumps(options) else: try: obj = self.obj.resolve(context) except template.VariableDoesNotExist: raise template.TemplateSyntaxError('could not resolve %s' % self.obj) if type(obj) not in [Article, Product, Stall, LoveList]: raise template.TemplateSyntaxError( 'social_script tag requires an object of type Article,' \ + ' Product, Stall or LoveList as the first argument ' \ + 'recieved type %s' % type(obj) ) if self.style == 'horizonal': options['className'] = 'sharrre horizontal' tags = [] # Stall if type(obj) == Stall: text = 'Loving %s on Eco Market' % obj.title media = absolute_uri(obj.user.get_profile().avatar_228) if media is None: media = self.DEFAULT_MEDIA # Product elif type(obj) == Product: text = 'Loving this %s on Eco Market' % obj.title media = obj.image.url_400 tags = obj.causes.all()[:3] tags = list(chain(tags, obj.keywords.all()[:2])) # Article elif type(obj) == Article: text = obj.title tags = obj.tags.all()[:3] if obj.youtube_video is not None: media = obj.youtube_video['url'] elif obj.attachments.exists(): attachment = obj.attachments.latest('id') media = absolute_uri(attachment.attachment.url) else: media = self.DEFAULT_MEDIA # LoveList elif type(obj) == LoveList: text = 'Loving %s by %s on Eco Market' % (obj.title, obj.user.get_name()) tags.append(str(obj.primary_category)) tags.append(str(obj.secondary_category)) media = absolute_uri(obj.products.latest('id').image.url_80) # sharing options.. options['text'] = text options['url'] = absolute_uri(obj.get_absolute_url()) options['buttons']['twitter']['hashtags'] = ','.join( [str(t) for t in tags]), options['buttons']['pinterest']['media'] = media options['buttons']['pinterest']['description'] = text return script % json.dumps(options) def get_defaults(self): ''' storing options in nestled dictionaries is a bad idea.''' return deepcopy(self.DEFAULT_OPTIONS)
def get_context(self, user): context = super(UserProfileCommentNotifier, self).get_context(user) context.update({ "PROFILE_URL": absolute_uri(self.user_profile.get_absolute_url()) }) return context
def render(self, context): script = self.SCRIPT script = script.replace('#', self.ele_id) options = self.get_defaults() if self.incl_script: script = self.SHARRRE_SCRIPT + script if self.obj is None: # like facebook page if there is no content to share options['buttons']['facebook'][ 'url'] = 'http://www.facebook.com/ecomarketdotcom' return script % json.dumps(options) else: try: obj = self.obj.resolve(context) except template.VariableDoesNotExist: raise template.TemplateSyntaxError('could not resolve %s' % self.obj) if type(obj) not in [Article, Product, Stall, LoveList]: raise template.TemplateSyntaxError( 'social_script tag requires an object of type Article,' \ + ' Product, Stall or LoveList as the first argument ' \ + 'recieved type %s' % type(obj) ) if self.style == 'horizonal': options['className'] = 'sharrre horizontal' tags = [] # Stall if type(obj) == Stall: text = 'Loving %s on Eco Market' % obj.title media = absolute_uri(obj.user.get_profile().avatar_228) if media is None: media = self.DEFAULT_MEDIA # Product elif type(obj) == Product: text = 'Loving this %s on Eco Market' % obj.title media = obj.image.url_400 tags = obj.causes.all()[:3] tags = list(chain(tags, obj.keywords.all()[:2])) # Article elif type(obj) == Article: text = obj.title tags = obj.tags.all()[:3] if obj.youtube_video is not None: media = obj.youtube_video['url'] elif obj.attachments.exists(): attachment = obj.attachments.latest('id') media = absolute_uri(attachment.attachment.url) else: media = self.DEFAULT_MEDIA # LoveList elif type(obj) == LoveList: text = 'Loving %s by %s on Eco Market' % (obj.title, obj.user.get_name()) tags.append(str(obj.primary_category)) tags.append(str(obj.secondary_category)) media = absolute_uri(obj.products.latest('id').image.url_80) # sharing options.. options['text'] = text options['url'] = absolute_uri(obj.get_absolute_url()) options['buttons']['twitter']['hashtags'] = ','.join( [str(t) for t in tags]), options['buttons']['pinterest']['media'] = media options['buttons']['pinterest']['description'] = text return script % json.dumps(options)