mirror of
				https://github.com/samuelclay/NewsBlur.git
				synced 2025-11-01 09:09:51 +00:00 
			
		
		
		
	change User.is_authenticated() and User.is_anonymous() to attributes
This commit is contained in:
		
							parent
							
								
									3f122d5e03
								
							
						
					
					
						commit
						7d95dbb5cf
					
				
					 12 changed files with 26 additions and 26 deletions
				
			
		| 
						 | 
				
			
			@ -291,7 +291,7 @@ def share_story(request, token=None):
 | 
			
		|||
    message   = None
 | 
			
		||||
    profile   = None
 | 
			
		||||
    
 | 
			
		||||
    if request.user.is_authenticated():
 | 
			
		||||
    if request.user.is_authenticated:
 | 
			
		||||
        profile = request.user.profile
 | 
			
		||||
    else:
 | 
			
		||||
        try:
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -264,7 +264,7 @@ class GoogleReaderImporter(Importer):
 | 
			
		|||
            self.process_feeds(feeds_xml)
 | 
			
		||||
        
 | 
			
		||||
    def send_request(self, url):
 | 
			
		||||
        if not self.user.is_authenticated():
 | 
			
		||||
        if not self.user.is_authenticated:
 | 
			
		||||
            return
 | 
			
		||||
            
 | 
			
		||||
        user_tokens = OAuthToken.objects.filter(user=self.user)
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -18,7 +18,7 @@ class LastSeenMiddleware(object):
 | 
			
		|||
             request.path.startswith('/reader/load_feeds') or
 | 
			
		||||
             request.path.startswith('/reader/feeds'))
 | 
			
		||||
            and hasattr(request, 'user')
 | 
			
		||||
            and request.user.is_authenticated()): 
 | 
			
		||||
            and request.user.is_authenticated): 
 | 
			
		||||
            hour_ago = datetime.datetime.utcnow() - datetime.timedelta(minutes=60)
 | 
			
		||||
            ip = request.META.get('HTTP_X_FORWARDED_FOR', None) or request.META['REMOTE_ADDR']
 | 
			
		||||
            # SUBSCRIBER_EXPIRE = datetime.datetime.utcnow() - datetime.timedelta(days=settings.SUBSCRIBER_EXPIRE)
 | 
			
		||||
| 
						 | 
				
			
			@ -287,7 +287,7 @@ class UserAgentBanMiddleware:
 | 
			
		|||
            
 | 
			
		||||
            return HttpResponse(json.encode(data), status=403, mimetype='text/json')
 | 
			
		||||
 | 
			
		||||
        if request.user.is_authenticated() and any(username == request.user.username for username in BANNED_USERNAMES):
 | 
			
		||||
        if request.user.is_authenticated and any(username == request.user.username for username in BANNED_USERNAMES):
 | 
			
		||||
            data = {
 | 
			
		||||
                'error': 'User banned: %s' % request.user.username,
 | 
			
		||||
                'code': -1
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -85,7 +85,7 @@ def index(request, **kwargs):
 | 
			
		|||
                reverse('index')))
 | 
			
		||||
        return load_social_page(request, user_id=user.pk, username=request.subdomain, **kwargs)
 | 
			
		||||
 | 
			
		||||
    if request.user.is_anonymous():
 | 
			
		||||
    if request.user.is_anonymous:
 | 
			
		||||
        return welcome(request, **kwargs)
 | 
			
		||||
    else:
 | 
			
		||||
        return dashboard(request, **kwargs)
 | 
			
		||||
