Ejemplo n.º 1
0
def website_page_update(request, childcare_slug, page_id):
    childcare = get_object_or_404(Childcare, slug=childcare_slug)
    page = get_object_or_404(Page, pk=page_id, childcare=childcare)
    if request.method == 'POST':
        form = WebsitePageCreateForm(data=request.POST, instance=page)
        if form.is_valid():
            form.save()
            log.info(log_prefix+'Page updated (%s: %s, user: %s)' % (childcare.name, page.title, request.user))
            return HttpResponseRedirect(reverse('childcare:page_list', kwargs={'childcare_slug': childcare.slug}))
    else:
        form = WebsitePageCreateForm(instance=page)
    return render(request, 'childcare/website_page_update.html', {'form': form,
                                                                  'childcare': childcare,
                                                                  'page': page})
Ejemplo n.º 2
0
def website_page_create(request, childcare_slug):
    childcare = get_object_or_404(Childcare, slug=childcare_slug)
    if request.method == 'POST':
        form = WebsitePageCreateForm(request.POST)
        if form.is_valid():
            obj = form.save(commit=False)
            obj.childcare = childcare
            obj.save
            form.save(commit=True)
            log.info(log_prefix+'Page created (childcare: %s, user: %s)' % (childcare.name, request.user))
            return HttpResponseRedirect(reverse('childcare:page_list', kwargs={'childcare_slug': childcare.slug}))
    else:
        form = WebsitePageCreateForm()
    return render(request, 'childcare/website_page_create.html', {'form': form, 'childcare': childcare})