Exemplo n.º 1
0
def mishna_campaign(request):

	# normalize URL
	if request.path != "/translate/Mishnah":
		return redirect("/translate/Mishnah", permanent=True)

	# expire old locks
	sefaria.locks.expire_locks()

	if "random" in request.GET:
		# choose a random Mishnah
		ref = {"error": "haven't chosen yet"}
		while "error" in ref:
			mishnas = db.index.find({"categories.0": "Mishna"}).distinct("title")
			mishna = choice(mishnas)
			ref = next_translation(mishna)
	else:
		# choose the next Mishnah in order
		skip = 0
		ref = {"error": "haven't chosen yet"}
		while "error" in ref:
			text = next_text("Mishna", skip=skip)
			ref = next_translation(text)
			skip += 1
	
	# get the assigned text
	assigned = get_text(ref, context=0, commentary=False)
	
	# get percentage and remaining counts
	percent = {
		"text":  get_percent_available(assigned["book"]),
		"order": get_percent_available(assigned["categories"]),
		"total": get_percent_available(assigned["categories"][0]),
	}
	remaining = {
		"text":  get_remaining_translation_count(assigned["book"], unit="Mishna"),
		"order": get_remaining_translation_count(assigned["categories"], unit="Mishna"),
		"total": get_remaining_translation_count(assigned["categories"][0], unit="Mishna"),
	}

	# Put a lock on this assignment
	user = request.user.id if request.user.is_authenticated() else 0
	sefaria.locks.set_lock(ref, "en", "Sefaria Community Translation", user)

	return render_to_response('translate_campaign.html', 
									{"title": "Help Create a Free English Mishnah",
									"assigned_ref": ref,
									"assigned_ref_url": url_ref(ref),
									"assigned_text": assigned["he"],
									"assigned": assigned,
									"remaining": remaining,
									"percent": percent,
									"thanks": "thank" in request.GET,
									'toc': get_toc(),
									"titlesJSON": json.dumps(get_text_titles()),
									},
									RequestContext(request))
Exemplo n.º 2
0
def mishna_campaign(request):

	mishnas = db.index.find({"categories.0": "Mishna"}).distinct("title")
	mishna = choice(mishnas)
	ref = next_translation(mishna)
	if "error" in ref:
		return redirect(request.path)
	assigned = get_text(ref, context=0, commentary=False)
	toc = get_toc()
	mtoc = toc[1]
	remaining = mtoc["availableCounts"]["he"]["Mishna"] - mtoc["availableCounts"]["en"]["Mishna"]
	percent = mtoc["percentAvailable"]["en"]



	return render_to_response('translate_campaign.html', 
									{"title": "Create a Free English Mishnah",
									"assigned_ref": ref,
									"assigned_ref_url": url_ref(ref),
									"assigned_text": assigned["he"],
									"assigned": assigned,
									"remaining": remaining,
									"percent": percent,
									'toc': toc,
									"titlesJSON": json.dumps(get_text_titles()),
									},
									RequestContext(request))
Exemplo n.º 3
0
def mishna_campaign(request):

	mishnas = db.index.find({"categories.0": "Mishna"}).distinct("title")
	mishna = choice(mishnas)
	ref = next_translation(mishna)
	if "error" in ref:
		return jsonResponse(ref)
	assigned = get_text(ref, context=0, commentary=False)

	return render_to_response('translate_campaign.html', 
									{"title": "Create a Free English Mishna",
									"assigned_ref": ref,
									"assigned_text": assigned["he"],
									"assigned": assigned,
									'toc': get_toc(),
									"titlesJSON": json.dumps(get_text_titles()),
									},
									RequestContext(request))
