def edit_board_cover(request, board): """ Displays edit from for board cover and handles edit action. """ board = get_object_or_404(Board, slug=board) admins = board.admins.all() if request.user in admins: if request.method == 'POST': board_cover = request.FILES.get('cover') if check_image_extension(board_cover.name): board.cover = board_cover board.save() return redirect('board', board=board.slug) else: return HttpResponse( 'Filetype not supported. Supported filetypes are .jpg, .png etc.' ) else: form_filling = True return render(request, 'boards/edit_board_cover.html', { 'board': board, 'form_filling': form_filling }) else: return HttpResponse( 'You can not change the cover of this board unless you are an admin here.' )
def change_picture(request): """ Handles profile picture change action. """ if request.method == 'POST': user_dp = request.FILES.get('dp') if check_image_extension(user_dp.name): profile_form = Profile.objects.get(user=request.user) profile_form.dp = user_dp profile_form.save() msg_txt = """ <p>Your profile picture is successfully saved. <a href="/" class="alert-link">Go to homepage</a></p> """ messages.success(request, msg_txt) else: msg_txt = """ <p> Filetype not supported. Please use .jpg or .png filetypes. <a href="/" class="alert-link">Go to homepage</a> </p> """ messages.warning(request, msg_txt) return redirect('picture_change') return redirect('user_profile', username=request.user.username) else: profile_form = ProfileEditForm(instance=request.user.profile) return render(request, 'users/change_picture.html', {'profile_form': profile_form})
def edit_board_cover(request, board): board = get_object_or_404(Board, slug=board) if request.method == 'POST': board_cover = request.FILES.get('cover') if check_image_extension(board_cover.name): board.cover = board_cover board.save() return redirect('board', board=board.slug) else: return HttpResponse( 'Filetype not supported. Supported filetypes are .jpg, .png etc.' ) else: form_filling = True return render(request, 'boards/edit_board_cover.html', { 'board': board, 'form_filling': form_filling })