def add_carousel_image(request): # check if user has edit permissions try: social = request.user.social_auth.get(provider='github') access_token = social.extra_data['access_token'] except: access_token = '' if access_token: has_permission = has_commit_permission(access_token, 'dipy_web') else: has_permission = False # if user does not have edit permission: if not has_permission: raise PermissionDenied # if user has edit permission: context = {} if request.method == 'POST': submitted_form = AddEditCarouselImageForm(request.POST) if submitted_form.is_valid(): submitted_form.save() return redirect('/dashboard/carousel/') else: context['form'] = submitted_form return render(request, 'website/addeditcarousel.html', context) form = AddEditCarouselImageForm() context['form'] = form return render(request, 'website/addeditcarousel.html', context)
def _edit_image(request, carousel_image_id, model, model_form, path, template): # check if user has edit permissions try: social = request.user.social_auth.get(provider='github') access_token = social.extra_data['access_token'] except: access_token = '' if access_token: has_permission = has_commit_permission(access_token, 'dipy_web') else: has_permission = False # if user does not have edit permission: if not has_permission: raise PermissionDenied # if user has edit permission: try: carousel_image = model.objects.get(id=carousel_image_id) except: raise Http404("Website Section does not exist") context = {} if request.method == 'POST': submitted_form = model_form(request.POST, instance=carousel_image) if submitted_form.is_valid(): submitted_form.save() return redirect('/dashboard' + path) else: context['form'] = submitted_form return render(request, template, context) form = AddEditCarouselImageForm(instance=carousel_image) context['form'] = form return render(request, template, context)
def _add_image(request, model_form, path, template): context = {'title': 'Add'} if request.method == 'POST': submitted_form = model_form(request.POST) if submitted_form.is_valid(): submitted_form.save() return redirect('/dashboard' + path) else: context['form'] = submitted_form return render(request, template, context) form = AddEditCarouselImageForm() context['form'] = form return render(request, template, context)
def _edit_image(request, carousel_image_id, model, model_form, path, template): try: carousel_image = model.objects.get(id=carousel_image_id) except Exception: raise Http404("Website Section does not exist") context = {'title': 'Edit'} if request.method == 'POST': submitted_form = model_form(request.POST, instance=carousel_image) if submitted_form.is_valid(): submitted_form.save() return redirect('/dashboard' + path) else: context['form'] = submitted_form return render(request, template, context) form = AddEditCarouselImageForm(instance=carousel_image) context['form'] = form return render(request, template, context)
def add_carousel_image(request): context = {} if request.method == 'POST': submitted_form = AddEditCarouselImageForm(request.POST) if submitted_form.is_valid(): submitted_form.save() return redirect(reverse('dashboard_carousel')) else: context['form'] = submitted_form return render(request, 'website/addeditcarousel.html', context) form = AddEditCarouselImageForm() context['form'] = form return render(request, 'website/addeditcarousel.html', context)
def edit_carousel_image(request, carousel_image_id): try: carousel_image = CarouselImage.objects.get(id=carousel_image_id) except: raise Http404("Website Section does not exist") context = {} if request.method == 'POST': submitted_form = AddEditCarouselImageForm(request.POST, instance=carousel_image) if submitted_form.is_valid(): submitted_form.save() return redirect(reverse('dashboard_carousel')) else: context['form'] = submitted_form return render(request, 'website/addeditcarousel.html', context) form = AddEditCarouselImageForm(instance=carousel_image) context['form'] = form return render(request, 'website/addeditcarousel.html', context)