def menuitem_edit(self, request, id): if not auth(request): return redirect('login') if request.method == 'POST': form = MenuItemForm(request.POST) print('prisla poziadavka') if form.is_valid(): try: obj = MenuItem.objects.get(id=request.POST.get('id', -1)) except (MenuItem.DoesNotExist, ValueError): obj = MenuItem() obj.populate(request.POST) obj.save() #po zmeneni menu ho treba znova nacitat self.sidebar_menu = MenuItem.objects.all().filter(visible=True) else: print('form isnt valid') x = self.menu_show(request) print(x) return x try: obj = MenuItem.objects.get(id=id) form = MenuItemForm(obj.__dict__) except MenuItem.DoesNotExist: form = MenuItemForm() return render(request, 'menu/menuitem.html', locals())
def delete(self, request, id): if not auth(request): return redirect('login') blog = get_object_or_404(Blogs, id=id) if blog: blog.deleted = True blog.save() return redirect('blog_list')
def delete(self,request,pagename): if not auth(request): return redirect('login') page = self.get(pagename) if page: page.deleted = True page.save() return self.list(request)
def menuitem_down(self, request, id): if not auth(request): return redirect('login') obj = MenuItem.objects.get(id=id) obj1 = MenuItem.objects.filter(id__gt=id).order_by('id')[0] obj.id, obj1.id = obj1.id, obj.id obj.save() obj1.save() return self.menu_show(request)
def list(self, request): visible = [True] if auth(request): visible.append(False) blogposts = Blogs.objects.all().filter( deleted=False, visible__in=visible).distinct().order_by('-id') return render(request, 'blog/list.html', locals())
def menu_delete(self, request, id): if not auth(request): return redirect('login') try: MenuItem.objects.get(id=id).delete() except MenuItem.DoesNotExist: pass self.sidebar_menu = MenuItem.objects.all().filter(visible=True) return self.menu_show(request)
def new(self, request): if not auth(request): return redirect('login') if request.method == 'POST': form = FlightForm(request.POST) new_flight = form.save() return redirect('edit_flight', id=new_flight.id) form = FlightForm() return render(request, 'flights/form.html', locals())
def show(self, request, id): if not auth(request): post = get_object_or_404(Blogs, id=id, visible=True) else: post = get_object_or_404(Blogs, id=id) #zakomentovane koli velkej casovej narocnosti post.views += 1 post.save() return render(request, 'blog/post.html', locals())
def new(self, request): if not auth(request): return redirect('login') if request.method == 'POST': form = BlogEditForm(request.POST) new_blog = form.save() return redirect('blog_show', id=new_blog.id) form = BlogEditForm() return render(request, 'blog/form.html', locals())
def edit(self, request, id): if not auth(request): return redirect('login') flight = get_object_or_404(Flight, id=id) if request.method == 'POST': form = FlightForm(request.POST, instance=flight) if form.is_valid(): form.save() else: form = FlightForm(instance=flight) return render(request, 'flights/form.html', locals())
def edit(self, request, id): if not auth(request): return redirect('login') blog = get_object_or_404(Blogs, id=id) if request.method == 'POST': form = BlogEditForm(request.POST, instance=blog) if form.is_valid(): form.save() return redirect('blog_show', id=id) else: form = BlogEditForm(instance=blog) return render(request, 'blog/form.html', locals())
def edit(self,request,pagename): if not auth(request): return redirect('login') #ak prisla poziadavka na update, tak updatneme if request.method == 'POST': form = PageEditForm(request.POST) if form.is_valid(): try: obj = Pages.objects.get(id=request.POST.get('id',-1)) except (Pages.DoesNotExist, ValueError): obj = Pages() obj.populate(request.POST) obj.save() return self.show(request,pagename) page = self.get(pagename) form = PageEditForm(page.__dict__) return render(request, 'page/form.html',locals())
def list(self,request): if not auth(request): return redirect('login') pages = Pages.objects.all() return render(request,'page/list.html',locals())
def menu_show(self, request): if not auth(request): return redirect('login') items = MenuItem.objects.all() return render(request, 'menu/show.html', locals())
def delete(self, request, id): if not auth(request): return redirect('login') flight = get_object_or_404(Flight, id=id) flight.delete() return redirect('list_flights')
def page_new(self,request): if not auth(request): return redirect('login') form = PageEditForm({'id':0,'visible':True}) return render(request, 'page/form.html',locals())
def menu_new(self, request): if not auth(request): return redirect('login') form = MenuItemForm({'id': 0, 'visible': True}) return render(request, 'menu/menuitem.html', locals())