Exemplo n.º 1
0
def manage(request, email=None):
    """
    Provide a way to manage all subscriptions for a user
    """
    message = []
    if request.method == 'GET' and email:
        if is_json_request(request):
            return JSONResponse({
                'newsletters': get_newsletters_with_subs(email)})
        form = NewsletterForm(initial={'email': email})
    elif request.method == 'GET' and email is None:
        return HttpResponseRedirect(
            reverse('newsletters_list'))
    elif request.method == 'POST':
        form = NewsletterForm(request.POST)
        if form.is_valid():
            unsubs, subs = sync_subscriptions(form)
            if unsubs:
                message.append(
                    "Successfully unsubscribed from %s" % 
                    ', '.join(map(unicode, unsubs)))
            if subs:
                message.append(
                    "Successfully subscribed to %s" % 
                    ', '.join(map(unicode,subs)))
        if is_json_request(request):
            return JSONResponse({
                'newsletters': get_newsletters_with_subs(email),
                'messages': message})
    return render_to_response('newsletters/manage.html', {
        'newsletters': Newsletter.objects.all(),
        'form': form,
        'messages': message
    }, RequestContext(request))
Exemplo n.º 2
0
    def test_newsletter_with_valid_template_works(self):
        data = dict(
            title = 'fake-title',
            slug = 'fake-slug',
            template = 'newsletters/newsletter_template.html',
            body = 'fake-body'
        )

        form = NewsletterForm(data)
        self.assertTrue(form.is_valid(), form.errors)
Exemplo n.º 3
0
    def test_newsletter_with_invalid_template_dit_not_work(self):
        data = dict(
            title = 'fake-title',
            slug = 'fake-slug',
            template = 'fake-template',
            body = 'fake-body'
        )

        form = NewsletterForm(data)
        self.assertFalse(form.is_valid())
Exemplo n.º 4
0
def login(request):
    template = "login.html"

    if request.method == "POST":
        form = NewsletterForm(request.POST)

        if form.is_valid():
            form.save()
    
    else:
        form = NewsletterForm

    context = {
    'form': form,
    }
    return render (request, template, context)
Exemplo n.º 5
0
def habitacion_vip(request):
    template = "sigle-room.html"

    if request.method == "POST":
        form = NewsletterForm(request.POST)

        if form.is_valid():
            form.save()
    
    else:
        form = NewsletterForm

    context = {
    'form': form,
    }
    return render (request, template, context)
Exemplo n.º 6
0
def sobre_nosotros(request):
    template = "about.html"

    if request.method == "POST":
        form = NewsletterForm(request.POST)

        if form.is_valid():
            form.save()
    
    else:
        form = NewsletterForm

    context = {
    'form': form,
    }
    return render (request, template, context)
Exemplo n.º 7
0
def registro(request):
    template = "base.html"

    if request.method == "POST":
        form = NewsletterForm(request.POST)

        if form.is_valid():
            form.save()

    else:
        form = NewsletterForm

    context = {
        'form': form,
    }
    return render(request, template, context)

    def logout(request):
        do_logout(request)
        return redirect('/')
Exemplo n.º 8
0
def contacto(request):
    template = "contact.html"

    if request.method == "POST":
        form = ContactoForm(request.POST)

        if form.is_valid():
            form.save()

        if request.method == "POST":
            form = NewsletterForm(request.POST)

            if form.is_valid():
                form.save()

            return redirect('/thanks/')
    else:
        form = ContactoForm

    context = {
        'form': form,
    }
    return render(request, template, context)