本文整理汇总了Python中apps.social.models.MSocialProfile.get_user方法的典型用法代码示例。如果您正苦于以下问题:Python MSocialProfile.get_user方法的具体用法?Python MSocialProfile.get_user怎么用?Python MSocialProfile.get_user使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类apps.social.models.MSocialProfile
的用法示例。
在下文中一共展示了MSocialProfile.get_user方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: follow
# 需要导入模块: from apps.social.models import MSocialProfile [as 别名]
# 或者: from apps.social.models.MSocialProfile import get_user [as 别名]
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,
}
示例2: unfollow
# 需要导入模块: from apps.social.models import MSocialProfile [as 别名]
# 或者: from apps.social.models.MSocialProfile import get_user [as 别名]
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),
}
示例3: save
# 需要导入模块: from apps.social.models import MSocialProfile [as 别名]
# 或者: from apps.social.models.MSocialProfile import get_user [as 别名]
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)
示例4: profile
# 需要导入模块: from apps.social.models import MSocialProfile [as 别名]
# 或者: from apps.social.models.MSocialProfile import get_user [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
示例5: render_feeds_skeleton
# 需要导入模块: from apps.social.models import MSocialProfile [as 别名]
# 或者: from apps.social.models.MSocialProfile import get_user [as 别名]
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,
}
示例6: load_user_profile
# 需要导入模块: from apps.social.models import MSocialProfile [as 别名]
# 或者: from apps.social.models.MSocialProfile import get_user [as 别名]
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),
}
示例7: save_blurblog_settings
# 需要导入模块: from apps.social.models import MSocialProfile [as 别名]
# 或者: from apps.social.models.MSocialProfile import get_user [as 别名]
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))
示例8: shared_stories_rss_feed
# 需要导入模块: from apps.social.models import MSocialProfile [as 别名]
# 或者: from apps.social.models.MSocialProfile import get_user [as 别名]
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())
示例9: shared_stories_rss_feed
# 需要导入模块: from apps.social.models import MSocialProfile [as 别名]
# 或者: from apps.social.models.MSocialProfile import get_user [as 别名]
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())
示例10: save_user_profile
# 需要导入模块: from apps.social.models import MSocialProfile [as 别名]
# 或者: from apps.social.models.MSocialProfile import get_user [as 别名]
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))
示例11: social_feed_trainer
# 需要导入模块: from apps.social.models import MSocialProfile [as 别名]
# 或者: from apps.social.models.MSocialProfile import get_user [as 别名]
def social_feed_trainer(request):
social_user_id = request.REQUEST.get("user_id")
social_profile = MSocialProfile.get_user(social_user_id)
social_user = get_object_or_404(User, pk=social_user_id)
user = get_user(request)
social_profile.count_stories()
classifier = social_profile.to_json()
classifier["classifiers"] = get_classifiers_for_user(user, social_user_id=classifier["id"])
classifier["num_subscribers"] = social_profile.follower_count
classifier["feed_tags"] = []
classifier["feed_authors"] = []
logging.user(user, "~FGLoading social trainer on ~SB%s: %s" % (social_user.username, social_profile.title))
return [classifier]
示例12: add_site_load_script
# 需要导入模块: from apps.social.models import MSocialProfile [as 别名]
# 或者: from apps.social.models.MSocialProfile import get_user [as 别名]
def add_site_load_script(request, token):
code = 0
usf = None
profile = None
user_profile = None
def image_base64(image_name, path="icons/circular/"):
image_file = open(os.path.join(settings.MEDIA_ROOT, "img/%s%s" % (path, image_name)))
return base64.b64encode(image_file.read())
accept_image = image_base64("newuser_icn_setup.png")
error_image = image_base64("newuser_icn_sharewith_active.png")
new_folder_image = image_base64("g_icn_arrow_right.png")
add_image = image_base64("g_icn_expand_hover.png")
try:
profiles = Profile.objects.filter(secret_token=token)
if profiles:
profile = profiles[0]
usf = UserSubscriptionFolders.objects.get(user=profile.user)
user_profile = MSocialProfile.get_user(user_id=profile.user.pk)
else:
code = -1
except Profile.DoesNotExist:
code = -1
except UserSubscriptionFolders.DoesNotExist:
code = -1
return render_to_response(
"api/share_bookmarklet.js",
{
"code": code,
"token": token,
"folders": (usf and usf.folders) or [],
"user": profile and profile.user or {},
"user_profile": user_profile and json.encode(user_profile.canonical()) or {},
"accept_image": accept_image,
"error_image": error_image,
"add_image": add_image,
"new_folder_image": new_folder_image,
},
context_instance=RequestContext(request),
mimetype="application/javascript",
)
示例13: welcome
# 需要导入模块: from apps.social.models import MSocialProfile [as 别名]
# 或者: from apps.social.models.MSocialProfile import get_user [as 别名]
def welcome(request, **kwargs):
user = get_user(request)
statistics = MStatistics.all()
social_profile = MSocialProfile.get_user(user.pk)
if request.method == "POST":
pass
else:
login_form = LoginForm(prefix='login')
signup_form = SignupForm(prefix='signup')
return {
'user_profile': hasattr(user, 'profile') and user.profile,
'login_form': login_form,
'signup_form': signup_form,
'statistics': statistics,
'social_profile': social_profile,
'post_request': request.method == 'POST'
}, "reader/welcome.xhtml"
示例14: save_user_profile
# 需要导入模块: from apps.social.models import MSocialProfile [as 别名]
# 或者: from apps.social.models.MSocialProfile import get_user [as 别名]
def save_user_profile(request):
data = request.POST
website = data["website"]
if website and not website.startswith("http"):
website = "http://" + website
profile = MSocialProfile.get_user(request.user.pk)
profile.location = data["location"]
profile.bio = data["bio"]
profile.website = 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))
示例15: add_site_load_script
# 需要导入模块: from apps.social.models import MSocialProfile [as 别名]
# 或者: from apps.social.models.MSocialProfile import get_user [as 别名]
def add_site_load_script(request, token):
code = 0
usf = None
profile = None;
user_profile = None;
def image_base64(image_name, path='icons/silk/'):
image_file = open(os.path.join(settings.MEDIA_ROOT, 'img/%s%s' % (path, image_name)))
return base64.b64encode(image_file.read())
accept_image = image_base64('accept.png')
error_image = image_base64('error.png')
new_folder_image = image_base64('arrow_down_right.png')
add_image = image_base64('add.png')
try:
profiles = Profile.objects.filter(secret_token=token)
if profiles:
profile = profiles[0]
usf = UserSubscriptionFolders.objects.get(
user=profile.user
)
user_profile = MSocialProfile.get_user(user_id=profile.user.pk)
else:
code = -1
except Profile.DoesNotExist:
code = -1
except UserSubscriptionFolders.DoesNotExist:
code = -1
return render_to_response('api/share_bookmarklet.js', {
'code': code,
'token': token,
'folders': (usf and usf.folders) or [],
'user': profile and profile.user or {},
'user_profile': user_profile and json.encode(user_profile.to_json()) or {},
'accept_image': accept_image,
'error_image': error_image,
'add_image': add_image,
'new_folder_image': new_folder_image,
},
context_instance=RequestContext(request),
mimetype='application/javascript')