def index(request): queryset = Idea.objects.all().order_by("pk") if not request.user.is_staff: queryset = queryset.exclude(is_draft=True) form = IdeaForm() if request.method == "POST": next = request.POST["next"] form = IdeaForm(request.POST) if form.is_valid(): idea = form.save() messages.success(request, u"Mensaje publicado con exito.") return redirect(next) else: return idea_new(request, form_instance=form) return render(request, "master.html", {"idea_form": form, "object_list": queryset})
def idea_new(request, tag_name=None, object_id=None, form_instance=None): form = IdeaForm() if object_id: idea = get_object_or_404(Idea, pk=object_id) form = IdeaForm(instance=idea) else: idea = None if form_instance: form = form_instance return render(request, 'idea_form.html', { 'form': form, 'instance': idea, 'tag_name': tag_name, })
def idea_detail(request, tag_name, object_id): queryset = Idea.objects.all() form = IdeaForm(initial={"tags": tag_name}) idea = get_object_or_404(Idea, pk=object_id) if request.method == "POST": next = request.POST["next"] form = IdeaForm(request.POST, instance=idea) if form.is_valid(): idea = form.save() messages.success(request, "Actualizaste el #%s" % (object_id)) return redirect(next) else: return idea_new(request, tag_name=tag_name, object_id=object_id, form_instance=form) return render( request, "detail.html", {"idea_form": form, "tag": tag_name, "object": idea, "object_list": queryset.filter(tags__icontains=tag_name)}, )
def idea_json(request, tag_name, object_id): queryset = Idea.objects.all() form = IdeaForm(initial={'tags': tag_name}) idea = get_object_or_404(Idea, pk=object_id) return HttpResponse(json.dumps({ 'title': idea.title, 'author': idea.author, 'description': idea.description, 'is_draft': idea.is_draft, 'tags': idea.tags }), mimetype="application/json")
def by_tag(request, tag_name=None): queryset = Idea.objects.all().order_by('tags') form = IdeaForm() if tag_name: queryset = queryset.filter(tags__icontains=tag_name) return render( request, 'list.html', { 'form': form, 'tag_name': tag_name, 'object_list': queryset.filter(tags__icontains=tag_name), })
def index(request): queryset = Idea.objects.all().order_by('pk') if not request.user.is_staff: queryset = queryset.exclude(is_draft=True) form = IdeaForm() if request.method == 'POST': next = request.POST['next'] form = IdeaForm(request.POST) if form.is_valid(): idea = form.save() messages.success(request, u'Mensaje publicado con exito.') return redirect(next) else: return idea_new(request, form_instance=form) return render(request, 'master.html', { 'idea_form': form, 'object_list': queryset, })
def idea_detail(request, tag_name, object_id): queryset = Idea.objects.all() form = IdeaForm(initial={'tags': tag_name}) idea = get_object_or_404(Idea, pk=object_id) if request.method == 'POST': next = request.POST['next'] form = IdeaForm(request.POST, instance=idea) if form.is_valid(): idea = form.save() messages.success(request, 'Actualizaste el #%s' % (object_id)) return redirect(next) else: return idea_new(request, tag_name=tag_name, object_id=object_id, form_instance=form) return render( request, 'detail.html', { 'idea_form': form, 'tag': tag_name, 'object': idea, 'object_list': queryset.filter(tags__icontains=tag_name), })