示例#1
0
文件: models.py 项目: 343max/NewsBlur
    def send_opml_export_email(self):
        if not self.user.email:
            return
        
        MSentEmail.objects.get_or_create(receiver_user_id=self.user.pk,
                                         email_type='opml_export')
        
        exporter = OPMLExporter(self.user)
        opml     = exporter.process()

        params = {
            'feed_count': UserSubscription.objects.filter(user=self.user).count(),
        }
        user    = self.user
        text    = render_to_string('mail/email_opml_export.txt', params)
        html    = render_to_string('mail/email_opml_export.xhtml', params)
        subject = "Backup OPML file of your NewsBlur sites"
        filename= 'NewsBlur Subscriptions - %s.xml' % datetime.datetime.now().strftime('%Y-%m-%d')
        msg     = EmailMultiAlternatives(subject, text, 
                                         from_email='NewsBlur <%s>' % settings.HELLO_EMAIL,
                                         to=['%s <%s>' % (user, user.email)])
        msg.attach_alternative(html, "text/html")
        msg.attach(filename, opml, 'text/xml')
        msg.send(fail_silently=True)
        
        logging.user(self.user, "~BB~FM~SBSending OPML backup email to: %s" % self.user.email)
示例#2
0
    def send_opml_export_email(self):
        if not self.user.email:
            return

        MSentEmail.objects.get_or_create(receiver_user_id=self.user.pk,
                                         email_type='opml_export')

        exporter = OPMLExporter(self.user)
        opml = exporter.process()

        params = {
            'feed_count':
            UserSubscription.objects.filter(user=self.user).count(),
        }
        user = self.user
        text = render_to_string('mail/email_opml_export.txt', params)
        html = render_to_string('mail/email_opml_export.xhtml', params)
        subject = "Backup OPML file of your NewsBlur sites"
        filename = 'NewsBlur Subscriptions - %s.xml' % datetime.datetime.now(
        ).strftime('%Y-%m-%d')
        msg = EmailMultiAlternatives(subject,
                                     text,
                                     from_email='NewsBlur <%s>' %
                                     settings.HELLO_EMAIL,
                                     to=['%s <%s>' % (user, user.email)])
        msg.attach_alternative(html, "text/html")
        msg.attach(filename, opml, 'text/xml')
        msg.send(fail_silently=True)

        logging.user(
            self.user,
            "~BB~FM~SBSending OPML backup email to: %s" % self.user.email)
示例#3
0
    def send_opml_export_email(self, reason=None, force=False):
        if not self.user.email:
            return
        
        emails_sent = MSentEmail.objects.filter(receiver_user_id=self.user.pk,
                                                email_type='opml_export')
        day_ago = datetime.datetime.now() - datetime.timedelta(days=1)
        for email in emails_sent:
            if email.date_sent > day_ago and not force:
                logging.user(self.user, "~SN~FMNot sending opml export email, already sent today.")
                return

        MSentEmail.record(receiver_user_id=self.user.pk, email_type='opml_export')
        
        exporter = OPMLExporter(self.user)
        opml     = exporter.process()

        params = {
            'feed_count': UserSubscription.objects.filter(user=self.user).count(),
            'reason': reason,
        }
        user    = self.user
        text    = render_to_string('mail/email_opml_export.txt', params)
        html    = render_to_string('mail/email_opml_export.xhtml', params)
        subject = "Backup OPML file of your NewsBlur sites"
        filename= 'NewsBlur Subscriptions - %s.xml' % datetime.datetime.now().strftime('%Y-%m-%d')
        msg     = EmailMultiAlternatives(subject, text, 
                                         from_email='NewsBlur <%s>' % settings.HELLO_EMAIL,
                                         to=['%s <%s>' % (user, user.email)])
        msg.attach_alternative(html, "text/html")
        msg.attach(filename, opml, 'text/xml')
        msg.send(fail_silently=True)
        
        logging.user(self.user, "~BB~FM~SBSending OPML backup email to: %s" % self.user.email)
示例#4
0
def opml_export(request):
    user     = get_user(request)
    exporter = OPMLExporter(user)
    opml     = exporter.process()
    now      = datetime.datetime.now()
    
    response = HttpResponse(opml, mimetype='text/xml')
    response['Content-Disposition'] = 'attachment; filename=NewsBlur Subscriptions - %s' % (
        now.strftime('%d %B %Y')
    )
    
    return response
