当前位置: 首页>>代码示例>>Python>>正文


Python UserSubscription.add_subscription方法代码示例

本文整理汇总了Python中apps.reader.models.UserSubscription.add_subscription方法的典型用法代码示例。如果您正苦于以下问题:Python UserSubscription.add_subscription方法的具体用法?Python UserSubscription.add_subscription怎么用?Python UserSubscription.add_subscription使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在apps.reader.models.UserSubscription的用法示例。


在下文中一共展示了UserSubscription.add_subscription方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: add_site

# 需要导入模块: from apps.reader.models import UserSubscription [as 别名]
# 或者: from apps.reader.models.UserSubscription import add_subscription [as 别名]
def add_site(request, token):
    code       = 0
    url        = request.GET['url']
    folder     = request.GET['folder']
    new_folder = request.GET.get('new_folder')
    callback   = request.GET['callback']
    
    if not url:
        code = -1
    else:
        try:
            profile = Profile.objects.get(secret_token=token)
            if new_folder:
                usf, _ = UserSubscriptionFolders.objects.get_or_create(user=profile.user)
                usf.add_folder(folder, new_folder)
                folder = new_folder
            code, message, us = UserSubscription.add_subscription(
                user=profile.user, 
                feed_address=url,
                folder=folder,
                bookmarklet=True
            )
        except Profile.DoesNotExist:
            code = -1
    
    if code > 0:
        message = 'OK'
        
    logging.user(profile.user, "~FRAdding URL from site: ~SB%s (in %s)" % (url, folder))
    
    return HttpResponse(callback + '(' + json.encode({
        'code':    code,
        'message': message,
        'usersub': us and us.feed.pk,
    }) + ')', mimetype='text/plain')
开发者ID:Laptop765,项目名称:NewsBlur,代码行数:37,代码来源:views.py

示例2: api_save_new_subscription

# 需要导入模块: from apps.reader.models import UserSubscription [as 别名]
# 或者: from apps.reader.models.UserSubscription import add_subscription [as 别名]
def api_save_new_subscription(request):
    user = request.user
    body = request.body_json
    fields = body.get('actionFields')
    url = urlnorm.normalize(fields['url'])
    folder = fields['folder']
    
    if folder == "Top Level":
        folder = " "
    
    code, message, us = UserSubscription.add_subscription(
        user=user, 
        feed_address=url,
        folder=folder,
        bookmarklet=True
    )
    
    logging.user(request, "~FRAdding URL from ~FC~SBIFTTT~SN~FR: ~SB%s (in %s)" % (url, folder))

    if us and us.feed:
        url = us.feed.feed_address

    return {"data": [{
        "id": us and us.feed_id,
        "url": url,
    }]}
开发者ID:76,项目名称:NewsBlur,代码行数:28,代码来源:views.py

示例3: add_site

# 需要导入模块: from apps.reader.models import UserSubscription [as 别名]
# 或者: from apps.reader.models.UserSubscription import add_subscription [as 别名]
def add_site(request, token):
    code = 0
    url = request.GET["url"]
    folder = request.GET["folder"]
    new_folder = request.GET.get("new_folder")
    callback = request.GET["callback"]

    if not url:
        code = -1
    else:
        try:
            profile = Profile.objects.get(secret_token=token)
            if new_folder:
                usf, _ = UserSubscriptionFolders.objects.get_or_create(user=profile.user)
                usf.add_folder(folder, new_folder)
                folder = new_folder
            code, message, us = UserSubscription.add_subscription(
                user=profile.user, feed_address=url, folder=folder, bookmarklet=True
            )
        except Profile.DoesNotExist:
            code = -1

    if code > 0:
        message = "OK"

    logging.user(profile.user, "~FRAdding URL from site: ~SB%s (in %s)" % (url, folder), request=request)

    return HttpResponse(
        callback + "(" + json.encode({"code": code, "message": message, "usersub": us and us.feed_id}) + ")",
        mimetype="text/plain",
    )
开发者ID:pabloav,项目名称:NewsBlur,代码行数:33,代码来源:views.py

