Beispiel #1
0
def notification_view(request):
    """
        This function will render notification detail view.
    """
    user = request.user
    check_profile = None
    flag = None
    if user.is_authenticated:
        flag = set_profile(request, user)
        check_profile = UserProfile.objects.get(user=user)

    # Read notifications of current user
    read_notif = user.notifications.read().filter()

    # Unread notifications of current user
    unread_notif = user.notifications.unread()

    # All user profiles
    user_profile_qs = UserProfile.objects.all()

    context = {
        'read_notif': read_notif,
        'unread_notif': unread_notif,
        'user_profile_qs': user_profile_qs,
    }

    if check_profile is not None:
        if not check_profile.is_profile_set:
            # messages.info(request, f"Set your profile first.")
            return HttpResponseRedirect(
                reverse('edit_profile',
                        kwargs={'username': request.user.username}))

    return render(request, 'notif/notifications_detail.html', context)
Beispiel #2
0
def user_profile(request, username, tag_name=None, liked=None, older=None):
    """
        This functions renders User Profile Page
    """
    service = get_calendar_service(request)
    # Call the Calendar API
    # print('Getting list of calendars')
    timeZone = None
    calendar_id = None
    if service:
        cal_service_found = True
        calendars_result = service.calendarList().list().execute()

        calendars = calendars_result.get('items', [])

        if not calendars:
            print('No calendars found.')
        for calendar in calendars:
            # print(calendar.get('primary'))# prints True only for the primary Calendar of User
            if calendar.get('primary'):
                summary = calendar['summary']
                calendar_id = calendar['id']
                timeZone = calendar['timeZone']
                primary = "Primary" if calendar.get('primary') else ""
                # print(timeZone) # prints Asia/Kolkata
                print("%s\t%s\t%s" % (summary, calendar_id, primary))
        # User whose profile is open
    native_user = get_object_or_404(User, username=username)
    profile = get_object_or_404(UserProfile, user=native_user)

    check_profile = None
    flag = False

    if request.user.is_authenticated:
        check_profile = get_object_or_404(UserProfile, user=request.user)
        if profile is check_profile:
            flag = set_profile(request, native_user)
            check_profile = get_object_or_404(UserProfile, user=request.user)

    # Users current user is following
    followed_users = check_profile.followed_users.all()
    # Users who are following current user
    followers = check_profile.followers.all()

    # Posts and avatar of that user
    native_posts = page_maker(request,
                              Post,
                              native_user,
                              tag_filter=tag_name,
                              liked=liked,
                              older=older)

    # drafts = page_maker(request, Post, native_user, draft=True)
    # This also contains scheduled but NOT yet approved event related post
    drafts = Post.objects.filter(author=native_user).filter(draft=True)

    # Scheduled event related post which have not been given permission yet.
    scheduled_posts = Post.objects.filter(author=native_user).filter(
        draft=True).filter(is_scheduled=True)

    # Fetching all User profiles, comments, tags, pending posts and
    # pending posts of native user
    user_profiles = UserProfile.objects.all()
    comments = Comment.objects.all()
    tags = Tags.objects.all()

    # Filtering All pending posts and pending post of native user which are NOT drafts.
    pending_posts = Post.objects.filter(verify_status=-1).filter(draft=False)
    native_pending_posts = pending_posts.filter(author=native_user).filter(
        draft=False)

    # Comment form, user signup form, post adding form and password change form
    comment_form = CommentForm()
    form = UserSignupForm()
    addpostform = PostForm()
    password_change_form = PasswordChangeForm(user=native_user)
    avatar_form = AvatarUploadForm()

    read_notif = None
    unread_notif = None
    if request.user.is_authenticated:

        # Read notifications
        read_notif = request.user.notifications.read()

        # Unread notifications
        unread_notif = request.user.notifications.unread()
    quiz_results = UserQuizResult.objects.all().filter(user=request.user)

    context = {
        'profile': profile,
        'avatar_form': avatar_form,
        'form': form,
        'native_user': native_user,
        'native_posts': native_posts,
        'addpostform': addpostform,
        'password_change_form': password_change_form,
        'comments': comments,
        'comment_form': comment_form,
        'user_profiles': user_profiles,
        'tags': tags,
        'pending_posts': pending_posts,
        'native_pending_posts': native_pending_posts,
        'read_notif': read_notif,
        'unread_notif': unread_notif,
        'drafts': drafts,
        'quiz_results': quiz_results,
        'scheduled_posts': scheduled_posts,
        'followed_users': followed_users,
        'followers': followers,
    }

    if check_profile is not None:
        if not profile.is_profile_set:
            messages.info(request, f"User profile not set")
            return HttpResponseRedirect(reverse('Index'))

    if 'cal_service_found' in locals():
        new_to_context = {
            'cal_service_found': 1,
            'calendar_id': calendar_id,
            'timeZone': timeZone
        }
        context.update(new_to_context)
    return render(request, 'user_profile/user_profile.html', context)