示例#5
0
def opml_export(request):
    user = get_user(request)
    exporter = OPMLExporter(user)
    opml = exporter.process()
    now = datetime.datetime.now()

    response = HttpResponse(opml, mimetype='text/xml')
    response[
        'Content-Disposition'] = 'attachment; filename=NewsBlur Subscriptions - %s' % (
            now.strftime('%d %B %Y'))

    return response
示例#6
0
def opml_export(request):
    user = get_user(request)
    now = datetime.datetime.now()
    if request.REQUEST.get('user_id') and user.is_staff:
        user = User.objects.get(pk=request.REQUEST['user_id'])
    exporter = OPMLExporter(user)
    opml = exporter.process()

    response = HttpResponse(opml, content_type='text/xml')
    response['Content-Disposition'] = 'attachment; filename=PyTune-%s-%s' % (
        user.username, now.strftime('%Y-%m-%d'))

    return response
示例#7
0
def opml_export(request):
    user     = get_user(request)
    now      = datetime.datetime.now()
    if request.REQUEST.get('user_id') and user.is_staff:
        user = User.objects.get(pk=request.REQUEST['user_id'])
    exporter = OPMLExporter(user)
    opml     = exporter.process()
    
    response = HttpResponse(opml, mimetype='text/xml')
    response['Content-Disposition'] = 'attachment; filename=NewsBlur Subscriptions - %s - %s' % (
        user.username,
        now.strftime('%Y-%m-%d')
    )
    
    return response
示例#8
0
def opml_export(request):
    user = get_user(request)
    now = datetime.datetime.now()
    if request.REQUEST.get("user_id") and user.is_staff:
        user = User.objects.get(pk=request.REQUEST["user_id"])
    exporter = OPMLExporter(user)
    opml = exporter.process()

    response = HttpResponse(opml, mimetype="text/xml")
    response["Content-Disposition"] = "attachment; filename=NewsBlur Subscriptions - %s - %s" % (
        user.username,
        now.strftime("%Y-%m-%d"),
    )

    return response
示例#9
0
def opml_export(request):
    user = get_user(request)
    now = datetime.datetime.now()
    if request.GET.get('user_id') and user.is_staff:
        user = User.objects.get(pk=request.GET['user_id'])
    exporter = OPMLExporter(user)
    opml = exporter.process()

    from apps.social.models import MActivity
    MActivity.new_opml_export(user_id=user.pk, count=exporter.feed_count)

    response = HttpResponse(opml, content_type='text/xml; charset=utf-8')
    response[
        'Content-Disposition'] = 'attachment; filename=NewsBlur-%s-%s.opml' % (
            user.username, now.strftime('%Y-%m-%d'))

    return response
示例#10
0
    def send_opml_export_email(self, reason=None, force=False):
        if not self.user.email:
            return

        emails_sent = MSentEmail.objects.filter(receiver_user_id=self.user.pk,
                                                email_type='opml_export')
        day_ago = datetime.datetime.now() - datetime.timedelta(days=1)
        for email in emails_sent:
            if email.date_sent > day_ago and not force:
                logging.user(
                    self.user,
                    "~SN~FMNot sending opml export email, already sent today.")
                return

        MSentEmail.record(receiver_user_id=self.user.pk,
                          email_type='opml_export')

        exporter = OPMLExporter(self.user)
        opml = exporter.process()

        params = {
            'feed_count':
            UserSubscription.objects.filter(user=self.user).count(),
            'reason': reason,
        }
        user = self.user
        text = render_to_string('mail/email_opml_export.txt', params)
        html = render_to_string('mail/email_opml_export.xhtml', params)
        subject = "Backup OPML file of your NewsBlur sites"
        filename = 'NewsBlur Subscriptions - %s.xml' % datetime.datetime.now(
        ).strftime('%Y-%m-%d')
        msg = EmailMultiAlternatives(subject,
                                     text,
                                     from_email='NewsBlur <%s>' %
                                     settings.HELLO_EMAIL,
                                     to=['%s <%s>' % (user, user.email)])
        msg.attach_alternative(html, "text/html")
        msg.attach(filename, opml, 'text/xml')
        msg.send(fail_silently=True)

        logging.user(
            self.user,
            "~BB~FM~SBSending OPML backup email to: %s" % self.user.email)