示例4: add_site

# 需要导入模块: from apps.reader.models import UserSubscription [as 别名]
# 或者: from apps.reader.models.UserSubscription import add_subscription [as 别名]
def add_site(request, token):
    code = 0
    url = request.GET['url']
    folder = request.GET['folder']
    callback = request.GET['callback']
    
    if not url:
        code = -1
    else:
        try:
            profile = Profile.objects.get(secret_token=token)
            code, message, us = UserSubscription.add_subscription(
                user=profile.user, 
                feed_address=url,
                folder=folder,
                bookmarklet=True
            )
        except Profile.DoesNotExist:
            code = -1
    
    if code > 0:
        message = 'OK'
        
    return HttpResponse(callback + '(' + json.encode({
        'code':    code,
        'message': message,
        'usersub': us and us.feed.pk,
    }) + ')', mimetype='text/plain')
开发者ID:francois2metz,项目名称:NewsBlur,代码行数:30,代码来源:views.py

示例5: add_site_authed

# 需要导入模块: from apps.reader.models import UserSubscription [as 别名]
# 或者: from apps.reader.models.UserSubscription import add_subscription [as 别名]
def add_site_authed(request):
    code       = 0
    url        = request.GET['url']
    folder     = request.GET['folder']
    new_folder = request.GET.get('new_folder')
    callback   = request.GET['callback']
    user       = get_user(request)
    
    if not url:
        code = -1
    else:
        if new_folder:
            usf, _ = UserSubscriptionFolders.objects.get_or_create(user=user)
            usf.add_folder(folder, new_folder)
            folder = new_folder
        code, message, us = UserSubscription.add_subscription(
            user=user, 
            feed_address=url,
            folder=folder,
            bookmarklet=True
        )
    
    if code > 0:
        message = 'OK'
        
    logging.user(user, "~FRAdding authed URL from site: ~SB%s (in %s)" % (url, folder),
                 request=request)
    
    return HttpResponse(callback + '(' + json.encode({
        'code':    code,
        'message': message,
        'usersub': us and us.feed_id,
    }) + ')', mimetype='text/plain')
开发者ID:MilenkoM,项目名称:NewsBlur,代码行数:35,代码来源:views.py

示例6: add_url

# 需要导入模块: from apps.reader.models import UserSubscription [as 别名]
# 或者: from apps.reader.models.UserSubscription import add_subscription [as 别名]
def add_url(request):
    code = 0
    url = request.POST['url']
    folder = request.POST['folder']

    code, message, _ = UserSubscription.add_subscription(user=request.user, feed_address=url, folder=folder)
    
    return dict(code=code, message=message)
开发者ID:francois2metz,项目名称:NewsBlur,代码行数:10,代码来源:views.py

示例7: receive_newsletter

# 需要导入模块: from apps.reader.models import UserSubscription [as 别名]
# 或者: from apps.reader.models.UserSubscription import add_subscription [as 别名]
 def receive_newsletter(self, params):
     user = self.user_from_email(params['recipient'])
     if not user:
         return
     
     sender_name, sender_username, sender_domain = self.split_sender(params['from'])
     feed_address = self.feed_address(user, "%[email protected]%s" % (sender_username, sender_domain))
     
     usf = UserSubscriptionFolders.objects.get(user=user)
     usf.add_folder('', 'Newsletters')
     
     try:
         feed = Feed.objects.get(feed_address=feed_address)
     except Feed.DoesNotExist:
         feed = Feed.objects.create(feed_address=feed_address, 
                                    feed_link='http://' + sender_domain,
                                    feed_title=sender_name,
                                    fetched_once=True,
                                    known_good=True)
         feed.update()
         logging.user(user, "~FCCreating newsletter feed: ~SB%s" % (feed))
         r = redis.Redis(connection_pool=settings.REDIS_PUBSUB_POOL)
         r.publish(user.username, 'reload:%s' % feed.pk)
     try:
         usersub = UserSubscription.objects.get(user=user, feed=feed)
     except UserSubscription.DoesNotExist:
         _, _, usersub = UserSubscription.add_subscription(
             user=user, 
             feed_address=feed_address,
             folder='Newsletters'
         )
     
     story_hash = MStory.ensure_story_hash(params['signature'], feed.pk)
     story_params = {
         "story_feed_id": feed.pk,
         "story_date": datetime.datetime.fromtimestamp(int(params['timestamp'])),
         "story_title": params['subject'],
         "story_content": self.get_content(params),
         "story_author_name": escape(params['from']),
         "story_permalink": reverse('newsletter-story', 
                                    kwargs={'story_hash': story_hash}),
         "story_guid": params['signature'],
     }
     try:
         story = MStory.objects.get(story_hash=story_hash)
     except MStory.DoesNotExist:
         story = MStory(**story_params)
         story.save()
     
     usersub.needs_unread_recalc = True
     usersub.save()
     
     self.publish_to_subscribers(feed)
     
     MFetchHistory.add(feed_id=feed.pk, fetch_type='push')
     logging.user(user, "~FCNewsletter feed story: ~SB%s~SN / ~SB%s" % (story.story_title, feed))
     
     return story
