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


Python models.MActivity类代码示例

本文整理汇总了Python中apps.social.models.MActivity的典型用法代码示例。如果您正苦于以下问题:Python MActivity类的具体用法?Python MActivity怎么用?Python MActivity使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


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

示例1: save

    def save(self, profile_callback=None):
        username = self.cleaned_data['username']
        password = self.cleaned_data['password']

        email = self.cleaned_data.get('email', None)
        if email:
            email_exists = User.objects.filter(email__iexact=email).count()
            if email_exists:
                raise forms.ValidationError(_(u'Someone is already using that email address.'))

        exists = User.objects.filter(username__iexact=username).count()
        if exists:
            user_auth = authenticate(username=username, password=password)
            if not user_auth:
                raise forms.ValidationError(_(u'Someone is already using that username.'))
            else:
                return user_auth
            
        new_user = User(username=username)
        new_user.set_password(password)
        new_user.is_active = True
        new_user.email = email
        new_user.save()
        new_user = authenticate(username=username,
                                password=password)
        
        MActivity.new_signup(user_id=new_user.pk)
        
        if new_user.email:
            EmailNewUser.delay(user_id=new_user.pk)
        
        return new_user
开发者ID:lgp171188,项目名称:NewsBlur,代码行数:32,代码来源:forms.py

示例2: add_subscription

    def add_subscription(cls, user, feed_address, folder=None, bookmarklet=False, auto_active=True,
                         skip_fetch=False):
        feed = None
        us = None
    
        logging.user(user, "~FRAdding URL: ~SB%s (in %s) %s" % (feed_address, folder, 
                                                                "~FCAUTO-ADD" if not auto_active else ""))
    
        feed = Feed.get_feed_from_url(feed_address)

        if not feed:    
            code = -1
            if bookmarklet:
                message = "This site does not have an RSS feed. Nothing is linked to from this page."
            else:
                message = "This address does not point to an RSS feed or a website with an RSS feed."
        else:
            us, subscription_created = cls.objects.get_or_create(
                feed=feed, 
                user=user,
                defaults={
                    'needs_unread_recalc': True,
                    'active': auto_active,
                }
            )
            code = 1
            message = ""
    
        if us:
            user_sub_folders_object, created = UserSubscriptionFolders.objects.get_or_create(
                user=user,
                defaults={'folders': '[]'}
            )
            if created:
                user_sub_folders = []
            else:
                user_sub_folders = json.decode(user_sub_folders_object.folders)
            user_sub_folders = add_object_to_folder(feed.pk, folder, user_sub_folders)
            user_sub_folders_object.folders = json.encode(user_sub_folders)
            user_sub_folders_object.save()
            
            if auto_active or user.profile.is_premium:
                us.active = True
                us.save()
        
            if not skip_fetch and feed.last_update < datetime.datetime.utcnow() - datetime.timedelta(days=1):
                feed = feed.update()
            
            from apps.social.models import MActivity
            MActivity.new_feed_subscription(user_id=user.pk, feed_id=feed.pk, feed_title=feed.title)
                
            feed.setup_feed_for_premium_subscribers()
        
        return code, message, us
开发者ID:TKupels,项目名称:NewsBlur,代码行数:54,代码来源:models.py

示例3: run

 def run(self, user_id):
     UserSubscription.trim_user_read_stories(user_id)
     UserSubscription.verify_feeds_scheduled(user_id)
     Profile.count_all_feed_subscribers_for_user(user_id)
     MInteraction.trim(user_id)
     MActivity.trim(user_id)
     # UserSubscription.refresh_stale_feeds(user_id)
     
     try:
         ss = MSocialServices.objects.get(user_id=user_id)
     except MSocialServices.DoesNotExist:
         logging.debug(" ---> ~FRCleaning up user, can't find social_services for user_id: ~SB%s" % user_id)
         return
     ss.sync_twitter_photo()
开发者ID:wizos,项目名称:NewsBlur,代码行数:14,代码来源:tasks.py

示例4: profile

