示例#1
0
def home(request):
    post_form = PostForm()
    current_user = request.user
    if request.method == 'POST':
        post_form = PostForm(request.POST)
        if post_form.is_valid():
            post = post_form.save(commit=False)
            post_form.instance.user = User(current_user.id)
            post_form.instance.user_profile = Profile.objects.get(
                user=current_user)
            print(request.FILES)
            if "image" in request.FILES:
                post.image = request.FILES['image']
            post.save()
            post_form = PostForm()

    else:
        post_form = PostForm()

    #loadmore
    old_posts = Post.objects.all().order_by('-created_date')
    page = request.GET.get('page', 1)
    paginator = Paginator(old_posts, 1)
    try:
        numbers = paginator.page(page)
    except PageNotAnInteger:
        numbers = paginator.page(1)
    except EmptyPage:
        numbers = paginator.page(paginator.num_pages)
    return render(request, 'socialApp/home.html', {
        'post_form': post_form,
        'posts': numbers
    })
示例#2
0
def videos(request):
    post_form = PostForm()
    current_user = request.user
    if request.method == 'POST':
        post_form = PostForm(request.POST)
        if post_form.is_valid():
            post = post_form.save(commit=False)
            post_form.instance.user = User(current_user.id)
            post_form.instance.user_profile = Profile.objects.get(
                user=current_user)
            print(request.FILES)
            if "image" in request.FILES:
                post.image = request.FILES['image']
            post.save()
            post_form = PostForm()

    else:
        post_form = PostForm()
    follow = Follow.objects.filter(user=current_user)
    old_posts = Post.objects.all().order_by('-created_date')
    print(old_posts)
    return render(request, 'socialApp/videos.html', {
        'post_form': post_form,
        'posts': old_posts,
        'follow': follow
    })
示例#3
0
def home(request):
    post_form = PostForm()
    current_user = request.user
    if request.method == 'POST':
        post_form = PostForm(request.POST)
        if post_form.is_valid():
            post = post_form.save(commit=False)
            post_form.instance.user = User(current_user.id)
            post_form.instance.user_profile = Profile.objects.get(
                user=current_user)
            print(request.FILES)
            if "image" in request.FILES:
                post.image = request.FILES['image']
            post.save()
            post_form = PostForm()

    else:
        post_form = PostForm()
    user_list = {}
    post_list = {}
    #loadmore
    follow = Follow.objects.filter(user=current_user)
    old_posts = Post.objects.all().order_by('-created_date')

    #for user in follow:
    #user_follow = User.objects.filter(id=user.following.id)
    #user_list[user]=user_follow
    #for post in old_posts:
    #post_list[post] =

    replys = Reply.objects.all().order_by('-created_date')
    page = request.GET.get('page', 1)
    paginator = Paginator(old_posts, 8)
    try:
        numbers = paginator.page(page)
    except PageNotAnInteger:
        numbers = paginator.page(1)
    except EmptyPage:
        numbers = paginator.page(paginator.num_pages)
    return render(
        request, 'socialApp/home.html', {
            'post_form': post_form,
            'posts': numbers,
            'replys': replys,
            'follow': follow
        })