Ejemplo n.º 1
0
def helptexts(request):
    helps = HelpText.objects.all()
    if helps:
        latest = HelpText.objects.filter().order_by('-order')[0]
        latest_order = latest.order + 1
    else:
        latest = None
        latest_order = 0
    selected = None
    message = None
    selected_help = request.GET.get('selected_help', None)
    if selected_help:
        selected = HelpText.objects.get(title=selected_help)

    if request.method == "POST":
        to_update = request.POST.get('id', None)
        if to_update:
            updated = HelpText.objects.get(id=to_update)
            updated.title = request.POST['title']
            slug = request.POST['slug']
            updated.slug = slugify(slug)
            updated.template = request.POST['template']
            updated.save()

            return HttpResponseRedirect(reverse('staff:tasks:todo'))

        else:
            helptext_form = HelpTextForm(request.POST)
            slug = slugify(request.POST['slug'])
            title = request.POST['title']
            template = request.POST['template']
            order = request.POST['order']
            helptext_form = HelpText(title=title, template=template, slug=slug, order=order)
            helptext_form.save()

            return HttpResponseRedirect(reverse('staff:tasks:todo'))
    else:
        helptext_form = HelpTextForm()

    context = {'latest_order': latest_order, 'helps': helps, 'helptext_form': helptext_form, 'selected': selected, 'message': message}
    return render(request, 'staff/settings/helptexts.html', context)
Ejemplo n.º 2
0
def helptexts(request):
    helps = HelpText.objects.all()
    if helps:
        latest = HelpText.objects.filter().order_by('-order')[0]
        latest_order = latest.order + 1
    else:
        latest = None
        latest_order = 0
    selected = None
    message = None
    selected_help = request.GET.get('selected_help', None)
    if selected_help:
        selected = HelpText.objects.get(title=selected_help)

    if request.method == "POST":
        to_update = request.POST.get('id', None)
        if to_update:
            updated = HelpText.objects.get(id=to_update)
            updated.title = request.POST['title']
            slug = request.POST['slug']
            updated.slug = slugify(slug)
            updated.template = request.POST['template']
            updated.save()

            return HttpResponseRedirect(reverse('staff:tasks:todo'))

        else:
            helptext_form = HelpTextForm(request.POST)
            slug = slugify(request.POST['slug'])
            title = request.POST['title']
            template = request.POST['template']
            order = request.POST['order']
            helptext_form = HelpText(title=title,
                                     template=template,
                                     slug=slug,
                                     order=order)
            helptext_form.save()

            return HttpResponseRedirect(reverse('staff:tasks:todo'))
    else:
        helptext_form = HelpTextForm()

    context = {
        'latest_order': latest_order,
        'helps': helps,
        'helptext_form': helptext_form,
        'selected': selected,
        'message': message
    }
    return render(request, 'staff/settings/helptexts.html', context)