Ejemplo n.º 1
0
def create_draw(request):
    """create_draw ws
    """
    # DEPRECATE
    LOG.debug("Received post data: {0}".format(request.POST))

    draw_type = request.POST.get("draw_type")
    if not draw_type:
        return HttpResponseBadRequest("Missing post argument draw_type")

    draw_form = draw_factory.create_form(draw_type, request.POST)
    try:
        bom_draw = draw_form.build_draw()
    except DrawFormError:
        LOG.info("Form not valid: {0}".format(draw_form.errors))
        return HttpResponseBadRequest("Not valid")
    else:
        bom_draw._id = None  # Ensure we have no id
        set_owner(bom_draw, request)
        MONGO.save_draw(bom_draw)
        LOG.info("Generated draw: {0}".format(bom_draw))
        ga_track_draw(bom_draw, "create_draw")
        #  notify users if any
        if bom_draw.users:
            invite_user(bom_draw.users, bom_draw.pk, bom_draw.owner)
        draw_url = reverse('retrieve_draw', args=(bom_draw.pk, ))
        return JsonResponse({'draw_url': draw_url})
Ejemplo n.º 2
0
def create_draw(request, draw_type, is_public):
    """create_draw view
    @param
    Serves the page to create a draw (empty) form
        and handles the creation of a draw.
    When received a GET request returns an empty form to create a draw
        and with a POST and data attempts to create a draw. If success,
        redirects to the draw, otherwise, returns the form with the errors.
    """

    is_public = is_public or is_public == 'True'

    if request.method == 'GET':
        LOG.debug("Serving view to create a draw: {0}".format(draw_type))
        draw_form = draw_factory.create_form(draw_type)
        return render(request, 'draws/new_draw.html',
                      {"draw": draw_form, "is_public": is_public, "draw_type": draw_type, "default_title": draw_form.DEFAULT_TITLE})
    else:
        LOG.debug("Received post data: {0}".format(request.POST))
        draw_form = draw_factory.create_form(draw_type, request.POST)
        try:
            bom_draw = draw_form.build_draw()
        except DrawFormError:
            return render(request, 'draws/new_draw.html',
                          {"draw": draw_form, "is_public": is_public, "draw_type": draw_type})
        else:
            bom_draw._id = None  # Ensure we have no id
            set_owner(bom_draw, request)
            #  generate a result if a private draw
            if not bom_draw.is_shared:
                bom_draw.toss()

            MONGO.save_draw(bom_draw)
            LOG.info("Generated draw: {0}".format(bom_draw))
            ga_track_draw(bom_draw, "create_draw")
            #  notify users if any
            if bom_draw.users:
                invite_user(bom_draw.users, bom_draw.pk, bom_draw.owner)

            return redirect('retrieve_draw', draw_id=bom_draw.pk)