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


Python models.MSocialProfile类代码示例

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


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

示例1: 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

示例2: unfollow

def unfollow(request):
    profile = MSocialProfile.get_user(request.user.pk)
    user_id = request.POST['user_id']
    try:
        unfollow_user_id = int(user_id)
    except ValueError:
        try:
            unfollow_user_id = int(user_id.replace('social:', ''))
            unfollow_profile = MSocialProfile.get_user(unfollow_user_id)
        except (ValueError, MSocialProfile.DoesNotExist):
            unfollow_username = user_id.replace('social:', '')
            try:
                unfollow_profile = MSocialProfile.objects.get(username=unfollow_username)
            except MSocialProfile.DoesNotExist:
                raise Http404
            unfollow_user_id = unfollow_profile.user_id
        
    profile.unfollow_user(unfollow_user_id)
    unfollow_profile = MSocialProfile.get_user(unfollow_user_id)
    
    logging.user(request, "~BB~FRUnfollowing: %s" % unfollow_profile.username)
    
    return {
        'user_profile': profile.to_json(include_follows=True),
        'unfollow_profile': unfollow_profile.to_json(common_follows_with_user=request.user.pk),
    }
开发者ID:superchink,项目名称:NewsBlur,代码行数:26,代码来源:views.py

示例3: follow

def follow(request):
    profile = MSocialProfile.get_user(request.user.pk)
    user_id = request.POST['user_id']
    try:
        follow_user_id = int(user_id)
    except ValueError:
        try:
            follow_user_id = int(user_id.replace('social:', ''))
            follow_profile = MSocialProfile.get_user(follow_user_id)
        except (ValueError, MSocialProfile.DoesNotExist):
            follow_username = user_id.replace('social:', '')
            try:
                follow_profile = MSocialProfile.objects.get(username=follow_username)
            except MSocialProfile.DoesNotExist:
                raise Http404
            follow_user_id = follow_profile.user_id

    profile.follow_user(follow_user_id)
    follow_profile = MSocialProfile.get_user(follow_user_id)
    
    social_params = {
        'user_id': request.user.pk,
        'subscription_user_id': follow_user_id,
        'include_favicon': True,
        'update_counts': True,
    }
    follow_subscription = MSocialSubscription.feeds(calculate_scores=True, **social_params)
    
    logging.user(request, "~BB~FRFollowing: %s" % follow_profile.username)
    
    return {
        "user_profile": profile.to_json(include_follows=True), 
        "follow_profile": follow_profile.to_json(common_follows_with_user=request.user.pk),
        "follow_subscription": follow_subscription,
    }
开发者ID:superchink,项目名称:NewsBlur,代码行数:35,代码来源:views.py

示例4: load_user_friends

def load_user_friends(request):
    user = get_user(request.user)
    social_profile, _ = MSocialProfile.objects.get_or_create(user_id=user.pk)
    social_services, _ = MSocialServices.objects.get_or_create(user_id=user.pk)
    following_profiles = MSocialProfile.profiles(social_profile.following_user_ids)
    follower_profiles = MSocialProfile.profiles(social_profile.follower_user_ids)
    recommended_users = social_profile.recommended_users()

    following_profiles = [p.to_json(include_following_user=user.pk) for p in following_profiles]
    follower_profiles = [p.to_json(include_following_user=user.pk) for p in follower_profiles]

    logging.user(
        request,
        "~BB~FRLoading Friends (%s following, %s followers)"
        % (social_profile.following_count, social_profile.follower_count),
    )

    return {
        "services": social_services,
        "autofollow": social_services.autofollow,
        "user_profile": social_profile.to_json(include_follows=True),
        "following_profiles": following_profiles,
        "follower_profiles": follower_profiles,
        "recommended_users": recommended_users,
    }
开发者ID:yoyo2k,项目名称:NewsBlur,代码行数:25,代码来源:views.py

