コード例 #1
0
 def send(self, user, email, request_date):
     self.recipient = user
     secret = crypt.crypt(email, "$6$" + str(request_date))
     link = abs_url(secure=True) +\
             "email_confirmation?user="******"&email=" + urllib.quote(email) +\
             "&secret=" + urllib.quote(secret)
     context = {'recipient': self.recipient, 'link': link}
     self.send_mail(context)
コード例 #2
0
    def send(self, expr, milestone):
        self.recipient = expr.owner
        context = {
            'message': ui.milestone_message,
            'expr': expr,
            'milestone': milestone,
            'server_url': abs_url()
        }

        self.subject = u'Your newhive "{}" has {} views'.format(
            expr['title'], milestone)
        sendgrid_args = {'expr_id': expr.id, 'milestone': milestone}

        self.send_mail(context, unique_args=sendgrid_args)
コード例 #3
0
 def send(self, user):
     self.recipient = user
     context = {
         'recipient':
         user,
         'profile_link':
         user.url,
         'profile_icon':
         self.asset('skin/site/welcome_email_images/profile_button.png',
                    http=True),
         'create_link':
         abs_url(secure=True) + "home/edit",
         'create_icon':
         self.asset('skin/site/welcome_email_images/create_button.png',
                    http=True),
         'follow_link':
         abs_url(secure=True) + "home/featured",
         'follow_icon':
         self.asset('skin/site/welcome_email_images/hive_button.png',
                    http=True),
         'featured_exprs':
         self.db.Expr.featured(6)
     }
     self.send_mail(context)
コード例 #4
0
 def send(self, expr, initiator, recipient, message, fullscreen=False):
     self.card = expr
     self.initiator = initiator
     self.recipient = recipient
     self.message = message
     context = {}
     if fullscreen:
         context['expr_url'] = (abs_url(domain=config.content_domain) +
                                expr.get_url(relative=True))
     if not hasattr(self.recipient, 'id'):
         referral = initiator.new_referral({
             'to': recipient.get('email'),
             'type': 'email'
         })
         context['signup_url'] = referral.url
     super(ShareExpr, self).send(context)
コード例 #5
0
    def send(self, context=None):
        if not context: context = {}

        featured, featured_type = self.featured_exprs
        # import ipdb; ipdb.set_trace()//!!
        context.update({
            'message': self.message,
            'initiator': self.initiator,
            'recipient': self.recipient,
            'header': self.header_message,
            'expr': self.card if self.card._col.name == 'expr' else None,
            'server_url': abs_url(),
            'featured_exprs': featured,
            'featured_type': featured_type
        })
        #bugbug: db.assets missing.
        # icon = self.db.assets.url('skin/1/email/' + self.name + '.png', return_debug=False)
        # if icon: context.update(icon=icon)

        sendgrid_args = {
            'initiator': self.initiator and self.initiator.get('name'),
            'expr_id': self.card.id
        }
        self.send_mail(context, unique_args=sendgrid_args)
コード例 #6
0
ファイル: utils.py プロジェクト: newhive/newhive
 def __init__(self, path='', user='', page='', secure=True):
     if user and not path:
         path = user + '/' + page
     super(AbsUrl, self).__init__(abs_url(secure=secure) + path)
コード例 #7
0
    def send_mail(self, context=None, filters=None, **kwargs):
        if not filters: filters = {}
        if not context: context = {}

        email_id = str(bson.objectid.ObjectId())

        record = {
            '_id': email_id,
            'email': self.recipient.get('email'),
            'category': self.name
        }
        if type(self.recipient) == newhive.state.User:
            record.update({
                'recipient': self.recipient.id,
                'recipient_name': self.recipient.get('name')
            })
        if type(self.initiator) == newhive.state.User:
            record.update({
                'initiator': self.initiator.id,
                'initiator_name': self.initiator.get('name')
            })
        if kwargs.has_key('unique_args'):
            record['unique_args'] = kwargs['unique_args']

        # Bypass sendgrid list management, we have our own system
        filters.update(bypass_list_management={'settings': {'enable': 1}})
        if self.unsubscribable:
            if isinstance(self.recipient, newhive.state.User):
                context.update({
                    'unsubscribe_url':
                    abs_url(secure=True) + self.recipient['name'] +
                    "/profile/settings",
                    'unsubscribe_text':
                    "To manage your email subscriptions"
                })
            else:
                context.update({
                    'unsubscribe_url':
                    abs_url(secure=True) + "unsubscribe",
                    'unsubscribe_text':
                    "To unsubscribe from this or all emails from newhive"
                })

        # build heads and body
        context.update({
            'type': self.name,
            'email_id': email_id,
            'css_debug': css_debug and self.inline_css,
            'server_url': AbsUrl()
        })

        if hasattr(self.__class__.__base__, 'name'):
            context['super_type'] = self.__class__.__base__.name

        body = self.body(context)
        heads = self.heads()
        # heads.update(To=self.recipient.get('email'))

        subscribed = self.check_subscription()
        record.update(sent=subscribed)

        logger.info("to: {}\tname: {}\tstatus: {}".format(
            self.recipient.get('email'), self.name,
            'unsubscribed' if not subscribed else 'sent'))

        # write e-mail to file for debugging
        if config.debug_mode:
            path = 'lib/email/' + email_id + utils.junkstr(4) + '.html'
            with open(config.src_home + '/' + path, 'w') as f:
                f.write('<div><pre>')
                for key, val in heads.items():
                    s = u"{:<20}{}\n".format(key + u":", val)
                    f.write(s.encode('utf-8'))
                f.write('</pre></div>')
                if body.has_key('html'):
                    f.write(body['html'].encode('utf-8'))
                else:
                    f.write('<pre style="font-family: sans-serif;">')
                    f.write(body['plain'].encode('utf-8'))
                    f.write('</pre>')
            debug_url = abs_url() + path
            logger.debug('temporary e-mail path: ' + debug_url)
            record.update(debug_url=debug_url)

        if subscribed:
            _send_mail(heads,
                       body,
                       self.db,
                       filters=filters,
                       category=self.name,
                       smtp=self.smtp,
                       **kwargs)

        self.db.MailLog.create(record)
コード例 #8
0
from urllib2 import urlopen
from newhive import state, config
from newhive.config import abs_url, url_host

db=state.Database() 

max_threads = 30
max_time = 10.

# This code assumes that the local db is (mostly) in sync
# with the external one.  (If loadtest is running externally)
# Alternatively, require the loadtest to run *on* the external machine

# Using abs_url() means it will use the server in config.py
# (which can point externally if desired)
server_url = abs_url()[:-1]
content_server = url_host(False)
server_url = "http://staging.newhive.com"
content_server = "staging.tnh.me/"

# TODO: make this a serializable class
# with an option to write to a file
class Log(object):
    """docstring for Log"""
    # histogram = {} 
    def __init__(self):
        super(Log, self).__init__()
        self.histogram = {}
        self.queries = {}
        self.log = []