예제 #1
0
def edit_kr(request):
	if not request.is_ajax(): raise Http404

	if request.method == 'POST' and request.POST.has_key('id'):
		kr = get_object_or_404(KeyResult, 
			id=request.POST['id'], objective__user=request.user)
		form = KeyResultForm(request.POST, instance=kr)
		if form.is_valid():
			form.save()
			response = {
				'status': 'ok',
				'data': {
					'name': kr.name,
					'percentage': int(kr.percentage),
					'details': get_details(kr.type_data, kr.obtained, kr.expected),
					'percentage_total': int(kr.objective.percentage_total()),
				}
			}   
			return HttpResponse(json.dumps(response), mimetype='application/json')
		else:
			response = {
				'status': 'error',
				'data': form.errors
			}
			return HttpResponse(json.dumps(response), mimetype='application/json')
	else:	
		response = {'status': 'method-error'}                                                             
		return HttpResponseBadRequest(json.dumps(response), mimetype='application/json')
예제 #2
0
def edit_kr(request):
    if not request.is_ajax(): raise Http404

    if request.method == 'POST' and request.POST.has_key('id'):
        kr = get_object_or_404(KeyResult, id=request.POST['id'], objective__user=request.user)
        form = KeyResultForm(request.POST, instance=kr)
        if form.is_valid():
            form.save()
            response = {
                'status': 'ok',
                'data': {
                    'name': kr.name,
                    'percentage': int(kr.percentage),
                    'details': get_details(kr.type_data, kr.obtained, kr.expected),
                    'percentage_total': int(kr.objective.percentage_total()),
                }
            }
        else:
            response = {
                'status': 'error',
                'data': form.errors
            }
    else:
        response = {'status': 'method-error'}
    return JsonResponse(response)
예제 #3
0
def add_kr(request, o):
	obj = get_object_or_404(Objective, id=o, user=request.user)
	form = KeyResultForm(request.POST or None)
	if request.method == "POST" and form.is_valid():
		kr = form.save(commit=False)
		kr.objective = obj
		kr.save()
		return HttpResponseRedirect(reverse('okr:index'))
	context = {
		'form': form,
		'objective': obj
	}
	return render(request, "okr/add_kr.html", context)
예제 #4
0
def add_kr(request, o):
    obj = get_object_or_404(Objective, id=o, user=request.user)
    form = KeyResultForm(request.POST or None)
    if request.method == "POST" and form.is_valid():
        kr = form.save(commit=False)
        kr.objective = obj
        kr.save()
        return redirect('okr:index')
    context = {
        'form': form,
        'objective': obj
    }
    return render(request, "okr/add_kr.html", context)
예제 #5
0
def list_okrs(objectives_list, show_forms=False):
    okr_list = []
    for o in objectives_list:
        key_results_list = KeyResult.objects.filter(objective=o).order_by('-pub_date')

        keyresults = []
        if key_results_list:
            for k in key_results_list:
                keyresults.append({
                    'id': k.id,
                    'name': k.name,
                    'percentage': int(k.percentage),
                    'details': get_details(k.type_data, k.obtained, k.expected),
                })
                if show_forms:
                    keyresults[-1]['form'] = KeyResultForm(instance=k)

        okr_list.append({
            'objective': o,
            'percentage': int(o.percentage_total()),
            'keyresults': keyresults,
        })

    return okr_list
예제 #6
0
def create_kr_form(name, type_data, expected, obtained):
	return KeyResultForm(data={'name': name,
							   'type_data': type_data,
							   'expected': expected,
							   'obtained': obtained
	})