Ejemplo n.º 1
0
def fortune_callback(record):
    """Process a fortune record"""
    form = FortuneForm(data=record)
    if form.is_valid():
        fortune = form.save(origin=constants.ORIGIN_IMPORTED)
        fortune.accept()
        return True
    else:
        for field, messages in form.errors.items():
            for msg in messages:
                print >> sys.stderr, "ERROR en el campo '%s': %s" % (field, msg)
        return False
Ejemplo n.º 2
0
def index(request, template='fortunes/index.html'):
    """Main view of fortunes app"""

    form = FortuneForm()
    fortune = None

    if request.method == 'POST':
        form = FortuneForm(data=request.POST)

        if form.is_valid():
            remote_addr = request.META.get('REMOTE_ADDR', None)
            fortune = form.save(remote_addr=remote_addr)
            set_message(strings.FORTUNE_CREATED_MSG, request)
            return HttpResponseRedirect(reverse('homepage'))

    random_fortune = Fortune.objects.random(exclude=fortune)

    return direct_to_template(
                request,
                template,
                {'form': form,
                 'random_fortune': random_fortune
                }
           )