本文整理汇总了Python中utils.user_functions.get_user函数的典型用法代码示例。如果您正苦于以下问题:Python get_user函数的具体用法?Python get_user怎么用?Python get_user使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了get_user函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: load_recommended_feed
def load_recommended_feed(request):
user = get_user(request)
page = int(request.REQUEST.get('page', 0))
usersub = None
refresh = request.REQUEST.get('refresh')
now = datetime.datetime.now
unmoderated = request.REQUEST.get('unmoderated', False) == 'true'
if unmoderated:
recommended_feeds = RecommendedFeed.objects.filter(is_public=False, declined_date__isnull=True)[page:page+2]
else:
recommended_feeds = RecommendedFeed.objects.filter(is_public=True, approved_date__lte=now)[page:page+2]
if recommended_feeds and request.user.is_authenticated():
usersub = UserSubscription.objects.filter(user=user, feed=recommended_feeds[0].feed)
if refresh != 'true' and page > 0:
logging.user(request, "~FBBrowse recommended feed: ~SBPage #%s" % (page+1))
recommended_feed = recommended_feeds and recommended_feeds[0]
feed_icon = MFeedIcon.objects(feed_id=recommended_feed.feed.pk)
if recommended_feed:
return render_to_response('recommendations/render_recommended_feed.xhtml', {
'recommended_feed' : recommended_feed,
'description' : recommended_feed.description or recommended_feed.feed.data.feed_tagline,
'usersub' : usersub,
'feed_icon' : feed_icon and feed_icon[0],
'has_next_page' : len(recommended_feeds) > 1,
'has_previous_page' : page != 0,
'unmoderated' : unmoderated,
'today' : datetime.datetime.now(),
}, context_instance=RequestContext(request))
else:
return HttpResponse("")
示例2: add_site_authed
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')
示例3: load_feed_statistics
def load_feed_statistics(request, feed_id):
user = get_user(request)
stats = dict()
feed = get_object_or_404(Feed, pk=feed_id)
feed.count_subscribers()
feed.set_next_scheduled_update(verbose=True, skip_scheduling=True)
feed.save_feed_story_history_statistics()
feed.save_classifier_counts()
# Dates of last and next update
stats['active'] = feed.active
stats['last_update'] = relative_timesince(feed.last_update)
if feed.is_push:
stats['next_update'] = "real-time..."
else:
stats['next_update'] = relative_timeuntil(feed.next_scheduled_update)
# Minutes between updates
update_interval_minutes, _ = feed.get_next_scheduled_update(force=True, verbose=False)
if feed.is_push:
stats['update_interval_minutes'] = 0
else:
stats['update_interval_minutes'] = update_interval_minutes
original_active_premium_subscribers = feed.active_premium_subscribers
original_premium_subscribers = feed.premium_subscribers
feed.active_premium_subscribers = max(feed.active_premium_subscribers+1, 1)
feed.premium_subscribers += 1
premium_update_interval_minutes, _ = feed.get_next_scheduled_update(force=True, verbose=False)
feed.active_premium_subscribers = original_active_premium_subscribers
feed.premium_subscribers = original_premium_subscribers
if feed.is_push:
stats['premium_update_interval_minutes'] = 0
else:
stats['premium_update_interval_minutes'] = premium_update_interval_minutes
# Stories per month - average and month-by-month breakout
average_stories_per_month, story_count_history = feed.average_stories_per_month, feed.data.story_count_history
stats['average_stories_per_month'] = average_stories_per_month
stats['story_count_history'] = story_count_history and json.decode(story_count_history)
# Subscribers
stats['subscriber_count'] = feed.num_subscribers
stats['stories_last_month'] = feed.stories_last_month
stats['last_load_time'] = feed.last_load_time
stats['premium_subscribers'] = feed.premium_subscribers
stats['active_subscribers'] = feed.active_subscribers
stats['active_premium_subscribers'] = feed.active_premium_subscribers
# Classifier counts
stats['classifier_counts'] = json.decode(feed.data.feed_classifier_counts)
# Fetch histories
timezone = user.profile.timezone
stats['feed_fetch_history'] = MFeedFetchHistory.feed_history(feed_id, timezone=timezone)
stats['page_fetch_history'] = MPageFetchHistory.feed_history(feed_id, timezone=timezone)
stats['feed_push_history'] = MFeedPushHistory.feed_history(feed_id, timezone=timezone)
logging.user(request, "~FBStatistics: ~SB%s ~FG(%s/%s/%s subs)" % (feed, feed.num_subscribers, feed.active_subscribers, feed.premium_subscribers,))
return stats
示例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,
}
示例5: refresh_feeds
def refresh_feeds(request):
user = get_user(request)
feeds = {}
user_subs = UserSubscription.objects.select_related('feed').filter(user=user, active=True)
UNREAD_CUTOFF = datetime.datetime.utcnow() - datetime.timedelta(days=settings.DAYS_OF_UNREAD)
favicons_fetching = [int(f) for f in request.POST.getlist('favicons_fetching')]
for sub in user_subs:
if (sub.needs_unread_recalc or
sub.unread_count_updated < UNREAD_CUTOFF or
sub.oldest_unread_story_date < UNREAD_CUTOFF):
sub.calculate_feed_scores(silent=True)
feeds[sub.feed.pk] = {
'ps': sub.unread_count_positive,
'nt': sub.unread_count_neutral,
'ng': sub.unread_count_negative,
}
if sub.feed.has_feed_exception or sub.feed.has_page_exception:
feeds[sub.feed.pk]['has_exception'] = True
feeds[sub.feed.pk]['exception_type'] = 'feed' if sub.feed.has_feed_exception else 'page'
feeds[sub.feed.pk]['feed_address'] = sub.feed.feed_address
feeds[sub.feed.pk]['exception_code'] = sub.feed.exception_code
if request.POST.get('check_fetch_status', False):
feeds[sub.feed.pk]['not_yet_fetched'] = not sub.feed.fetched_once
if sub.feed.pk in favicons_fetching:
feeds[sub.feed.pk]['favicon'] = sub.feed.icon.data
feeds[sub.feed.pk]['favicon_color'] = sub.feed.icon.color
feeds[sub.feed.pk]['favicon_fetching'] = bool(not (sub.feed.icon.not_found or sub.feed.icon.data))
return {'feeds': feeds}
示例6: render_feeds_skeleton
def render_feeds_skeleton(context):
user = get_user(context['user'])
return {
'user': user,
'MEDIA_URL': settings.MEDIA_URL,
}
示例7: 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)
示例8: story_public_comments
def story_public_comments(request):
format = request.REQUEST.get('format', 'json')
relative_user_id = request.REQUEST.get('user_id', None)
feed_id = int(request.REQUEST['feed_id'])
story_id = request.REQUEST['story_id']
if not relative_user_id:
relative_user_id = get_user(request).pk
stories = MSharedStory.objects.filter(story_feed_id=feed_id, story_guid=story_id).limit(1)
stories = Feed.format_stories(stories)
stories, profiles = MSharedStory.stories_with_comments_and_profiles(stories, relative_user_id,
check_all=True,
public=True)
if format == 'html':
stories = MSharedStory.attach_users_to_stories(stories, profiles)
return render_to_response('social/story_comments.xhtml', {
'story': stories[0],
}, context_instance=RequestContext(request))
else:
return json.json_response(request, {
'comments': stories[0]['public_comments'],
'user_profiles': profiles,
})
示例9: 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
示例10: load_starred_stories
def load_starred_stories(request):
user = get_user(request)
offset = int(request.REQUEST.get('offset', 0))
limit = int(request.REQUEST.get('limit', 10))
page = int(request.REQUEST.get('page', 0))
if page: offset = limit * (page - 1)
mstories = MStarredStory.objects(user_id=user.pk).order_by('-starred_date')[offset:offset+limit]
stories = Feed.format_stories(mstories)
for story in stories:
story_date = localtime_for_timezone(story['story_date'], user.profile.timezone)
now = localtime_for_timezone(datetime.datetime.now(), user.profile.timezone)
story['short_parsed_date'] = format_story_link_date__short(story_date, now)
story['long_parsed_date'] = format_story_link_date__long(story_date, now)
starred_date = localtime_for_timezone(story['starred_date'], user.profile.timezone)
story['starred_date'] = format_story_link_date__long(starred_date, now)
story['read_status'] = 1
story['starred'] = True
story['intelligence'] = {
'feed': 0,
'author': 0,
'tags': 0,
'title': 0,
}
logging.user(request, "~FCLoading starred stories: ~SB%s stories" % (len(stories)))
return dict(stories=stories)
示例11: 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)
示例12: render_recommended_users
def render_recommended_users(context):
user = get_user(context['user'])
profile = MSocialProfile.profile(user.pk)
return {
'user': user,
'profile': profile,
}
示例13: load_feeds
def load_feeds(request):
user = get_user(request)
feeds = {}
not_yet_fetched = False
try:
folders = UserSubscriptionFolders.objects.get(user=user)
except UserSubscriptionFolders.DoesNotExist:
data = dict(feeds=[], folders=[])
return data
except UserSubscriptionFolders.MultipleObjectsReturned:
UserSubscriptionFolders.objects.filter(user=user)[1:].delete()
folders = UserSubscriptionFolders.objects.get(user=user)
user_subs = UserSubscription.objects.select_related('feed', 'feed__feed_icon').filter(user=user)
for sub in user_subs:
feeds[sub.feed.pk] = {
'id': sub.feed.pk,
'feed_title': sub.user_title or sub.feed.feed_title,
'feed_address': sub.feed.feed_address,
'feed_link': sub.feed.feed_link,
'ps': sub.unread_count_positive,
'nt': sub.unread_count_neutral,
'ng': sub.unread_count_negative,
'updated': relative_timesince(sub.feed.last_update),
'subs': sub.feed.num_subscribers,
'active': sub.active,
'favicon': sub.feed.icon.data,
'favicon_color': sub.feed.icon.color,
'favicon_fetching': bool(not (sub.feed.icon.not_found or sub.feed.icon.data))
}
if not sub.feed.fetched_once:
not_yet_fetched = True
feeds[sub.feed.pk]['not_yet_fetched'] = True
if sub.feed.has_page_exception or sub.feed.has_feed_exception:
feeds[sub.feed.pk]['has_exception'] = True
feeds[sub.feed.pk]['exception_type'] = 'feed' if sub.feed.has_feed_exception else 'page'
feeds[sub.feed.pk]['feed_address'] = sub.feed.feed_address
feeds[sub.feed.pk]['exception_code'] = sub.feed.exception_code
if not sub.feed.active and not sub.feed.has_feed_exception and not sub.feed.has_page_exception:
sub.feed.count_subscribers()
sub.feed.schedule_feed_fetch_immediately()
if not_yet_fetched:
for f in feeds:
if 'not_yet_fetched' not in feeds[f]:
feeds[f]['not_yet_fetched'] = False
starred_count = MStarredStory.objects(user_id=user.pk).count()
data = {
'feeds': feeds,
'folders': json.decode(folders.folders),
'starred_count': starred_count,
}
return data
示例14: get_classifiers_feed
def get_classifiers_feed(request, feed_id):
user = get_user(request)
code = 0
payload = get_classifiers_for_user(user, feed_id=feed_id)
response = dict(code=code, payload=payload)
return response
示例15: load_single_feed
def load_single_feed(request, feed_id):
user = get_user(request)
feed = get_object_or_404(Feed, pk=feed_id)
classifiers = get_classifiers_for_user(user, feed_id=feed.pk)
payload = feed.canonical(full=True)
payload['classifiers'] = classifiers
return payload