| 
						 | 
				
			
			@ -288,7 +288,7 @@ def load_feeds(request):
 | 
			
		|||
        elif sub.feed.next_scheduled_update < day_ago:
 | 
			
		||||
            scheduled_feeds.append(sub.feed.pk)
 | 
			
		||||
    
 | 
			
		||||
    if len(scheduled_feeds) > 0 and request.user.is_authenticated():
 | 
			
		||||
    if len(scheduled_feeds) > 0 and request.user.is_authenticated:
 | 
			
		||||
        logging.user(request, "~SN~FMTasking the scheduling immediate fetch of ~SB%s~SN feeds..." % 
 | 
			
		||||
                     len(scheduled_feeds))
 | 
			
		||||
        ScheduleImmediateFetches.apply_async(kwargs=dict(feed_ids=scheduled_feeds, user_id=user.pk))
 | 
			
		||||
| 
						 | 
				
			
			@ -362,7 +362,7 @@ def load_feeds_flat(request):
 | 
			
		|||
    if include_favicons == 'false': include_favicons = False
 | 
			
		||||
    if update_counts == 'false': update_counts = False
 | 
			
		||||
    
 | 
			
		||||
    if not user.is_authenticated():
 | 
			
		||||
    if not user.is_authenticated:
 | 
			
		||||
        return HttpResponseForbidden()
 | 
			
		||||
    
 | 
			
		||||
    try:
 | 
			
		||||
| 
						 | 
				
			
			@ -397,7 +397,7 @@ def load_feeds_flat(request):
 | 
			
		|||
        for sub in inactive_subs:
 | 
			
		||||
            inactive_feeds[sub.feed_id] = sub.canonical(include_favicon=include_favicons)
 | 
			
		||||
    
 | 
			
		||||
    if len(scheduled_feeds) > 0 and request.user.is_authenticated():
 | 
			
		||||
    if len(scheduled_feeds) > 0 and request.user.is_authenticated:
 | 
			
		||||
        logging.user(request, "~SN~FMTasking the scheduling immediate fetch of ~SB%s~SN feeds..." % 
 | 
			
		||||
                     len(scheduled_feeds))
 | 
			
		||||
        ScheduleImmediateFetches.apply_async(kwargs=dict(feed_ids=scheduled_feeds, user_id=user.pk))
 | 
			
		||||
| 
						 | 
				
			
			@ -1943,9 +1943,9 @@ def mark_feed_as_read(request):
 | 
			
		|||
def _parse_user_info(user):
 | 
			
		||||
    return {
 | 
			
		||||
        'user_info': {
 | 
			
		||||
            'is_anonymous': json.encode(user.is_anonymous()),
 | 
			
		||||
            'is_authenticated': json.encode(user.is_authenticated()),
 | 
			
		||||
            'username': json.encode(user.username if user.is_authenticated() else 'Anonymous')
 | 
			
		||||
            'is_anonymous': json.encode(user.is_anonymous),
 | 
			
		||||
            'is_authenticated': json.encode(user.is_authenticated),
 | 
			
		||||
            'username': json.encode(user.username if user.is_authenticated else 'Anonymous')
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -12,7 +12,7 @@ def render_recommended_feed(context, recommended_feeds, unmoderated=False):
 | 
			
		|||
    user = get_user(context['user'])
 | 
			
		||||
    
 | 
			
		||||
    usersub = None
 | 
			
		||||
    if context['user'].is_authenticated():
 | 
			
		||||
    if context['user'].is_authenticated:
 | 
			
		||||
        usersub = UserSubscription.objects.filter(user=user, feed=recommended_feeds[0].feed)
 | 
			
		||||
    recommended_feed = recommended_feeds and recommended_feeds[0]
 | 
			
		||||
    feed_icon = MFeedIcon.objects(feed_id=recommended_feed.feed_id)
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -23,7 +23,7 @@ def load_recommended_feed(request):
 | 
			
		|||
        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():
 | 
			
		||||
    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))
 | 
			
		||||
| 
						 | 
				
			
			@ -53,7 +53,7 @@ def load_recommended_feed(request):
 | 
			
		|||
