예제 #1
0
def DeleteDataSet(request):
    #get the dataset by "id" by passing the dataset's id to the "GetDataset" method in the JSONDataSet.py file
    dataset = JSONDataSet.GetDataset(request.GET.get('id'))
    #after getting the desired dataset, it passed to DeleteDataSet method in the the JSONDataSet.py file
    dataset.DeleteDataSet(request.user)
    username = request.user.username

    return redirect('http://127.0.0.1:8000/userpage/')
예제 #2
0
def profile(request):
    data = list(
        map(lambda x: x.json_dict["title"],
            JSONDataSet.GetDatasets(request.user)))
    datasets = JSONDataSet.GetDatasets(request.user)
    username = request.user.username

    data = list()
    for d in datasets:
        temp = dict()
        temp['id'] = d.id
        temp['name'] = d.json_dict["title"]
        data.append(temp)

    return render(request, 'profile.html', {
        "data": data,
        "username": username
    })
예제 #3
0
def deleteData(request):
    toreturn = dict()
    #get the dataset by "id" by passing the dataset's id to the "GetDataset" method in the JSONDataSet.py file
    dataset = JSONDataSet.GetDataset(request.POST.get("itemId"))
    #after getting the desired dataset, it passed to DeleteDataSet method in the the JSONDataSet.py file
    dataset.DeleteDataSet(request.user)
    toreturn["results"] = True

    return JsonResponse(toreturn)
예제 #4
0
def colSelect(request):
    parameter = request.GET.get('dataset', '')
    if parameter != "":
        dataset = JSONDataSet.GetDataset(parameter)
    else:
        return render(request, 'index.html')

    questions = dataset.GetQuestions(True)
    context = {'questions': questions, 'id': parameter}
    return render(request, 'colSelect.html', context)
예제 #5
0
def setCols(request):
    toreturn = dict()
    try:
        dataset = JSONDataSet.GetDataset(request.POST.get('id'))
        dataset.SetCols(request.POST.getlist('cols[]'))
        dataset.SaveDataset(request.user)
        toreturn['result'] = True
    except Exception as e:
        toreturn['result'] = False
        toreturn['message'] = str(e)
    return JsonResponse(toreturn)
예제 #6
0
def RemoveItemTag(request):
    toreturn = dict()
    try:
        dataset = JSONDataSet.GetDataset(request.POST.get("id"))
        dataset.RemoveItemTag(request.POST.get("rid"), request.POST.get("tag"))
        dataset.SaveDataset(request.user)
        toreturn['results'] = True
    except Exception as e:
        toreturn['results'] = False
        toreturn['message'] = str(e)

    return JsonResponse(toreturn)
예제 #7
0
def ExportCSV(request):
    dataset = JSONDataSet.GetDataset(request.GET.get('id'))
    dataset.ExportCSV(request.user)

    file_name = dataset.json_dict['title'] + ".csv"
    fpntr = File(open("media/tmp/" + file_name))

    response = HttpResponse(fpntr, content_type="text/csv")
    response['Content-Disposition'] = 'attachment; filename=%s' % smart_str(file_name)

    os.remove("media/tmp/" + file_name)

    return response
예제 #8
0
def ExportXLSX(request):
    dataset = JSONDataSet.GetDataset(request.GET.get('id'))
    dataset.ExportXLSX(request.user)

    file_name = dataset.json_dict['title'] + ".xlsx"
    fpntr = File(open("media/tmp/" + file_name, 'rb'))

    response = HttpResponse(fpntr, content_type="application/vnd.openxmlformats-officedocument.spreadsheetml.sheet")
    response['Content-Disposition'] = 'attachment; filename=%s' % smart_str(file_name)

    os.remove("media/tmp/" + file_name)

    return response
예제 #9
0
def importing(request):
    form = FileForm(request.POST or None)
    if request.method == 'POST':
        form = FileForm(request.POST, request.FILES)
        if form.is_valid():
            f = request.FILES['file']
            # TODO: should probably get the file type in a better way than looking at the extension (similar to linux `file`?)
            # file exension really says nothing about the type
            if os.path.splitext(f.name)[1] == ".csv":
                filetype = FileType.CSV
            elif os.path.splitext(f.name)[1] == ".xlsx":
                filetype = FileType.XLSX
            else:
                # TODO: correct way to error out here?
                context1 = {
                    'error': True,
                    'message': "Incorrect file extension",
                }
                return render(request, 'importing.html', { 'context': context1, 'form': form })

            filepath = saveUploadedFile(f) # save file to disk temporarily

            name = request.POST.get("name", "")
            description = request.POST.get("description", "")

            try:
                data = JSONDataSet(filepath, filetype, name, description)
                data.SaveDataset(request.user) # save dataset to database as json
            except InputException as e:
                # TODO: correct way to error out here?
                os.remove(filepath) # delete the temporary file
                context2 = {
                    'error': True,
                    'message': str(e),
                }
                return render(request, 'importing.html', {'context': context2, 'form': form })

            os.remove(filepath) # delete the temporary file

            data = list(map(lambda x: x.json_dict["title"], JSONDataSet.GetDatasets(request.user)))
            datasets = JSONDataSet.GetDatasets(request.user)
            username = request.user.username

            data = list()
            for d in datasets:
                temp = dict()
                temp['id'] = d.id
                temp['name'] = d.json_dict["title"]
                data.append(temp)

            return redirect('http://127.0.0.1:8000/colSelect?dataset=' + str(d.id))

    return render(request, 'importing.html', { 'form': form })
예제 #10
0
def TagItem(request):
    toreturn = dict()
    try:
        dataset = JSONDataSet.GetDataset(request.POST.get("datasetId"))
        if (dataset.ItemHasTag(request.POST.get("rid"), request.POST.getlist('tags[]')[-1])):
            toreturn['result'] = False
            toreturn['message'] = "Item already has that tag"
        else:
            dataset.TagItem(request.POST.get("rid"), request.POST.getlist("tags[]"))
            dataset.SaveDataset(request.user)
            toreturn["result"] = True
    except Exception as e:
        toreturn['result'] = False
        toreturn['message'] = str(e)
    return JsonResponse(toreturn);
예제 #11
0
def viewdata(request):
    parameter = request.GET.get('dataset', '')
    if (parameter != ""):
        id = parameter.split('-', 1)[1]
        dataset = JSONDataSet.GetDataset(id)
    else:
        return render(request,'index.html')

    context = {
        'data': dataset.GetResponseMatrix(False),
        'questions': dataset.GetQuestions(False),
        'tags': dataset.GetTags(),
        'id': id,
    }
    return render(request, 'viewdata.html', context=context)
예제 #12
0
def addtag(request):
    toreturn = dict()
    try:
        dataset = JSONDataSet.GetDataset(request.POST.get("id"))

        if (dataset.HasTag(request.POST.get("tag"))):
            toreturn['results'] = False
            toreturn['message'] = "Tag already exists"
        else:
            if (request.POST.get('tag') == ""):
                toreturn['results'] = False
                toreturn['message'] = "Tag cannot be empty"
            else:
                dataset.AddTag(request.POST.get('tag'))
                dataset.SaveDataset(request.user)
                toreturn['results']=True

    except Exception as e:
        toreturn['results']=False
        toreturn['message']=str(e)
    return JsonResponse(toreturn)