def profile(request):
    user = get_user(request.user)
    user_id = request.GET.get('user_id', user.pk)
    include_activities_html = request.REQUEST.get('include_activities_html', None)

    user_profile = MSocialProfile.get_user(user_id)
    user_profile.count_follows()
    user_profile = user_profile.to_json(include_follows=True, common_follows_with_user=user.pk)
    profile_ids = set(user_profile['followers_youknow'] + user_profile['followers_everybody'] + 
                      user_profile['following_youknow'] + user_profile['following_everybody'])
    profiles = MSocialProfile.profiles(profile_ids)
    activities, _ = MActivity.user(user_id, page=1, public=True)
    logging.user(request, "~BB~FRLoading social profile: %s" % user_profile['username'])
        
    payload = {
        'user_profile': user_profile,
        # XXX TODO: Remove following 4 vestigial params.
        'followers_youknow': user_profile['followers_youknow'],
        'followers_everybody': user_profile['followers_everybody'],
        'following_youknow': user_profile['following_youknow'],
        'following_everybody': user_profile['following_everybody'],
        'profiles': dict([(p.user_id, p.to_json(compact=True)) for p in profiles]),
        'activities': activities,
    }
    
    if include_activities_html:
        payload['activities_html'] = render_to_string('reader/activities_module.xhtml', {
            'activities': activities,
            'username': user_profile['username'],
            'public': True,
        })
    
    return payload
开发者ID:superchink,项目名称:NewsBlur,代码行数:33,代码来源:views.py

示例5: load_activities

def load_activities(request):
    user_id = request.REQUEST.get("user_id", None)
    if user_id:
        user_id = int(user_id)
        user = User.objects.get(pk=user_id)
    else:
        user = get_user(request)
        user_id = user.pk

    public = user_id != request.user.pk
    page = max(1, int(request.REQUEST.get("page", 1)))
    limit = request.REQUEST.get("limit", 4)
    activities, has_next_page = MActivity.user(user_id, page=page, limit=limit, public=public)
    format = request.REQUEST.get("format", None)

    data = {
        "activities": activities,
        "page": page,
        "has_next_page": has_next_page,
        "username": (user.username if public else "You"),
    }

    if format == "html":
        return render_to_response("reader/activities_module.xhtml", data, context_instance=RequestContext(request))
    else:
        return json.json_response(request, data)
开发者ID:yoyo2k,项目名称:NewsBlur,代码行数:26,代码来源:views.py

示例6: load_activities

def load_activities(request):
    user_id = request.REQUEST.get('user_id', None)
    if user_id:
        user_id = int(user_id)
        user = User.objects.get(pk=user_id)
    else:
        user = get_user(request)
        user_id = user.pk
        
    public = user_id != request.user.pk
    page = max(1, int(request.REQUEST.get('page', 1)))
    limit = request.REQUEST.get('limit', 4)
    activities, has_next_page = MActivity.user(user_id, page=page, limit=limit, public=public)
    format = request.REQUEST.get('format', None)
    
    data = {
        'activities': activities,
        'page': page,
        'has_next_page': has_next_page,
        'username': (user.username if public else 'You'),
    }
    
    if format == 'html':
        return render_to_response('reader/activities_module.xhtml', data,
                                  context_instance=RequestContext(request))
    else:
        return json.json_response(request, data)
开发者ID:superchink,项目名称:NewsBlur,代码行数:27,代码来源:views.py

示例7: like_comment

def like_comment(request):
    code     = 1
    feed_id  = int(request.POST['story_feed_id'])
    story_id = request.POST['story_id']
    comment_user_id = request.POST['comment_user_id']
    format = request.REQUEST.get('format', 'json')
    
    if comment_user_id == request.user.pk:
        return json.json_response(request, {'code': -1, 'message': 'You cannot favorite your own shared story comment.'})
        
    shared_story = MSharedStory.objects.get(user_id=comment_user_id, 
                                            story_feed_id=feed_id, 
                                            story_guid=story_id)
    shared_story.add_liking_user(request.user.pk)
    comment, profiles = shared_story.comment_with_author_and_profiles()

    comment_user = User.objects.get(pk=shared_story.user_id)
    logging.user(request, "~BB~FMLiking comment by ~SB%s~SN: %s" % (
        comment_user.username, 
        shared_story.comments[:30],
    ))

    MActivity.new_comment_like(liking_user_id=request.user.pk,
                               comment_user_id=comment['user_id'],
                               story_id=story_id,
                               story_title=shared_story.story_title,
                               comments=shared_story.comments)
    MInteraction.new_comment_like(liking_user_id=request.user.pk, 
                                  comment_user_id=comment['user_id'],
                                  story_id=story_id,
                                  story_title=shared_story.story_title,
                                  comments=shared_story.comments)
                                       
    if format == 'html':
        comment = MSharedStory.attach_users_to_comment(comment, profiles)
        return render_to_response('social/story_comment.xhtml', {
            'comment': comment,
        }, context_instance=RequestContext(request))
    else:
        return json.json_response(request, {
            'code': code, 
            'comment': comment, 
            'user_profiles': profiles,
        })