def load_feed_info(request, feed_id):
 | 
			
		||||
    feed = get_object_or_404(Feed, pk=feed_id)
 | 
			
		||||
    previous_recommendation = None
 | 
			
		||||
    if request.user.is_authenticated():
 | 
			
		||||
    if request.user.is_authenticated:
 | 
			
		||||
        recommended_feed = RecommendedFeed.objects.filter(user=request.user, feed=feed)
 | 
			
		||||
        if recommended_feed:
 | 
			
		||||
            previous_recommendation = recommended_feed[0].created_date
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -44,7 +44,7 @@ def search_feed(request):
 | 
			
		|||
    logging.user(request.user, "~FBFinding feed (search_feed): %s" % address)
 | 
			
		||||
    ip = request.META.get('HTTP_X_FORWARDED_FOR', None) or request.META['REMOTE_ADDR']
 | 
			
		||||
    logging.user(request.user, "~FBIP: %s" % ip)
 | 
			
		||||
    aggressive = request.user.is_authenticated()
 | 
			
		||||
    aggressive = request.user.is_authenticated
 | 
			
		||||
    feed = Feed.get_feed_from_url(address, create=False, aggressive=aggressive, offset=offset)
 | 
			
		||||
    if feed:
 | 
			
		||||
        return feed.canonical()
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -29,7 +29,7 @@ def render_story_comments(context, story):
 | 
			
		|||
    user = context['user']
 | 
			
		||||
    user_social_profile = context.get('user_social_profile')
 | 
			
		||||
    MEDIA_URL = settings.MEDIA_URL
 | 
			
		||||
    if not user_social_profile and user.is_authenticated():
 | 
			
		||||
    if not user_social_profile and user.is_authenticated:
 | 
			
		||||
        user_social_profile = MSocialProfile.objects.get(user_id=user.pk)
 | 
			
		||||
    
 | 
			
		||||
    return {
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -360,7 +360,7 @@ def load_social_page(request, user_id, username=None, **kwargs):
 | 
			
		|||
    user_social_services = None
 | 
			
		||||
    user_following_social_profile = None
 | 
			
		||||
    relative_user_id = user_id
 | 
			
		||||
    if user.is_authenticated():
 | 
			
		||||
    if user.is_authenticated:
 | 
			
		||||
        user_social_profile = MSocialProfile.get_user(user.pk)
 | 
			
		||||
        user_social_services = MSocialServices.get_user(user.pk)
 | 
			
		||||
        user_following_social_profile = user_social_profile.is_following_user(social_user_id)
 | 
			
		||||
| 
						 | 
				
			
			@ -376,7 +376,7 @@ def load_social_page(request, user_id, username=None, **kwargs):
 | 
			
		|||
        current_tab = "global"
 | 
			
		||||
        global_feed = True
 | 
			
		||||
    
 | 
			
		||||
    if social_profile.private and (not user.is_authenticated() or 
 | 
			
		||||
    if social_profile.private and (not user.is_authenticated or 
 | 
			
		||||
                                   not social_profile.is_followed_by_user(user.pk)):
 | 
			
		||||
        stories = []
 | 
			
		||||
    elif global_feed:
 | 
			
		||||
| 
						 | 
				
			
			@ -386,7 +386,7 @@ def load_social_page(request, user_id, username=None, **kwargs):
 | 
			
		|||
                                                 offset=offset, limit=limit+1,
 | 
			
		||||
                                                 # order=order, read_filter=read_filter,
 | 
			
		||||
                                                 relative_user_id=relative_user_id,
 | 
			
		||||
                                                 cache=request.user.is_authenticated(),
 | 
			
		||||
                                                 cache=request.user.is_authenticated,
 | 
			
		||||
                                                 cutoff_date=user.profile.unread_cutoff)
 | 
			
		||||
        if len(story_ids) > limit:
 | 
			
		||||
            has_next_page = True
 | 
			
		||||
| 
						 | 
				
			
			@ -439,7 +439,7 @@ def load_social_page(request, user_id, username=None, **kwargs):
 | 
			
		|||
    stories, profiles = MSharedStory.stories_with_comments_and_profiles(stories, social_user.pk, 
 | 
			
		||||
                                                                        check_all=True)
 | 
			
		||||
 | 
			
		||||
    if user.is_authenticated():
 | 
			
		||||
    if user.is_authenticated:
 | 
			
		||||
        for story in stories:
 | 
			
		||||
            if user.pk in story['share_user_ids']:
 | 
			
		||||
                story['shared_by_user'] = True
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -129,7 +129,7 @@ def json_response(request, response=None):
 | 
			
		|||
            response = dict(response)
 | 
			
		||||
            if 'result' not in response:
 | 
			
		||||
                response['result'] = 'ok'
 | 
			
		||||
            authenticated = request.user.is_authenticated()
 | 
			
		||||
            authenticated = request.user.is_authenticated
 | 
			
		||||
            response['authenticated'] = authenticated
 | 
			
		||||
            if authenticated:
 | 
			
		||||
                response['user_id'] = request.user.pk
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -46,7 +46,7 @@ def user(u, msg, request=None, warn_color=True):
 | 
			
		|||
                color,
 | 
			
		||||
                seconds,
 | 
			
		||||
            )
 | 
			
		||||
    is_premium = u.is_authenticated() and u.profile.is_premium
 | 
			
		||||
    is_premium = u.is_authenticated and u.profile.is_premium
 | 
			
		||||
    premium = '*' if is_premium else ''
 | 
			
		||||
    username = cipher(unicode(u)) if settings.CIPHER_USERNAMES else unicode(u)
 | 
			
		||||
    info(' ---> [~FB~SN%-6s~SB] %s[%s%s] %s' % (platform, time_elapsed, username, premium, msg))
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -11,7 +11,7 @@ from django.conf import settings
 | 
			
		|||
