Пример #1
0
def createSelections(jsonArray):
    # iterate over all
    list = []
    for json in jsonArray:
        s = Selection(time=json['duration'], connection=json['connection'], device=get_device(json), content=json['service'])
        s.save()    
        list.append(s)
    return list    
Пример #2
0
def project_selection(request, project_id):
    user = get_object_or_404(User, pk=request.user.pk)
    project = get_object_or_404(Project, pk=project_id)

    if request.method == "POST":
        print request.POST.get("user")
        thumbs_up = request.POST.get("thumbsUp")
        user_id = request.session["_auth_user_id"]
        print user_id
        vote_status = _("Thumbs Up")

        try:
            selection = get_object_or_404(Selection, user_id=user_id, project_id=project_id)
        except Http404:
            selection = Selection()
            selection.user = user
            selection.project = project

        if thumbs_up == "true":
            selection.passed = True
        else:
            selection.passed = False
            vote_status = _("Thumbs Down")
        selection.date = datetime.utcnow()
        selection.save()

        event = {
            "time": datetime.now(),
            "project_id": int(project_id),
            "message": u"{} ".format(user.username) + _("Expert has voted") + u":{}".format(vote_status),
        }
        create_log(event)

        query_set = Selection.objects.filter(pk=selection.id)
        data = serializers.serialize("json", query_set)
        print data
        return HttpResponse(data, content_type="application/json")
        # return HttpResponse(json.dumps(selection), content_type="application/json")
    else:
        selections = Selection.objects.filter(project_id=project_id)
        print selections
        print user.has_perm("enterprise.approve_submission")
        print user.has_perm("enterprise.add_submission")
        return render(
            request, "project_selection.html", {"selections": selections, "project": project, "project_id": project_id}
        )