示例#1
0
def get_grade_weight(grade):
    if in_group(grade.user, employees):
        return grade.innovation.employee_grade_weight
    elif in_group(grade.user, students):
        return grade.innovation.student_grade_weight
    else:
        return 0
示例#2
0
def update_weights(request, id):
    innovation = get_object_or_404(Innovation, id=id)
    if in_group(request.user, administrators):
        if request.method == 'GET':
            form = WeightForm()
            return render(request, "innovations/update_weights.html",
                          {"form": form})
        if request.method == 'POST':
            form = WeightForm(data=request.POST)
            if form.is_valid():
                innovation.student_grade_weight = form.cleaned_data.get(
                    'student_grade_weight')
                innovation.employee_grade_weight = form.cleaned_data.get(
                    'employee_grade_weight')
                innovation.save()
            return redirect("details", id=id)
    else:
        return render(request, "permission_denied.html")
示例#3
0
def update_status(request, id):
    if not in_group(request.user, administrators):
        return render(request, "permission_denied.html")
    innovation = get_object_or_404(Innovation, id=id)
    if request.method == 'GET':
        form = StatusUpdateForm()
        form.fields["status"].choices = available_status_choices(
            request.user, innovation)
        return render(request, "innovations/update_status.html",
                      {"form": form})
    if request.method == "POST":
        form = StatusUpdateForm(data=request.POST)
        if form.is_valid():
            status = form.cleaned_data.get('status')
            status_substantiation = form.cleaned_data.get(
                'status_substantiation'),
            if try_update_status(request.user, innovation, status,
                                 status_substantiation):
                return redirect("details", id=id)
            else:
                return render(request, "permission_denied.html")
    return render(request,
                  "permission_denied.html")  # In case of strange data in form.
示例#4
0
def has_voting_access(user, innovation):
    has_voting_status = innovation.status in [Innovation.Status.VOTING]
    has_voting_privileges = (in_group(user, students) and innovation.student_grade_weight) or \
                            (in_group(user, employees) and innovation.employee_grade_weight)
    return has_voting_status and has_voting_privileges
示例#5
0
def set_status(request, id, status):
    if not in_group(request.user, administrators):
        return render(request, "permission_denied.html")
    innovation = get_object_or_404(Innovation, id=id)
    try_update_status(request.user, innovation, status)
    return redirect("details", id=id)
示例#6
0
def has_admin_access(user):
    return in_group(user, administrators)