def ajax_login_required(function=None):
 | 
			
		||||
    def _dec(view_func):
 | 
			
		||||
        def _view(request, *args, **kwargs):
 | 
			
		||||
            if request.user.is_anonymous():
 | 
			
		||||
            if request.user.is_anonymous:
 | 
			
		||||
                return HttpResponseForbidden()
 | 
			
		||||
            else:
 | 
			
		||||
                return view_func(request, *args, **kwargs)
 | 
			
		||||
| 
						 | 
				
			
			@ -30,7 +30,7 @@ def ajax_login_required(function=None):
 | 
			
		|||
def oauth_login_required(function=None):
 | 
			
		||||
    def _dec(view_func):
 | 
			
		||||
        def _view(request, *args, **kwargs):
 | 
			
		||||
            if request.user.is_anonymous():
 | 
			
		||||
            if request.user.is_anonymous:
 | 
			
		||||
                return HttpResponse(content=json.encode({
 | 
			
		||||
                    "message": "You must have a valid OAuth token.",
 | 
			
		||||
                }), status=401)
 | 
			
		||||
| 
						 | 
				
			
			@ -79,7 +79,7 @@ def get_user(request):
 | 
			
		|||
    else:
 | 
			
		||||
        user = request.user
 | 
			
		||||
        
 | 
			
		||||
    if user.is_anonymous() and hasattr(request, 'POST'):
 | 
			
		||||
    if user.is_anonymous and hasattr(request, 'POST'):
 | 
			
		||||
        # Check secret_token parameter
 | 
			
		||||
        secret_token = request.POST.get('secret_token', None) or request.GET.get('secret_token', None)
 | 
			
		||||
        if secret_token:
 | 
			
		||||
| 
						 | 
				
			
			@ -89,7 +89,7 @@ def get_user(request):
 | 
			
		|||
            except User.DoesNotExist:
 | 
			
		||||
                pass
 | 
			
		||||
        
 | 
			
		||||
    if user.is_anonymous():
 | 
			
		||||
    if user.is_anonymous:
 | 
			
		||||
        user = cache.get('user:%s' % settings.HOMEPAGE_USERNAME, None)
 | 
			
		||||
        if not user:
 | 
			
		||||
            try:
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
	Add table
		
		Reference in a new issue