本文整理汇总了Python中apps.social.models.MSocialProfile.profiles方法的典型用法代码示例。如果您正苦于以下问题:Python MSocialProfile.profiles方法的具体用法?Python MSocialProfile.profiles怎么用?Python MSocialProfile.profiles使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类apps.social.models.MSocialProfile
的用法示例。
在下文中一共展示了MSocialProfile.profiles方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: load_user_friends
# 需要导入模块: from apps.social.models import MSocialProfile [as 别名]
# 或者: from apps.social.models.MSocialProfile import profiles [as 别名]
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,
}
示例2: profile
# 需要导入模块: from apps.social.models import MSocialProfile [as 别名]
# 或者: from apps.social.models.MSocialProfile import profiles [as 别名]
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
示例3: profile
# 需要导入模块: from apps.social.models import MSocialProfile [as 别名]
# 或者: from apps.social.models.MSocialProfile import profiles [as 别名]
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
示例4: check_share_on_site
# 需要导入模块: from apps.social.models import MSocialProfile [as 别名]
# 或者: from apps.social.models.MSocialProfile import profiles [as 别名]
def check_share_on_site(request, token):
code = 0
story_url = request.GET['story_url']
rss_url = request.GET.get('rss_url')
callback = request.GET['callback']
other_stories = None
same_stories = None
usersub = None
message = None
user = None
if not story_url:
code = -1
else:
try:
user_profile = Profile.objects.get(secret_token=token)
user = user_profile.user
except Profile.DoesNotExist:
code = -1
feed = Feed.get_feed_from_url(rss_url, create=False, fetch=False)
if not feed:
feed = Feed.get_feed_from_url(story_url, create=False, fetch=False)
if not feed:
parsed_url = urlparse.urlparse(story_url)
base_url = "%s://%s%s" % (parsed_url.scheme, parsed_url.hostname, parsed_url.path)
feed = Feed.get_feed_from_url(base_url, create=False, fetch=False)
if not feed:
feed = Feed.get_feed_from_url(base_url+'/', create=False, fetch=False)
if feed and user:
try:
usersub = UserSubscription.objects.filter(user=user, feed=feed)
except UserSubscription.DoesNotExist:
usersub = None
feed_id = feed and feed.pk
your_story, same_stories, other_stories = MSharedStory.get_shared_stories_from_site(feed_id,
user_id=user_profile.user.pk, story_url=story_url)
previous_stories = MSharedStory.objects.filter(user_id=user_profile.user.pk).order_by('-shared_date').limit(3)
previous_stories = [{
"user_id": story.user_id,
"story_title": story.story_title,
"comments": story.comments,
"shared_date": story.shared_date,
"relative_date": relative_timesince(story.shared_date),
"blurblog_permalink": story.blurblog_permalink(),
} for story in previous_stories]
user_ids = set([user_profile.user.pk])
for story in same_stories:
user_ids.add(story['user_id'])
for story in other_stories:
user_ids.add(story['user_id'])
users = {}
profiles = MSocialProfile.profiles(user_ids)
for profile in profiles:
users[profile.user_id] = {
"username": profile.username,
"photo_url": profile.photo_url,
}
logging.user(user_profile.user, "~BM~FCChecking share from site: ~SB%s" % (story_url),
request=request)
response = HttpResponse(callback + '(' + json.encode({
'code' : code,
'message' : message,
'feed' : feed,
'subscribed' : bool(usersub),
'your_story' : your_story,
'same_stories' : same_stories,
'other_stories' : other_stories,
'previous_stories' : previous_stories,
'users' : users,
}) + ')', mimetype='text/plain')
response['Access-Control-Allow-Origin'] = '*'
response['Access-Control-Allow-Methods'] = 'GET'
return response
示例5: check_share_on_site
# 需要导入模块: from apps.social.models import MSocialProfile [as 别名]
# 或者: from apps.social.models.MSocialProfile import profiles [as 别名]
def check_share_on_site(request, token):
code = 0
story_url = request.GET["story_url"]
rss_url = request.GET.get("rss_url")
callback = request.GET["callback"]
other_stories = None
same_stories = None
usersub = None
message = None
user = None
if not story_url:
code = -1
else:
try:
user_profile = Profile.objects.get(secret_token=token)
user = user_profile.user
except Profile.DoesNotExist:
code = -1
feed = Feed.get_feed_from_url(rss_url, create=False, fetch=False)
if not feed:
feed = Feed.get_feed_from_url(story_url, create=False, fetch=False)
if not feed:
parsed_url = urlparse.urlparse(story_url)
base_url = "%s://%s%s" % (parsed_url.scheme, parsed_url.hostname, parsed_url.path)
feed = Feed.get_feed_from_url(base_url, create=False, fetch=False)
if not feed:
feed = Feed.get_feed_from_url(base_url + "/", create=False, fetch=False)
if feed and user:
try:
usersub = UserSubscription.objects.filter(user=user, feed=feed)
except UserSubscription.DoesNotExist:
usersub = None
feed_id = feed and feed.pk
your_story, same_stories, other_stories = MSharedStory.get_shared_stories_from_site(
feed_id, user_id=user_profile.user.pk, story_url=story_url
)
previous_stories = MSharedStory.objects.filter(user_id=user_profile.user.pk).order_by("-shared_date").limit(3)
previous_stories = [
{
"user_id": story.user_id,
"story_title": story.story_title,
"comments": story.comments,
"shared_date": story.shared_date,
"relative_date": relative_timesince(story.shared_date),
"blurblog_permalink": story.blurblog_permalink(),
}
for story in previous_stories
]
user_ids = set([user_profile.user.pk])
for story in same_stories:
user_ids.add(story["user_id"])
for story in other_stories:
user_ids.add(story["user_id"])
users = {}
profiles = MSocialProfile.profiles(user_ids)
for profile in profiles:
users[profile.user_id] = {"username": profile.username, "photo_url": profile.photo_url}
logging.user(user_profile.user, "~BM~FCChecking share from site: ~SB%s" % (story_url), request=request)
response = HttpResponse(
callback
+ "("
+ json.encode(
{
"code": code,
"message": message,
"feed": feed,
"subscribed": bool(usersub),
"your_story": your_story,
"same_stories": same_stories,
"other_stories": other_stories,
"previous_stories": previous_stories,
"users": users,
}
)
+ ")",
mimetype="text/plain",
)
response["Access-Control-Allow-Origin"] = "*"
response["Access-Control-Allow-Methods"] = "GET"
return response