Exemplo n.º 1
0
def password(request, slug):
    """ process the password for a page"""
    try:
        page = Page.custom.visible().get(slug=slug)
    except Page.DoesNotExist:
        raise Http404()

    # if there is no password for the page redirect back
    if not page.password:
        return HttpResponseRedirect(
                reverse('ccpages:view', args=[page.slug]))
    # make a form
    form = PagePasswordForm()

    # check the post
    if request.method == 'POST':
        form = PagePasswordForm(request.POST, page=page)
        if form.is_valid():
             request.session['ccpage_%s_hash' % page.pk] = form.hash
             return HttpResponseRedirect(
                     reverse('ccpages:view', args=[page.slug]))

    return render_to_response(
            'ccpages/password.html',
            {
                'page': page,
                'form': form },
            RequestContext(request))
Exemplo n.º 2
0
 def test_supply_correct_password_and_form_is_valid(self):
     """If we supply the correct password to the form then the
     form will validate"""
     page1 = Page()
     page1.title = '1'
     page1.slug = '1'
     page1.content = '1'
     page1.order = Decimal('1')
     page1.password = '******'
     page1.status = Page.VISIBLE
     page1.save()
     # make the data
     data = {'password': '******'}
     # make the form
     form = PagePasswordForm(data, page=page1)
     # form is valid
     self.assertTrue(form.is_valid())