示例#1
0
def add_tip(request):
    if request.POST:
        form = TipForm(request.POST)
        try:
            form.save()
            return HttpResponseRedirect(reverse('tip-mytips'))
        except:
            pass
            
        return mytips(request, form)
    return HttpResponseRedirect(reverse('tip-mytips'))
示例#2
0
def add_tip(request):
    if request.POST:
        form = TipForm(request.POST)
        try:
            form.save()
            return HttpResponseRedirect(reverse('tip-mytips'))
        except:
            pass

        return mytips(request, form)
    return HttpResponseRedirect(reverse('tip-mytips'))
示例#3
0
def update_tip(request):
    if request.POST:
        id = request.POST.get('id')
        tip = get_object_or_404(Tip, id=id, author=request.user)
        form = TipForm(request.POST, instance=tip)
        try:
            form.save()
            return HttpResponseRedirect(reverse('tip-mytips'))
        except:
            pass
            
    context = {'form':form , 'active_menu':'mytips'}
    return direct_to_template(request, 'edit.html', context)
示例#4
0
def update_tip(request):
    if request.POST:
        id = request.POST.get('id')
        tip = get_object_or_404(Tip, id=id, author=request.user)
        form = TipForm(request.POST, instance=tip)
        try:
            form.save()
            return HttpResponseRedirect(reverse('tip-mytips'))
        except:
            pass

    context = {'form': form, 'active_menu': 'mytips'}
    return direct_to_template(request, 'edit.html', context)
示例#5
0
def mytips(request, form=None):
    if form == None:
        form = TipForm()
    tips = Tip.objects.filter(author=request.user)
    bookmarked_tips = Bookmark.objects.filter(user=request.user)

    context = {
        'tips': tips,
        'bookmarked_tips': bookmarked_tips,
        'form': form,
        'active_menu': 'mytips'
    }
    return direct_to_template(request, 'mytips.html', context)
示例#6
0
def show_edit_form(request, id, slug=None):
    tip = get_object_or_404(Tip, id=id, author=request.user)
    context = {'form': TipForm(instance=tip), 'active_menu': 'mytips'}
    return direct_to_template(request, 'edit.html', context)