开发者ID:670415613,项目名称:NewsBlur,代码行数:60,代码来源:models.py

示例8: add_url

# 需要导入模块: from apps.reader.models import UserSubscription [as 别名]
# 或者: from apps.reader.models.UserSubscription import add_subscription [as 别名]
def add_url(request):
    code = 0
    url = request.POST['url']
    if not url:
        code = -1
        message = 'Enter in the website address or the feed URL.'
    else:
        folder = request.POST.get('folder', '')
        code, message, _ = UserSubscription.add_subscription(user=request.user, feed_address=url, folder=folder)
    
    return dict(code=code, message=message)
开发者ID:mrcrabby,项目名称:NewsBlur,代码行数:13,代码来源:views.py

示例9: receive_newsletter

# 需要导入模块: from apps.reader.models import UserSubscription [as 别名]
# 或者: from apps.reader.models.UserSubscription import add_subscription [as 别名]
    def receive_newsletter(self, params):
        user = self._user_from_email(params['recipient'])
        if not user:
            return
        
        sender_name, sender_username, sender_domain = self._split_sender(params['from'])
        feed_address = self._feed_address(user, "%[email protected]%s" % (sender_username, sender_domain))
        
        try:
            usf = UserSubscriptionFolders.objects.get(user=user)
        except UserSubscriptionFolders.DoesNotExist:
            logging.user(user, "~FRUser does not have a USF, ignoring newsletter.")
            return
        usf.add_folder('', 'Newsletters')
        
        try:
            feed = Feed.objects.get(feed_address=feed_address)
        except Feed.DoesNotExist:
            feed = Feed.objects.create(feed_address=feed_address, 
                                       feed_link='http://' + sender_domain,
                                       feed_title=sender_name,
                                       fetched_once=True,
                                       known_good=True)
            feed.update()
            logging.user(user, "~FCCreating newsletter feed: ~SB%s" % (feed))
            r = redis.Redis(connection_pool=settings.REDIS_PUBSUB_POOL)
            r.publish(user.username, 'reload:%s' % feed.pk)
            self._check_if_first_newsletter(user)
        
        feed.last_update = datetime.datetime.now()
        feed.last_story_date = datetime.datetime.now()
        feed.save()
        
        if feed.feed_title != sender_name:
            feed.feed_title = sender_name
            feed.save()
        
        try:
            usersub = UserSubscription.objects.get(user=user, feed=feed)
        except UserSubscription.DoesNotExist:
            _, _, usersub = UserSubscription.add_subscription(
                user=user, 
                feed_address=feed_address,
                folder='Newsletters'
            )
            r = redis.Redis(connection_pool=settings.REDIS_PUBSUB_POOL)
            r.publish(user.username, 'reload:feeds')            
        
        story_hash = MStory.ensure_story_hash(params['signature'], feed.pk)
        story_content = self._get_content(params)
        plain_story_content = self._get_content(params, force_plain=True)
        if len(plain_story_content) > len(story_content):
            story_content = plain_story_content
        story_content = self._clean_content(story_content)
        story_params = {
            "story_feed_id": feed.pk,
            "story_date": datetime.datetime.fromtimestamp(int(params['timestamp'])),
            "story_title": params['subject'],
            "story_content": story_content,
            "story_author_name": params['from'],
            "story_permalink": "https://%s%s" % (
                                    Site.objects.get_current().domain,
                                    reverse('newsletter-story', 
                                            kwargs={'story_hash': story_hash})),
            "story_guid": params['signature'],
        }

        try:
            story = MStory.objects.get(story_hash=story_hash)
        except MStory.DoesNotExist:
            story = MStory(**story_params)
            story.save()
        
        usersub.needs_unread_recalc = True
        usersub.save()
        
        self._publish_to_subscribers(feed, story.story_hash)
        
        MFetchHistory.add(feed_id=feed.pk, fetch_type='push')
        logging.user(user, "~FCNewsletter feed story: ~SB%s~SN / ~SB%s" % (story.story_title, feed))
        
        return story
