示例#1
0
    def test_is_system_url(self):
        # The front page is not a system URL
        UNUSED_SYSTEM_URL = '/'

        # This system URL is not expected to change
        USED_SYSTEM_URL = '/innmelding/'

        self.assertEqual(is_system_url(UNUSED_SYSTEM_URL, self.central_site), False)
        self.assertEqual(is_system_url(USED_SYSTEM_URL, self.central_site), True)
示例#2
0
def new(request, site):
    active_site = Site.get_cached_by_id(site)

    if request.method != 'POST':
        return redirect('admin:sites.pages.page.list', active_site.id)

    slug = request.POST['slug'].strip().strip('/')

    unused_system_url = not is_system_url(slug, active_site)
    unused_page_slug = Page.slug_is_unique(slug, active_site)

    if not unused_system_url or not unused_page_slug:
        messages.error(request, 'slug_not_unique')
        return redirect('admin:sites.pages.page.new', active_site.id)

    page = Page(
        title=request.POST['title'],
        slug=slug,
        published=False,
        created_by=request.user,
        parent=Page.objects.get(id=request.POST['parent_id']),
        site=active_site,
    )
    page.save()

    version = Version(
        page=page,
        article=None,
        version=1,
        owner=request.user,
        active=True,
    )
    version.save()

    create_template(request.POST['template'], version)
    return redirect('admin:sites.pages.page.edit', active_site.id, version.id)
示例#3
0
def check_slug(request, site):
    active_site = Site.get_cached_by_id(site)
    slug = request.POST['slug'].strip()
    unused_system_url = not is_system_url(slug, active_site)
    unused_page_slug = Page.slug_is_unique(slug=slug, site=active_site, exclude_id=request.POST.get('exclude'))
    return HttpResponse(json.dumps({'valid': unused_system_url and unused_page_slug}))