Exemplo n.º 4
0
def mishna_campaign(request):

    # normalize URL
    if request.path != "/translate/Mishnah":
        return redirect("/translate/Mishnah", permanent=True)

    # expire old locks
    sefaria.locks.expire_locks()

    if "random" in request.GET:
        # choose a random Mishnah
        ref = {"error": "haven't chosen yet"}
        while "error" in ref:
            mishnas = db.index.find({
                "categories.0": "Mishna"
            }).distinct("title")
            mishna = choice(mishnas)
            ref = next_translation(mishna)
    else:
        # choose the next Mishnah in order
        skip = 0
        ref = {"error": "haven't chosen yet"}
        while "error" in ref:
            text = next_text("Mishna", skip=skip)
            ref = next_translation(text)
            skip += 1

    # get the assigned text
    assigned = get_text(ref, context=0, commentary=False)

    # get percentage and remaining counts
    percent = {
        "text": get_percent_available(assigned["book"]),
        "order": get_percent_available(assigned["categories"]),
        "total": get_percent_available(assigned["categories"][0]),
    }
    remaining = {
        "text":
        get_remaining_translation_count(assigned["book"], unit="Mishna"),
        "order":
        get_remaining_translation_count(assigned["categories"], unit="Mishna"),
        "total":
        get_remaining_translation_count(assigned["categories"][0],
                                        unit="Mishna"),
    }

    # Put a lock on this assignment
    user = request.user.id if request.user.is_authenticated() else 0
    sefaria.locks.set_lock(ref, "en", "Sefaria Community Translation", user)

    return render_to_response(
        'translate_campaign.html', {
            "title": "Help Create a Free English Mishnah",
            "assigned_ref": ref,
            "assigned_ref_url": url_ref(ref),
            "assigned_text": assigned["he"],
            "assigned": assigned,
            "remaining": remaining,
            "percent": percent,
            "thanks": "thank" in request.GET,
            'toc': get_toc(),
            "titlesJSON": json.dumps(get_text_titles()),
        }, RequestContext(request))
Exemplo n.º 5
0
def mishna_campaign(request):

    # normalize URL
    if request.path != "/translate/Mishnah":
        return redirect("/translate/Mishnah", permanent=True)

        # expire old locks
    sefaria.locks.expire_locks()

    if "random" in request.GET:
        # choose a random Mishnah
        ref = {"error": "haven't chosen yet"}
        while "error" in ref:
            mishnas = db.index.find({"categories.0": "Mishna"}).distinct("title")
            mishna = choice(mishnas)
            ref = next_translation(mishna)
            next = mishna

    elif "text" in request.GET:
        # choose the next text requested in URL
        text = norm_ref(request.GET["text"])
        next = text
        if get_percent_available(text) == 100:
            return HttpResponse("%s is complete! Work on <a href='/translate/Mishnah'>another Mishnah</a>.")
        ref = next_translation(text)
        if "error" in ref:
            return HttpResponse(
                "All remainging Mishnahs in %s are being worked on by other contributors. Work on <a href='/translate/Mishnah'>another Mishnah</a> for now."
            )

    else:
        # choose the next Mishnah in order
        skip = 0
        ref = {"error": "haven't chosen yet"}
        while "error" in ref:
            text = next_text("Mishna", skip=skip)
            ref = next_translation(text)
            skip += 1
        next = None

        # get the assigned text
    assigned = get_text(ref, context=0, commentary=False)

    # get percentage and remaining counts
    percent = {
        "text": get_percent_available(assigned["book"]),
        "order": get_percent_available(assigned["categories"]),
        "total": get_percent_available(assigned["categories"][0]),
    }
    remaining = {
        "text": get_remaining_translation_count(assigned["book"], unit="Mishna"),
        "order": get_remaining_translation_count(assigned["categories"], unit="Mishna"),
        "total": get_remaining_translation_count(assigned["categories"][0], unit="Mishna"),
    }

    # Put a lock on this assignment
    user = request.user.id if request.user.is_authenticated() else 0
    sefaria.locks.set_lock(ref, "en", "Sefaria Community Translation", user)

    return render_to_response(
        "translate_campaign.html",
        {
            "title": "Help Create a Free English Mishnah",
            "assigned_ref": ref,
            "assigned_ref_url": url_ref(ref),
            "assigned_text": assigned["he"],
            "assigned": assigned,
            "remaining": remaining,
            "percent": percent,
            "thanks": "thank" in request.GET,
            "next_text": next,
            "toc": get_toc(),
            "titlesJSON": json.dumps(get_text_titles()),
        },
        RequestContext(request),
    )