开发者ID:superchink,项目名称:NewsBlur,代码行数:44,代码来源:views.py

示例8: save

    def save(self, profile_callback=None):
        username = self.cleaned_data['username']
        password = self.cleaned_data['password']

        email = self.cleaned_data.get('email', None)
        if email:
            email_exists = User.objects.filter(email__iexact=email).count()
            if email_exists:
                raise forms.ValidationError(_(u'Someone is already using that email address.'))

        exists = User.objects.filter(username__iexact=username).count()
        if exists:
            user_auth = authenticate(username=username, password=password)
            if not user_auth:
                raise forms.ValidationError(_(u'Someone is already using that username.'))
            else:
                return user_auth
        
        if not password:
            password = username
            
        new_user = User(username=username)
        new_user.set_password(password)
        new_user.is_active = False
        new_user.email = email
        new_user.save()
        new_user = authenticate(username=username,
                                password=password)
        
        MActivity.new_signup(user_id=new_user.pk)
        
        RNewUserQueue.add_user(new_user.pk)
        
        if new_user.email:
            EmailNewUser.delay(user_id=new_user.pk)
        
        if getattr(settings, 'AUTO_PREMIUM_NEW_USERS', False):
            new_user.profile.activate_premium()
        elif getattr(settings, 'AUTO_ENABLE_NEW_USERS', False):
            new_user.profile.activate_free()
        
        return new_user
开发者ID:1059232202,项目名称:NewsBlur,代码行数:42,代码来源:forms.py

示例9: load_activities

def load_activities(request):
    user = get_user(request)
    page = max(1, int(request.REQUEST.get('page', 1)))
    activities, has_next_page = MActivity.user(user.pk, page=page)

    return {
        'activities': activities,
        'page': page,
        'has_next_page': has_next_page,
        'username': '你',
    }
开发者ID:linuxayn,项目名称:NewsBlur,代码行数:11,代码来源:views.py

示例10: save

    def save(self, profile_callback=None):
        username = self.cleaned_data["username"]
        password = self.cleaned_data["password"]

        email = self.cleaned_data.get("email", None)
        if email:
            email_exists = User.objects.filter(email__iexact=email).count()
            if email_exists:
                raise forms.ValidationError(_(u"此邮件地址已经被使用。"))

        exists = User.objects.filter(username__iexact=username).count()
        if exists:
            user_auth = authenticate(username=username, password=password)
            if not user_auth:
                raise forms.ValidationError(_(u"此用户名已经被使用。"))
            else:
                return user_auth

        if not password:
            password = username

        new_user = User(username=username)
        new_user.set_password(password)
        new_user.is_active = False
        new_user.email = email
        new_user.save()
        new_user = authenticate(username=username, password=password)

        MActivity.new_signup(user_id=new_user.pk)

        RNewUserQueue.add_user(new_user.pk)

        if new_user.email:
            EmailNewUser.delay(user_id=new_user.pk)

        if getattr(settings, "AUTO_PREMIUM_NEW_USERS", False):
            new_user.profile.activate_premium()
        elif getattr(settings, "AUTO_ENABLE_NEW_USERS", False):
            new_user.profile.activate_free()

        return new_user
开发者ID:bruceyou,项目名称:NewsBlur,代码行数:41,代码来源:forms.py

示例11: like_comment