def user_profile(request, username, tag_name=None, liked=None, older=None):
    """
        This functions renders User Profile Page
    """
    native_user = get_object_or_404(User, username=username)
    profile = get_object_or_404(UserProfile, user=native_user)

    check_profile = None
    flag = False

    # Users current user is following
    followed_users = None
    # Users who are following current user
    followers = None

    if request.user.is_authenticated:
        check_profile = get_object_or_404(UserProfile, user=request.user)
        # Users current user is following
        followed_users = check_profile.followed_users.all()
        # Users who are following current user
        followers = check_profile.followers.all()
        if profile is check_profile:
            flag = set_profile(request, native_user)
            check_profile = get_object_or_404(UserProfile, user=request.user)

    # Posts and avatar of that user
    native_posts = page_maker(request,
                              Post,
                              native_user,
                              tag_filter=tag_name,
                              liked=liked,
                              older=older)

    # drafts = page_maker(request, Post, native_user, draft=True)
    # This also contains scheduled but NOT yet approved event related post
    drafts = Post.objects.filter(author=native_user).filter(draft=True)

    admin = User.objects.get(username='******')
    # Scheduled event related post which have not been given permission yet.
    scheduled_posts = Post.objects.filter(author=admin).filter(
        draft=True).filter(is_scheduled=True)

    # Fetching all User profiles, comments, tags, pending posts and
    # pending posts of native user
    user_profiles = UserProfile.objects.all()
    comments = Comment.objects.all()
    tags = Tags.objects.all()

    # Filtering All pending posts and pending post of native user which are NOT drafts.
    pending_posts = Post.objects.filter(verify_status=-1).filter(draft=False)
    native_pending_posts = pending_posts.filter(author=native_user).filter(
        draft=False)

    # Comment form, user signup form, post adding form and password change form
    comment_form = CommentForm()
    form = UserSignupForm()
    addpostform = PostForm()
    password_change_form = PasswordChangeForm(user=native_user)
    avatar_form = AvatarUploadForm()

    read_notif = None
    unread_notif = None
    quiz_results = None
    if request.user.is_authenticated:

        # Read notifications
        # read_notif = request.user.notifications.read()
        read_notif = Notification.objects.filter(
            recipient=request.user).filter(unread=False)

        # Unread notifications
        # unread_notif = request.user.notifications.unread()
        unread_notif = Notification.objects.filter(
            recipient=request.user).filter(unread=True)

        quiz_results = UserQuizResult.objects.all().filter(user=request.user)

    context = {
        'profile': profile,
        'avatar_form': avatar_form,
        'form': form,
        'native_user': native_user,
        'native_posts': native_posts,
        'addpostform': addpostform,
        'password_change_form': password_change_form,
        'comments': comments,
        'comment_form': comment_form,
        'user_profiles': user_profiles,
        'tags': tags,
        'pending_posts': pending_posts,
        'native_pending_posts': native_pending_posts,
        'read_notif': read_notif,
        'unread_notif': unread_notif,
        'drafts': drafts,
        'quiz_results': quiz_results,
        'scheduled_posts': scheduled_posts,
        'followed_users': followed_users,
        'followers': followers,
    }

    if check_profile is not None:
        if not profile.is_profile_set:
            messages.info(request, f"User profile not set")
            return HttpResponseRedirect(reverse('Index'))

    return render(request, 'user_profile/user_profile.html', context)