示例5: save

    def save(self, profile_callback=None):
        username = self.cleaned_data['username']
        new_password = self.cleaned_data.get('new_password', None)
        old_password = self.cleaned_data.get('old_password', None)
        email = self.cleaned_data.get('email', None)
        custom_css = self.cleaned_data.get('custom_css', None)
        custom_js = self.cleaned_data.get('custom_js', None)
        
        if username and self.user.username != username:
            change_password(self.user, self.user.username, username)
            self.user.username = username
            self.user.save()
            social_profile = MSocialProfile.get_user(self.user.pk)
            social_profile.username = username
            social_profile.save()

        
        if self.user.email != email:
            self.user.email = email
            self.user.save()
            
            sp = MSocialProfile.get_user(self.user.pk)
            sp.email = email
            sp.save()
        
        if old_password or new_password:
            change_password(self.user, old_password, new_password)
        
        MCustomStyling.save_user(self.user.pk, custom_css, custom_js)
开发者ID:PKRoma,项目名称:NewsBlur,代码行数:29,代码来源:forms.py

示例6: render_recommended_users

def render_recommended_users(context):
    user    = get_user(context['user'])
    profile = MSocialProfile.profile(user.pk)

    return {
        'user': user,
        'profile': profile,
    }
开发者ID:1761461582,项目名称:NewsBlur,代码行数:8,代码来源:utils_tags.py

示例7: render_feeds_skeleton

def render_feeds_skeleton(context):
    user = get_user(context['user'])
    social_profile = MSocialProfile.get_user(user.pk)

    return {
        'user': user,
        'social_profile': social_profile,
        'MEDIA_URL': settings.MEDIA_URL,
    }
开发者ID:1761461582,项目名称:NewsBlur,代码行数:9,代码来源:utils_tags.py

示例8: render_getting_started

def render_getting_started(context):
    user    = get_user(context['user'])
    profile = MSocialProfile.profile(user.pk)

    return {
        'user': user,
        'user_profile': user.profile,
        'social_profile': profile,
    }
开发者ID:1761461582,项目名称:NewsBlur,代码行数:9,代码来源:utils_tags.py

示例9: load_user_profile

def load_user_profile(request):
    social_profile = MSocialProfile.get_user(request.user.pk)
    social_services, _ = MSocialServices.objects.get_or_create(user_id=request.user.pk)
    
    logging.user(request, "~BB~FRLoading social profile and blurblog settings")
    
    return {
        'services': social_services,
        'user_profile': social_profile.to_json(include_follows=True, include_settings=True),
    }
开发者ID:superchink,项目名称:NewsBlur,代码行数:10,代码来源:views.py

示例10: save_blurblog_settings

def save_blurblog_settings(request):
    data = request.POST

    profile = MSocialProfile.get_user(request.user.pk)
    profile.custom_css = data.get('custom_css', None)
    profile.custom_bgcolor = data.get('custom_bgcolor', None)
    profile.blurblog_title = data.get('blurblog_title', None)
    profile.save()

    logging.user(request, "~BB~FRSaving blurblog settings")
    
    return dict(code=1, user_profile=profile.to_json(include_follows=True, include_settings=True))
开发者ID:superchink,项目名称:NewsBlur,代码行数:12,代码来源:views.py

示例11: shared_stories_rss_feed

def shared_stories_rss_feed(request, user_id, username):
    try:
        user = User.objects.get(pk=user_id)
    except User.DoesNotExist:
        raise Http404

    username = username and username.lower()
    profile = MSocialProfile.get_user(user.pk)
    if not username or profile.username_slug.lower() != username:
        params = {"username": profile.username_slug, "user_id": user.pk}
        return HttpResponseRedirect(reverse("shared-stories-rss-feed", kwargs=params))

    social_profile = MSocialProfile.get_user(user_id)

    data = {}
    data["title"] = social_profile.title
    data["link"] = social_profile.blurblog_url
    data["description"] = "Stories shared by %s on NewsBlur." % user.username
    data["lastBuildDate"] = datetime.datetime.utcnow()
    data["items"] = []
    data["generator"] = "NewsBlur"
    data["docs"] = None

    shared_stories = MSharedStory.objects.filter(user_id=user.pk).order_by("-shared_date")[:25]
    for shared_story in shared_stories:
        story_data = {
            "title": shared_story.story_title,
            "link": shared_story.story_permalink,
            "description": shared_story.story_content_z and zlib.decompress(shared_story.story_content_z),
            "author": shared_story.story_author_name,
            "categories": shared_story.story_tags,
            "guid": shared_story.story_guid,
            "pubDate": shared_story.shared_date,
        }
        data["items"].append(RSS.RSSItem(**story_data))

    rss = RSS.RSS2(**data)

    return HttpResponse(rss.to_xml())