开发者ID:MilenkoM,项目名称:NewsBlur,代码行数:84,代码来源:models.py

示例10: receive_newsletter

# 需要导入模块: from apps.reader.models import UserSubscription [as 别名]
# 或者: from apps.reader.models.UserSubscription import add_subscription [as 别名]
    def receive_newsletter(self, params):
        user = self.user_from_email(params["recipient"])
        if not user:
            return

        sender_name, sender_username, sender_domain = self.split_sender(params["from"])
        feed_address = self.feed_address(user, "%[email protected]%s" % (sender_username, sender_domain))

        usf = UserSubscriptionFolders.objects.get(user=user)
        usf.add_folder("", "Newsletters")

        try:
            feed = Feed.objects.get(feed_address=feed_address)
        except Feed.DoesNotExist:
            feed = Feed.objects.create(
                feed_address=feed_address,
                feed_link="http://" + sender_domain,
                feed_title=sender_name,
                fetched_once=True,
                known_good=True,
            )
            feed.update()
            logging.user(user, "~FCCreating newsletter feed: ~SB%s" % (feed))
            r = redis.Redis(connection_pool=settings.REDIS_PUBSUB_POOL)
            r.publish(user.username, "reload:%s" % feed.pk)

        if feed.feed_title != sender_name:
            feed.feed_title = sender_name
            feed.save()

        try:
            usersub = UserSubscription.objects.get(user=user, feed=feed)
        except UserSubscription.DoesNotExist:
            _, _, usersub = UserSubscription.add_subscription(
                user=user, feed_address=feed_address, folder="Newsletters"
            )

        story_hash = MStory.ensure_story_hash(params["signature"], feed.pk)
        story_content = self.get_content(params)
        story_content = self.clean_content(story_content)
        story_params = {
            "story_feed_id": feed.pk,
            "story_date": datetime.datetime.fromtimestamp(int(params["timestamp"])),
            "story_title": params["subject"],
            "story_content": story_content,
            "story_author_name": params["from"],
            "story_permalink": "https://%s%s"
            % (Site.objects.get_current().domain, reverse("newsletter-story", kwargs={"story_hash": story_hash})),
            "story_guid": params["signature"],
        }
        try:
            story = MStory.objects.get(story_hash=story_hash)
        except MStory.DoesNotExist:
            story = MStory(**story_params)
            story.save()

        usersub.needs_unread_recalc = True
        usersub.save()

        self.publish_to_subscribers(feed)

        MFetchHistory.add(feed_id=feed.pk, fetch_type="push")
        logging.user(user, "~FCNewsletter feed story: ~SB%s~SN / ~SB%s" % (story.story_title, feed))

        return story
开发者ID:jklmn13,项目名称:NewsBlur,代码行数:67,代码来源:models.py


注:本文中的apps.reader.models.UserSubscription.add_subscription方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。