def like_comment(request):
    code = 1
    feed_id = int(request.POST["story_feed_id"])
    story_id = request.POST["story_id"]
    comment_user_id = request.POST["comment_user_id"]
    format = request.REQUEST.get("format", "json")

    if comment_user_id == request.user.pk:
        return json.json_response(
            request, {"code": -1, "message": "You cannot favorite your own shared story comment."}
        )

    shared_story = MSharedStory.objects.get(user_id=comment_user_id, story_feed_id=feed_id, story_guid=story_id)
    shared_story.add_liking_user(request.user.pk)
    comment, profiles = shared_story.comment_with_author_and_profiles()

    comment_user = User.objects.get(pk=shared_story.user_id)
    logging.user(request, "~BB~FMLiking comment by ~SB%s~SN: %s" % (comment_user.username, shared_story.comments[:30]))

    MActivity.new_comment_like(
        liking_user_id=request.user.pk,
        comment_user_id=comment["user_id"],
        story_id=story_id,
        story_title=shared_story.story_title,
        comments=shared_story.comments,
    )
    MInteraction.new_comment_like(
        liking_user_id=request.user.pk,
        comment_user_id=comment["user_id"],
        story_id=story_id,
        story_title=shared_story.story_title,
        comments=shared_story.comments,
    )

    if format == "html":
        comment = MSharedStory.attach_users_to_comment(comment, profiles)
        return render_to_response(
            "social/story_comment.xhtml", {"comment": comment}, context_instance=RequestContext(request)
        )
    else:
        return json.json_response(request, {"code": code, "comment": comment, "user_profiles": profiles})
开发者ID:yoyo2k,项目名称:NewsBlur,代码行数:41,代码来源:views.py

示例12: render_activities_module

def render_activities_module(context, page=1):
    user = get_user(context['user'])
    activities, has_next_page = MActivity.user(user.pk, page)
    
    return {
        'user': user,
        'activities': activities,
        'page': page,
        'has_next_page': has_next_page,
        'username': 'You',
        'MEDIA_URL': context['MEDIA_URL'],
    }
开发者ID:0077cc,项目名称:NewsBlur,代码行数:12,代码来源:utils_tags.py

示例13: profile

def profile(request):
    user = get_user(request.user)
    user_id = request.GET.get("user_id", user.pk)
    categories = request.GET.getlist("category")
    include_activities_html = request.REQUEST.get("include_activities_html", None)

    user_profile = MSocialProfile.get_user(user_id)
    user_profile.count_follows()
    user_profile = user_profile.to_json(include_follows=True, common_follows_with_user=user.pk)
    profile_ids = set(
        user_profile["followers_youknow"]
        + user_profile["followers_everybody"]
        + user_profile["following_youknow"]
        + user_profile["following_everybody"]
    )
    profiles = MSocialProfile.profiles(profile_ids)
    activities, _ = MActivity.user(user_id, page=1, public=True, categories=categories)
    logging.user(request, "~BB~FRLoading social profile: %s" % user_profile["username"])

    payload = {
        "user_profile": user_profile,
        # XXX TODO: Remove following 4 vestigial params.
        "followers_youknow": user_profile["followers_youknow"],
        "followers_everybody": user_profile["followers_everybody"],
        "following_youknow": user_profile["following_youknow"],
        "following_everybody": user_profile["following_everybody"],
        "profiles": dict([(p.user_id, p.to_json(compact=True)) for p in profiles]),
        "activities": activities,
    }

    if include_activities_html:
        payload["activities_html"] = render_to_string(
            "reader/activities_module.xhtml",
            {"activities": activities, "username": user_profile["username"], "public": True},
        )

    return payload
开发者ID:eric011,项目名称:NewsBlur,代码行数:37,代码来源:views.py

示例14: remove_comment_reply

