def administer_project(request, project_id): project = get_object_or_404(ReadingAssignmentProject, pk=project_id) items = ReadingAssignmentItem.objects.filter(participation_project=project, is_active=True).distinct() item_details = [] for item in items: current_item_detail = cv.get_item_details(item, True) submissions = Submission.objects.filter(participation_item=item) num_submissions = submissions.count() current_item_detail["num_submissions"] = num_submissions submission_details = [] for s in submissions: user_id = s.user_profile.user.email if project.group: try: user_id = cm.GroupMembership.objects.get(group=project.group, member=s.user_profile).member_name except ObjectDoesNotExist: pass except MultipleObjectsReturned: user_id = "{}: WARNING: this user is registered multiple times for this {}".format(user_id, project.group.group_type) submission_detail = {"user_id": user_id, "responses": []} for tqr in s.textquestionresponse_set.all(): qr_detail = {"question": tqr.question.question_text, "response":tqr.response} submission_detail["responses"].append(qr_detail) submission_details.append(submission_detail) current_item_detail["submission_details"] = submission_details item_details.append(current_item_detail) return render(request, 'reading_assignment/project_results.html', {"items": item_details, "project":project, 'site': os.environ["SITE"]})
def overview(request, ignore): items = ToolReviewItem.objects.all()[:100] return render( request, 'tool_review/overview.html', { "items": [cv.get_item_details(i, True) for i in items if i.is_active], 'site': os.environ["SITE"], "tool_categories": [x[1] for x in TOOL_CATEGORIES], "project_categories": [x[1] for x in PROJECT_CATEGORIES] })
def administer_project(request, project_id): project = get_object_or_404(ToolReviewProject, pk=project_id) items = ToolReviewItem.objects.filter(participation_project=project) return render( request, 'core/project_admin_base.html', { "items": [cv.get_item_details(i, True) for i in items if i.is_active], "project": project, 'site': os.environ["SITE"] })
def administer_project(request, project_id): project = get_object_or_404(BeatTheBullshitProject, pk=project_id) items = BeatTheBullshitItem.objects.filter(participation_project=project, is_active=True).distinct() responses = QuoteFallacyQuizItemResponse.objects.filter( participation_item__participation_project=project).distinct() return render( request, 'beat_the_bullshit/project_admin.html', { "items": [cv.get_item_details(i, True) for i in items if i.is_active], "project": project, 'site': os.environ["SITE"], 'responses': responses })
def administer_project(request, project_id): project = get_object_or_404(BallotDeciderProject, pk=project_id) items = BallotDeciderItem.objects.filter(participation_project=project, is_active=True).distinct() item_details = [] for item in items: current_item_detail = cv.get_item_details(item, True) responses = POVToolResponse.objects.filter( participation_item=item).distinct() num_responses = responses.count() num_yes = responses.filter(final_decision__gt=0).count() num_no = responses.filter(final_decision__lt=0).count() num_undecided = responses.filter(final_decision=0).count() num_extreme = responses.filter(final_decision__abs__gt=.15).count() current_item_detail["num_decisions"] = num_responses current_item_detail["outcome"] = "Num Yes:" + str( num_yes) + ", Num No:" + str(num_no) + ", Num undecided:" + str( num_undecided) if num_responses == 0: current_item_detail["fraction_strong"] = 0.0 else: current_item_detail[ "fraction_strong"] = 1.0 * num_extreme / responses.count() pov_details = [] for pov in PointOfView.objects.filter( ballotdeciderproject=project).distinct(): current_pov_detail = dict() current_pov_detail["quote"] = pov.quote pov_item_responses = POVItemResponse.objects.filter( point_of_view=pov) scores = [x.score for x in pov_item_responses] current_pov_detail["num"] = len(scores) current_pov_detail["avg"] = np.mean(scores) current_pov_detail["stdev"] = np.std(scores) pov_details.append(current_pov_detail) current_item_detail["povs"] = pov_details item_details.append(current_item_detail) return render(request, 'ballot_decider/project_results.html', { "items": item_details, "project": project, 'site': os.environ["SITE"] })
def administer_project(request, project_id): project = get_object_or_404(LandUseProject, pk=project_id) questions = project.get_questions() items = LandUseParticipationItem.objects.filter( participation_project=project, is_active=True).distinct() item_details = [] for item in items: current_item_detail = cv.get_item_details(item, True) responses = ItemResponse.objects.filter(participation_item=item) num_responses = responses.count() question_summaries = [] for q in questions: summary = dict() summary["label"] = q.question_text try: tmcq = q.tmcq except: raise Exception("Invalid question type. Only TMCQ supported") else: response_counts = TMCQResponse.objects.filter( item_response__participation_item=item).filter( question=q).values('option_index').annotate( count=Count("id")) rc_option_indices = [ x["option_index"] for x in response_counts ] answers = [] for i in range(1, 6): question = None if i == 1: question = tmcq.option1 elif i == 2: question = tmcq.option2 elif i == 3: question = tmcq.option3 elif i == 4: question = tmcq.option4 elif i == 5: question = tmcq.option5 rc = [x for x in response_counts if x["option_index"] == i] if len(rc) == 1: answers.append([question, rc[0]["count"]]) else: answers.append([question, 0]) summary["answers"] = answers question_summaries.append(summary) current_item_detail["question_summaries"] = question_summaries current_item_detail["num_responses"] = num_responses item_details.append(current_item_detail) return render(request, 'land_use_planning/project_results.html', { "items": item_details, "project": project, 'site': os.environ["SITE"] })
def participate(request, item_id): (profile, permissions, is_default) = cv.get_profile_and_permissions(request) item = BallotDeciderItem.objects.get(pk=item_id) context = cv.get_default_og_metadata(request, item) project = item.participation_project.ballotdeciderproject context.update({ "ballot": project, "basics": [ cv.get_item_details(i, False) for i in project.basics.all() if i.is_active ], "effects": [ cv.get_item_details(i, False) for i in project.effects.all() if i.is_active ], 'site': os.environ["SITE"], "item": item }) if not request.method == "POST": return render(request, 'ballot_decider/participate.html', context) if request.method == 'POST' and request.is_ajax(): submission_data = json.loads(request.body.strip()) form = ParticipateForm(item, submission_data) if form.is_valid(): submission = POVToolResponse() submission.user_profile = profile submission.participation_item = item submission.save() for k in form.cleaned_data.keys(): if "pov_weight" in k: pov_id = int(k.replace("pov_weight_", "")) pov = PointOfView.objects.get(id=pov_id) item_response = POVItemResponse() item_response.point_of_view = pov item_response.score = int(form.cleaned_data[k]) item_response.tool_response = submission item_response.save() decision, explanation = submission.generate_decision() submission.final_decision = decision submission.save() content = dict() content["reveal"] = ["response"] content["hide"] = ["ajax_form"] content["explanation"] = explanation if decision == 0: content["reveal"].append("no-decision") elif decision >= .15: content["reveal"].append("strong-yes") elif decision > 0: content["reveal"].append("lean-yes") elif decision <= -.15: content["reveal"].append("strong-no") elif decision < 0: content["reveal"].append("lean-no") return JsonResponse(content) else: return HttpResponse("sorry, the form isn't valid")