Exemple #1
0
def tasklist_post(request, slug):
	tl = get_object_or_404(TaskList, slug=slug)
	if "post" not in tl.get_user_roles(request.user):
		return HttpResponseForbidden()

	if request.POST.get("incoming") in (None, ""):
		incoming = TaskList.new(request.user)
	else:
		incoming = get_object_or_404(TaskList, id=request.POST.get("incoming"))
		if "admin" not in tl.get_user_roles(request.user):
			return HttpResponseForbidden()

	# create the task
	t = Task.new(request.user, incoming, tl)

	# update with initial properties
	t.title = str(request.POST.get("title")).strip()
	t.notes = str(request.POST.get("note")).strip()
	t.autoclose = request.POST.get("autoclose") != None
	t.save()

	return { "status": "ok" }
Exemple #2
0
def tasklist_post(request):
    # the "outgoing" (assigner) list
    if request.user.is_authenticated():
        outgoing = get_object_or_404(TaskList, id=request.POST.get("outgoing"))
        if "admin" not in outgoing.get_user_roles(request.user):
            return HttpResponseForbidden()
    else:
        # this is an anonymous task
        outgoing = None

    # the incoming (assignee) list
    m = re.match(r".* \[#(\d+)\]$", request.POST.get("incoming", ""))
    if m:
        incoming = get_object_or_404(TaskList, id=int(m.group(1)))
    else:
        try:
            id = int(request.POST.get("incoming"))
        except ValueError:
            return {
                "status": "error",
                "msg": "That is not a recipient we know."
            }
        incoming = get_object_or_404(TaskList, id=id)

    if "post" not in incoming.get_user_roles(request.user):
        return HttpResponseForbidden()

    # create the task
    t = Task.new(request.user, outgoing, incoming)

    # update with initial properties
    t.title = str(request.POST.get("title")).strip()
    t.notes = str(request.POST.get("note")).strip()

    # if the user is anonymous, store the user's email in the task
    # and also a random UUID so the user can claim it after registering
    if not request.user.is_authenticated():
        # assign a random UUID to this task so the user can claim it later
        claim_id = request.POST.get("claim_id", "")

        # validate that the user provided a valid claim ID, or if one was
        # not provided make one.
        if len(claim_id.strip()) != 32 or not Task.objects.filter(
                anonymous_claim_id=claim_id).exists():
            claim_id = ""
        if claim_id == "":
            import uuid
            claim_id = uuid.uuid4().hex

        t.metadata = {"owner_email": request.POST.get("assigner_email")}
        t.anonymous_claim_id = claim_id

    t.save()

    # render the task for the response
    from django.template import Context, Template, loader as template_loader
    prepare_for_view(t, request)
    template = template_loader.get_template("task.html")
    task_html = template.render(
        Context({
            "task": t,
            "user": request.user,
            "incoming_outgoing": request.POST.get("view_orientation"),
        }))

    return {
        "status": "ok",
        "task_html": task_html,
        "state": t.state,
        "is_self_task": (incoming == outgoing),
        "anonymous_claim_id": t.anonymous_claim_id,
    }
Exemple #3
0
def tasklist_post(request):
	# the "outgoing" (assigner) list
	if request.user.is_authenticated():
		outgoing = get_object_or_404(TaskList, id=request.POST.get("outgoing"))
		if "admin" not in outgoing.get_user_roles(request.user):
			return HttpResponseForbidden()
	else:
		# this is an anonymous task
		outgoing = None

	# the incoming (assignee) list
	m = re.match(r".* \[#(\d+)\]$", request.POST.get("incoming", ""))
	if m:
		incoming = get_object_or_404(TaskList, id=int(m.group(1)))
	else:
		try:
			id = int(request.POST.get("incoming"))
		except ValueError:
			return { "status": "error", "msg": "That is not a recipient we know." }
		incoming = get_object_or_404(TaskList, id=id)

	if "post" not in incoming.get_user_roles(request.user):
		return HttpResponseForbidden()

	# create the task
	t = Task.new(request.user, outgoing, incoming)

	# update with initial properties
	t.title = str(request.POST.get("title")).strip()
	t.notes = str(request.POST.get("note")).strip()

	# if the user is anonymous, store the user's email in the task
	# and also a random UUID so the user can claim it after registering
	if not request.user.is_authenticated():
		# assign a random UUID to this task so the user can claim it later
		claim_id = request.POST.get("claim_id", "")

		# validate that the user provided a valid claim ID, or if one was
		# not provided make one.
		if len(claim_id.strip()) != 32 or not Task.objects.filter(anonymous_claim_id=claim_id).exists():
			claim_id = ""
		if claim_id == "":
			import uuid
			claim_id = uuid.uuid4().hex

		t.metadata = { "owner_email": request.POST.get("assigner_email") }
		t.anonymous_claim_id = claim_id

	t.save()

	# render the task for the response
	from django.template import Context, Template, loader as template_loader
	prepare_for_view(t, request)
	template = template_loader.get_template("task.html")
	task_html = template.render(Context({
		"task": t,
		"user": request.user,
		"incoming_outgoing": request.POST.get("view_orientation"),
	}))

	return {
		"status": "ok",
		"task_html": task_html,
		"state": t.state,
		"is_self_task": (incoming == outgoing),
		"anonymous_claim_id": t.anonymous_claim_id,
		 }