开发者ID:yoyo2k,项目名称:NewsBlur,代码行数:39,代码来源:views.py

示例12: shared_stories_rss_feed

def shared_stories_rss_feed(request, user_id, username):
    try:
        user = User.objects.get(pk=user_id)
    except User.DoesNotExist:
        raise Http404
    
    username = username and username.lower()
    profile = MSocialProfile.get_user(user.pk)
    if not username or profile.username_slug.lower() != username:
        params = {'username': profile.username_slug, 'user_id': user.pk}
        return HttpResponseRedirect(reverse('shared-stories-rss-feed', kwargs=params))

    social_profile = MSocialProfile.get_user(user_id)

    data = {}
    data['title'] = social_profile.title
    data['link'] = social_profile.blurblog_url
    data['description'] = "Stories shared by %s on NewsBlur." % user.username
    data['lastBuildDate'] = datetime.datetime.utcnow()
    data['items'] = []
    data['generator'] = 'NewsBlur'
    data['docs'] = None

    shared_stories = MSharedStory.objects.filter(user_id=user.pk).order_by('-shared_date')[:25]
    for shared_story in shared_stories:
        story_data = {
            'title': shared_story.story_title,
            'link': shared_story.story_permalink,
            'description': shared_story.story_content_z and zlib.decompress(shared_story.story_content_z),
            'author': shared_story.story_author_name,
            'categories': shared_story.story_tags,
            'guid': shared_story.story_guid,
            'pubDate': shared_story.shared_date,
        }
        data['items'].append(RSS.RSSItem(**story_data))
        
    rss = RSS.RSS2(**data)
    
    return HttpResponse(rss.to_xml())
开发者ID:superchink,项目名称:NewsBlur,代码行数:39,代码来源:views.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: set_account_settings

def set_account_settings(request):
    code = 1
    message = ''
    post_settings = request.POST
    
    if post_settings['username'] and request.user.username != post_settings['username']:
        try:
            User.objects.get(username__iexact=post_settings['username'])
        except User.DoesNotExist:
            request.user.username = post_settings['username']
            request.user.save()
            social_profile = MSocialProfile.get_user(request.user.pk)
            social_profile.username = post_settings['username']
            social_profile.save()
        else:
            code = -1
            message = "This username is already taken. Try something different."
    
    if request.user.email != post_settings['email']:
        if not post_settings['email'] or not User.objects.filter(email=post_settings['email']).count():
            request.user.email = post_settings['email']
            request.user.save()
        else:
            code = -2
            message = "This email is already being used by another account. Try something different."
        
    if code != -1 and (post_settings['old_password'] or post_settings['new_password']):
        code = change_password(request.user, post_settings['old_password'], post_settings['new_password'])
        if code == -3:
            message = "Your old password is incorrect."
    
    payload = {
        "username": request.user.username,
        "email": request.user.email,
        "social_profile": MSocialProfile.profile(request.user.pk)
    }
    return dict(code=code, message=message, payload=payload)
开发者ID:0077cc,项目名称:NewsBlur,代码行数:37,代码来源:views.py

示例15: save_user_profile

def save_user_profile(request):
    data = request.POST

    profile = MSocialProfile.get_user(request.user.pk)
    profile.location = data['location']
    profile.bio = data['bio']
    profile.website = data['website']
    profile.save()

    social_services = MSocialServices.objects.get(user_id=request.user.pk)
    profile = social_services.set_photo(data['photo_service'])
    
    logging.user(request, "~BB~FRSaving social profile")
    
    return dict(code=1, user_profile=profile.to_json(include_follows=True))
开发者ID:superchink,项目名称:NewsBlur,代码行数:15,代码来源:views.py


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