def remove_comment_reply(request):
    code     = 1
    feed_id  = int(request.POST['story_feed_id'])
    story_id = request.POST['story_id']
    comment_user_id = request.POST['comment_user_id']
    reply_id = request.POST.get('reply_id')
    format = request.REQUEST.get('format', 'json')
    original_message = None
    
    shared_story = MSharedStory.objects.get(user_id=comment_user_id, 
                                            story_feed_id=feed_id, 
                                            story_guid=story_id)
    replies = []
    for story_reply in shared_story.replies:
        if ((story_reply.user_id == request.user.pk or request.user.is_staff) and 
            story_reply.reply_id == ObjectId(reply_id)):
            original_message = story_reply.comments
            # Skip reply
        else:
            replies.append(story_reply)
    shared_story.replies = replies
    shared_story.save()

    logging.user(request, "~FCRemoving comment reply in ~FM%s: ~SB~FB%s~FM" % (
             shared_story.story_title[:20], original_message and original_message[:30]))
    
    comment, profiles = shared_story.comment_with_author_and_profiles()

    # Interaction for every other replier and original commenter
    MActivity.remove_comment_reply(user_id=request.user.pk,
                                   comment_user_id=comment['user_id'],
                                   reply_content=original_message,
                                   story_id=story_id,
                                   story_feed_id=feed_id)
    MInteraction.remove_comment_reply(user_id=comment['user_id'], 
                                      reply_user_id=request.user.pk, 
                                      reply_content=original_message,
                                      story_id=story_id,
                                      story_feed_id=feed_id)
    
    reply_user_ids = [reply['user_id'] for reply in comment['replies']]
    for user_id in set(reply_user_ids).difference([comment['user_id']]):
        if request.user.pk != user_id:
            MInteraction.remove_reply_reply(user_id=user_id, 
                                            comment_user_id=comment['user_id'],
                                            reply_user_id=request.user.pk, 
                                            reply_content=original_message,
                                            story_id=story_id,
                                            story_feed_id=feed_id)
    
    if format == 'html':
        comment = MSharedStory.attach_users_to_comment(comment, profiles)
        return render_to_response('social/story_comment.xhtml', {
            'comment': comment,
        }, context_instance=RequestContext(request))
    else:
        return json.json_response(request, {
            'code': code, 
            'comment': comment, 
            'user_profiles': profiles
        })
开发者ID:superchink,项目名称:NewsBlur,代码行数:61,代码来源:views.py

示例15: remove_comment_reply

def remove_comment_reply(request):
    code = 1
    feed_id = int(request.POST["story_feed_id"])
    story_id = request.POST["story_id"]
    comment_user_id = request.POST["comment_user_id"]
    reply_id = request.POST.get("reply_id")
    format = request.REQUEST.get("format", "json")
    original_message = None

    shared_story = MSharedStory.objects.get(user_id=comment_user_id, story_feed_id=feed_id, story_guid=story_id)
    replies = []
    for story_reply in shared_story.replies:
        if (story_reply.user_id == request.user.pk or request.user.is_staff) and story_reply.reply_id == ObjectId(
            reply_id
        ):
            original_message = story_reply.comments
            # Skip reply
        else:
            replies.append(story_reply)
    shared_story.replies = replies
    shared_story.save()

    logging.user(
        request,
        "~FCRemoving comment reply in ~FM%s: ~SB~FB%s~FM"
        % (shared_story.story_title[:20], original_message and original_message[:30]),
    )

    comment, profiles = shared_story.comment_with_author_and_profiles()

    # Interaction for every other replier and original commenter
    MActivity.remove_comment_reply(
        user_id=request.user.pk,
        comment_user_id=comment["user_id"],
        reply_content=original_message,
        story_id=story_id,
        story_feed_id=feed_id,
    )
    MInteraction.remove_comment_reply(
        user_id=comment["user_id"],
        reply_user_id=request.user.pk,
        reply_content=original_message,
        story_id=story_id,
        story_feed_id=feed_id,
    )

    reply_user_ids = [reply["user_id"] for reply in comment["replies"]]
    for user_id in set(reply_user_ids).difference([comment["user_id"]]):
        if request.user.pk != user_id:
            MInteraction.remove_reply_reply(
                user_id=user_id,
                comment_user_id=comment["user_id"],
                reply_user_id=request.user.pk,
                reply_content=original_message,
                story_id=story_id,
                story_feed_id=feed_id,
            )

    if format == "html":
        comment = MSharedStory.attach_users_to_comment(comment, profiles)
        return render_to_response(
            "social/story_comment.xhtml", {"comment": comment}, context_instance=RequestContext(request)
        )
    else:
        return json.json_response(request, {"code": code, "comment": comment, "user_profiles": profiles})
开发者ID:yoyo2k,项目名称:NewsBlur,代码行数:65,代码来源:views.py


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