def user_album(request): form = UploadPhotoForm() album_form = UploadAlbumForm() if request.method=='POST': images = request.FILES.getlist('upload_photos') title = request.POST.get('album_title') album = Album(image_title=title) album.save() for img in images: photo = Photos( user=request.user, user_images=img, album=album ) photo.save() # if images.index(img) == 0 : # user_photo = Photos(user=request.user, user_images=img) # user_photo.album = True # user_photo.image_title = request.POST.get('image_title') # user_photo.save() # last_id = Photos.objects.all().order_by("-id")[0] # else: # user_photo = Photos(user=request.user, user_images=img) # user_photo.album = True # user_photo.parent = last_id # user_photo.save() return HttpResponseRedirect("/user/photos") print ("post") ctx = { 'album_form':album_form, # 'form':form, } return render(request, 'users/user_photos.html', ctx)
def upload_photo(request): image = request.FILES.get('photo') if request.method=='POST': photo = Photos( user=request.user, user_images=image, ) photo.save() return HttpResponseRedirect("/user/photos")
def user_timeline(request): current_user =request.user form = PostForm() friends = Friend.objects.friends(current_user) users_objects = CustomUser.objects.filter(email__in=friends) current_cover= None album_profile_pic = Album.objects.get_or_create( image_title="Cover pic", reserved=True) try: current_cover = Photos.objects.get(album=album_profile_pic[0], user=request.user,current_pic=True ) except: pass all_post = Post.objects.filter( Q(users=current_user) | Q(users__in=users_objects)).order_by('-created_at') if request.method=='POST': images = request.FILES.getlist('upload_photos') title = request.POST.get('album_title') videos = request.FILES.getlist('upload_vedio') form = PostForm(request.POST) if form.is_valid(): post = form.save(commit=False) post.users = current_user post.save() album_timeline_pic = Album.objects.get_or_create( image_title="Timeline pic", reserved=True) for img in images: user_photo = Photos(user_images= img, post=post, album=album_timeline_pic[0], user=request.user ) user_photo.save() if videos: for video in videos: user_video = Item(post=post,video=video,user=request.user) user_video.save() return redirect(reverse('timeline')) ctx = { 'form':form, 'all_post':all_post, 'friends':friends, 'current_cover':current_cover, } return render(request, 'users/timeline.html', ctx)
def add_img_album(request): get_id = request.POST.get('get_id',None) images = request.FILES.getlist('upload_photos') if request.method=='POST': album = Album.objects.get(id=get_id) for img in images: photo = Photos( user=request.user, user_images=img, album=album ) photo.save() return HttpResponseRedirect("/user/photos")
def coverphotos(request): "Will call on post to save user profile picture" if request.method=='POST': image = request.FILES.get('upload_photos') album_profile_pic = Album.objects.get_or_create( image_title="Cover pic", reserved=True) try: cuttent_cover = Photos.objects.get(album=album_profile_pic[0], user=request.user,current_pic=True ) cuttent_cover.current_pic = False cuttent_cover.save() except: pass user_photo = Photos(user_images= image, album=album_profile_pic[0], user=request.user,current_pic=True ) user_photo.save() return HttpResponseRedirect("/user/timeline")
def profile_picture(request): "Will call on post to save user profile picture" if request.method=='POST': image = request.FILES.get('profile_pic') album_profile_pic = Album.objects.get_or_create( image_title="Profile pic", reserved=True) try: photo = Photos.objects.get(album=album_profile_pic[0], user=request.user, current_pic=True ) photo.current_pic = False photo.save() except: pass user_photo = Photos(user_images= image, album=album_profile_pic[0], user=request.user,current_pic=True ) user_photo.save() return HttpResponseRedirect("/user/photos")