def get_user_profile(session_id): if session_id is None: return None try: djsession = djSession.objects.get(expire_date__gt=timezone.now(), session_key=session_id) except djSession.DoesNotExist: return None try: return UserProfile.objects.get(pk=get_session_user(djsession)) except (UserProfile.DoesNotExist, KeyError): return None