예제 #1
0
    def save(self):
        if not self.is_valid():
            raise Exception('The form must be valid in order to save')
        title = self.cleaned_data['title']
        template = self.cleaned_data['template']
        slug = self.cleaned_data['slug']
        order = self.cleaned_data['order']

        help_text = HelpText(title=title, template=template, slug=slug, order=order)
        help_text.save()

        return help_text
예제 #2
0
    def save(self):
        if not self.is_valid():
            raise Exception('The form must be valid in order to save')
        title = self.cleaned_data['title']
        template = self.cleaned_data['template']
        slug = self.cleaned_data['slug']
        order = self.cleaned_data['order']

        help_text = HelpText(title=title, template=template, slug=slug, order=order)
        help_text.save()

        return help_text
예제 #3
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)