Beispiel #1
0
def liss(request):
    # Handle file upload
	    
    MEDIA_FILE = os.path.join(BASE_DIR, 'media/%s.enc' % os.urandom(10).encode('hex'))
   
    if request.method == 'POST':
        form = DocumentForm(request.POST, request.FILES)
        if form.is_valid():
            newdoc = Document(docfile=request.FILES['docfile'])
            encrypt_file(request.FILES['docfile'], MEDIA_FILE, '8W;>i^H0qi|J&$coR5MFpR*Vn')
            decrypt_file( MEDIA_FILE,  os.path.join(BASE_DIR, 'media/file.jpg' ), b'my private key')
            newdoc.save()

            # Redirect to the document list after POST
            return HttpResponseRedirect(reverse('liss'))
    else:
        form = DocumentForm()  # A empty, unbound form

    # Load documents for the list page
    documents = Document.objects.all()

    # Render list page with the documents and the form
    """ 
   return render_to_response(
        'list.html',
        {'documents': documents, 'form': form },
        context_instance=RequestContext(request)
    )
    """
    return render(request, 
        'myapp/list.html', 
        {'documents': documents, 'form': form }
    )
Beispiel #2
0
def list(request):
    # Handle file upload
    if request.method == "POST":
        form = DocumentForm(request.POST, request.FILES)
        if form.is_valid():
            abc = "abcd"
            newdoc = Document(docfile=request.FILES["docfile"], userid=request.POST["userid"])
            if not existPhoto(newdoc.docfile.name, newdoc.userid):
                newdoc.save()  # This need to be looked into
            newNode(newdoc.userid, newdoc.docfile.name)

            # Redirect to the document list after POST
            return JsonResponse({"abcd": abc})  # HttpResponseRedirect(reverse('list'))
    # Handle file retrieval
    if request.method == "GET":
        url = "http://192.168.0.108:8000/media/"
        image_array = []
        final_object = {}
        newdoc = Doc(user=request.GET["userid"])
        photos = retrieveImage(newdoc.user)
        for photo in photos:
            """image_data['name']=url+photo.name
            image_array.append(image_data)
            print image_data
            print image_array"""
            image_data = url + photo.name
            record = {"name": image_data}
            # print record
            image_array.append(record)
        final_object["photos"] = image_array
        return JsonResponse(final_object)

    else:
        form = DocumentForm()  # A empty, unbound form
def list(request):
    # Handle file upload
    if request.method == 'POST':
        form = DocumentForm(request.POST, request.FILES)
        files = request.FILES.getlist('docfile')
        user = request.user.username
        if form.is_valid():
            for f in files:
                filename = f.name
                try:
                    doc = Document.objects.get(filename=filename)
                    doc.filename = filename
                    doc.uploadedby = user
                    doc.lastuploadtime = timezone.now().strftime(
                        "%Y-%m-%d %H:%M:%S")
                    doc.docfile = f
                except Document.DoesNotExist:
                    doc = Document(docfile=f,
                                   filename=filename,
                                   uploadedby=user,
                                   lastuploadtime=timezone.now().strftime(
                                       "%Y-%m-%d %H:%M:%S"))
                doc.save()

            # Redirect to the document list after POST
            return HttpResponseRedirect(reverse('list'))
    else:
        form = DocumentForm()  # A empty, unbound form

    # Load documents for the list page
    documents = Document.objects.all()

    # Render list page with the documents and the form
    return render(request, 'list.html', {'documents': documents, 'form': form})
def list(request):
    # Handle file upload
    if request.method == 'POST':
        form = DocumentForm(request.POST, request.FILES)
        if form.is_valid():
            newdoc = Document(docfile = request.FILES['docfile'])
            newdoc.save()

            # Redirect to the document list after POST
            return HttpResponseRedirect(reverse('list'))
    else:
        form = DocumentForm() # A empty, unbound form

    # Load documents for the list page
    documents = Document.objects.last()

    if(request.GET.get('mybtn')):
        pass
        
    # Render list page with the documents and the form
    return render_to_response(
        'myapp/list.html',
        {'documents': documents, 'form': form},
        context_instance=RequestContext(request)
    )
def list(request):
    # Handle file upload
    if request.method == 'POST':
        form = DocumentForm(request.POST, request.FILES)
        if form.is_valid():
            newdoc = Document(docfile=request.FILES['docfile'])
            newdoc.save()

            # Redirect to the document list after POST
            return HttpResponseRedirect(reverse('list'))
    else:
        form = DocumentForm()  # A empty, unbound form

    # Load documents for the list page
    documents = Document.objects.last()

    if (request.GET.get('mybtn')):
        pass

    # Render list page with the documents and the form
    return render_to_response('myapp/list.html', {
        'documents': documents,
        'form': form
    },
                              context_instance=RequestContext(request))
Beispiel #6
0
def list(request):
    # Handle file upload
    if request.method == 'POST':
        if request.POST.get("form1") != "":
            form = DocumentForm(request.POST, request.FILES)
            if form.is_valid():
                newdoc = Document(docfile=request.FILES['docfile'])
                newdoc.save()

                # Redirect to the document list after POST
                return HttpResponseRedirect(reverse('list'))

        elif request.POST.get("form2") != "":
            mail = request.POST.get("mail")
            dropdown = request.POST.get("ident")
            #plik = {{ document.docfile.url }}
            # run(lokalizacja pliku, lokalizacja modelu, nazwa modelu)
            #send (mail,link)
            #return HttpResponseRedirect("/myapp/"+dropdown)

    else:
        form = DocumentForm()  # A empty, unbound form

    # Load documents for the list page
    documents = Document.objects.all()

    # Render list page with the documents and the form
    return render(request, 'list.html', {'documents': documents, 'form': form})
Beispiel #7
0
def list(request):
    # Handle file upload
    if request.method == 'POST':
        form = DocumentForm(request.POST, request.FILES)
        if form.is_valid():
            filename = request.FILES['docfile']
            if zipfile_is_valid(filename):
                fields = extract_xml(filename)
                newdoc = Document(docfile = filename, **fields)
                newdoc.save()

            # Redirect to the document list after POST
            return HttpResponseRedirect(reverse('myapp.views.list'))
    else:
        form = DocumentForm() # A empty, unbound form

    # Load documents for the list page
    documents = Document.objects.all()

    # Render list page with the documents and the form
    return render_to_response(
        'list.html',
        {'documents': documents, 'form': form},
        context_instance=RequestContext(request)
    )
Beispiel #8
0
def sample(request):
    """
    View for rendering the sample tuples of the uploaded file.
    This view does the following:
        1. Read the upload type.
        2. Save the uploaded file locally.
        3. Set session parameters to reference the file subsequently.
        4. Read and return a sample of tuples.
    Arguments:
        request: The request object.
    Returns an HttpResponse object.
    """
    upload_type = ""
    cdrive_file_path = request.POST.get('cdriveFile')
    if cdrive_file_path is not None:
        upload_type = "CDrive"
    elif 'docfile' in request.FILES:
        upload_type = "Local"
    if upload_type == "CDrive":
        token = request.session[CLIENT_TOKEN_KEY]
        get_url = CDRIVE_URL + "content/?path=" + str(cdrive_file_path)
        header = {"Authorization": "Bearer " + token}
        read_response = requests.get(url=get_url, headers=header)
        tuples = read_response.json().split("\n")
        uploaded_df = pd.DataFrame(tuples)
        uploaded_df.columns = ['foo']
        uploaded_df['id'] = range(0, len(uploaded_df))
        column_order = ['id', 'foo']
        if not os.path.exists(CDRIVE_FILES_DIR):
            os.makedirs(CDRIVE_FILES_DIR)
        index = cdrive_file_path.rfind("/")
        cdrive_file = cdrive_file_path[index + 1:]
        parent_path = cdrive_file_path[0:index]
        uploaded_df[column_order].to_csv(os.path.join(CDRIVE_FILES_DIR,
                                                      cdrive_file),
                                         index=False)
        sample_tuples = tuples[1:10]
        request.session['uploaded_file'] = cdrive_file
        request.session['cdrive_path'] = parent_path
        request.session['file_type'] = "CDrive"
    elif upload_type == "Local":
        uploaded_doc = Document(docfile=request.FILES['docfile'])
        uploaded_doc.save()
        uploaded_doc_path = os.path.join(PROJECT_DIR,
                                         uploaded_doc.docfile.url[1:])
        uploaded_df = pd.read_csv(uploaded_doc_path, names=['foo'])
        uploaded_df['id'] = range(0, len(uploaded_df))
        column_order = ['id', 'foo']
        whitespace_striper = lambda x: str(x).strip()
        uploaded_df['foo'] = uploaded_df['foo'].apply(whitespace_striper)
        uploaded_df[column_order].to_csv(uploaded_doc_path, index=False)
        request.session['uploaded_file'] = uploaded_doc.docfile.url
        request.session['uploaded_file_name'] = uploaded_doc.docfile.name
        request.session['file_type'] = "Local"
        sample_tuples = uploaded_df['foo'].head(10).tolist()
    return render(request, 'sample.html', {'sample_tuples': sample_tuples})
Beispiel #9
0
def show(request):
    # Handle file upload   
    myfile = "/home/zyy/Documents/kdd-master/myweb/doc-django-master/media/documents/test_data.txt"
    form = DocumentForm() # A empty, unbound form
    
    if request.method == 'POST':
        form = DocumentForm(request.POST, request.FILES)
        if form.is_valid():
            newdoc = Document(docfile = request.FILES['docfile'])
            newdoc.save()
          #  if os.path.isfile(myfile):
            #plot(request)
        return HttpResponseRedirect(reverse('show'))
    
    data = process_document(myfile)
    text = " | ".join([", ".join(row) for row in data])
    return render(request, 'show.html', {'text': text, 'form': form, 'graphic': ""})
Beispiel #10
0
def list(request):
    # Handle file upload
    if request.method == 'POST':
        form = DocumentForm(request.POST, request.FILES)
        if form.is_valid():
            newdoc = Document(docfile=request.FILES['docfile'])
            newdoc.save()

            # Redirect to the document list after POST
            return HttpResponseRedirect(reverse('list'))
    else:
        form = DocumentForm()  # A empty, unbound form

    # Load documents for the list page
    documents = Document.objects.all()

    # Render list page with the documents and the form
    return render(request, 'list.html', {'documents': documents, 'form': form})
Beispiel #11
0
def liss(request):
    # Handle file upload

    # MEDIA_FILE = os.path.join(BASE_DIR, 'media/documents/%s.jpg' % os.urandom(10).encode('hex'))

    if request.method == 'POST':
        form = DocumentForm(request.POST, request.FILES)
        if form.is_valid():
            # handle_uploaded_file(request.FILES['docfile'], MEDIA_FILE)
            current_user = request.user
            newdoc = Document(docfile=request.FILES['docfile'],
                              uploader=current_user.id)
            newdoc.save()
            # os.remove(MEDIA_FILE)
            # a.save()
            # encrypt_file(request.FILES['docfile'], MEDIA_FILE, '8W;>i^H0qi|J&$coR5MFpR*Vn')
            # uploaderObj =
            # with open(MEDIA_FILE, 'rw') as f:
            #     mile = File(f)
            #     current_user = request.user
            #     newdoc = Document(docfile=mile, uploader=current_user.id)
            #     newdoc.save()
            #     f.close()

            # Redirect to the document list after POST
            return HttpResponseRedirect(reverse('liss'))
    else:
        form = DocumentForm()  # A empty, unbound form

    # Load documents for the list page
    documents = Document.objects.all()

    # Render list page with the documents and the form
    """
   return render_to_response(
        'list.html',
        {'documents': documents, 'form': form },
        context_instance=RequestContext(request)
    )
    """
    return render(request, 'myapp/list.html', {
        'documents': documents,
        'form': form
    })
def list(request):
    # Handle file upload
    if request.method == 'POST':
        form = DocumentForm(request.POST, request.FILES)
        if form.is_valid():
            newdoc = Document(docfile = request.FILES['docfile'])
            newdoc.save()

            # Redirect to the document list after POST
            return HttpResponseRedirect(reverse('list'))
    else:
        form = DocumentForm() # A empty, unbound form

    # Load documents for the list page
    documents = Document.objects.all()


    # Render list page with the documents and the form
    return render(request, 'list.html', {'documents': documents, 'form': form})
Beispiel #13
0
def show(request):
    # Handle file upload
    if request.method == 'POST':
        form = DocumentForm(request.POST, request.FILES)
        if form.is_valid():
            newdoc = Document(docfile=request.FILES['docfile'])
            newdoc.save()

            return HttpResponseRedirect(reverse('show'))
    else:
        form = DocumentForm()  # A empty, unbound form

    data = process_document(Document.objects.last())
    text = " | ".join([", ".join(row) for row in data])

    plot(request)

    return render(request, 'show.html', {
        'text': text,
        'form': form,
        'graphic': ""
    })
Beispiel #14
0
def list(request):
    # Handle file upload
    if request.method == 'POST':
        form = DocumentForm(request.POST, request.FILES)
        if form.is_valid():
            newdoc = Document(docfile = request.FILES['docfile'])
            newdoc.save()
            
	    filename = 'media/' + newdoc.docfile.name
	    extension = filename.rsplit('.')[-1]
#############is vaild?#####################
	    if(imghdr.what(filename)=='rgb' or imghdr.what(filename)=='gif' or imghdr.what(filename)=='pbm' or imghdr.what(filename)=='pgm' or imghdr.what(filename)=='ppm' or imghdr.what(filename)=='tiff' or imghdr.what(filename)=='rast' or imghdr.what(filename)=='xbm' or imghdr.what(filename)=='jpeg' or imghdr.what(filename)=='bmp' or imghdr.what(filename)=='png' or imghdr.what(filename)=='jpg'):

	        #exception handle. jpg is a part of jpeg format
	        if (imghdr.what(filename)=='jpeg' and extension=='jpg'):
		    extSyntax = 1
	        elif imghdr.what(filename) == extension:
		    extSyntax = 1
	        else:
		    extSyntax = 2
	    else:
		extSyntax = 0


##############################test#########
      	    exVar = newdoc.docfile.name
            exx = check_output(['myapp/embed.py','media/'+exVar])
	    tmp_str = exx.rsplit('\n')[3]
	    if(imghdr.what(filename) == 'gif' or imghdr.what(filename) == 'jpeg' or imghdr.what(filename) == 'jpeg' or imghdr.what(filename) == 'png'):
	        if(tmp_str == 'no files found'):
		    embSyntax = 1
	        else:
		    embSyntax = 2
		    tmp_str = exx.rsplit('\n')[4] + exx.rsplit('\n')[5]
	    else:
		embSyntax = 0
###########################################
	  


            # Json to the document list after POST
	    data = {
		    'original' : request.FILES['docfile'].name,
		    'filename' : newdoc.docfile.name.rsplit('/')[2],
		    'extension_result' : extSyntax,
		    'embedded_result' : embSyntax,
		    'embedded_message' : tmp_str,
		    'current' : extension,
		    'expected' : imghdr.what(filename)
		   }
	    return JsonResponse(data)

    else:
        form = DocumentForm() # A empty, unbound form

    # Load documents for the list page
    documents = Document.objects.all()

    # Render list page with the documents and the form
    return render_to_response(
        'list.html',
        {'documents': documents, 'form': form},
        context_instance=RequestContext(request)
    )
Beispiel #15
0
def createPicsule(request):
    docfile = request.FILES['docfile']
    newDoc = Document(docfile=docfile)
    newDoc.save()
    newDoc = Document.objects.get(id=newDoc.id)
    ret = {}
    try:
        imageObj = Image.open('myproject' + newDoc.docfile.url)
        info = imageObj._getexif()
        if info is not None:
            for tag, value in info.items():
                decoded = TAGS.get(tag, tag)
                if decoded == "GPSInfo":
                    gps_data = {}
                    for t in value:
                        sub_decoded = GPSTAGS.get(t, t)
                        gps_data[sub_decoded] = value[t]
                    lat,long = get_lat_lon(gps_data)
                    ret["Latitude"] = lat;
                    ret["Longitude"] = long;
                else:
                    ret[decoded] = value
    except:
        print "error occured while tryin to grab image exif"

    #get top songs
    date = ret.get("DateTime")
    chart = None
    if date is not None:
        dateObj = datetime.datetime.strptime(date, '%Y:%m:%d %H:%M:%S')
        weekday = dateObj.weekday() #billboard only supports links on a saturday
        if weekday <= 1 or weekday == 6:
            while dateObj.weekday() != 5:
                dateObj = dateObj + datetime.timedelta(days=-1)
        else:
            while dateObj.weekday() != 5:
                dateObj = dateObj + datetime.timedelta(days=1)
        formattedDate = dateObj.strftime("%Y-%m-%d")
        chart = billboard.ChartData('hot-100', formattedDate)
        ret["Top100"] = [str(e) for e in chart.entries[:10]]


        nonTouchedDate = datetime.datetime.strptime(date, '%Y:%m:%d %H:%M:%S')
        actualFormattedDate = nonTouchedDate.strftime("%Y-%m-%d")

        #get weather
        latitude = ret.get("Latitude")
        longitude = ret.get("Longitude")
        if latitude is not None and longitude is not None:
           locObj = urlopen(Request("http://www.geoplugin.net/extras/postalcode.gp?lat=" + str(latitude) +
                                    "&long=" + str(longitude) + "&format=json")).read()
           jsonObj = json.loads(locObj)
           if type(jsonObj) is dict:
              #  print jsonObj
                postalCode = jsonObj.get("geoplugin_postCode")
                countryCode = jsonObj.get("geoplugin_countryCode")
              #  print postalCode
            #    print countryCode
                #print formattedDate
                try:
                    weatherObj = urlopen(Request("https://api.weathersource.com/v1/4d6060d10090464668ef/postal_codes/" +
                                             postalCode + "," + countryCode + "/forecast.json?period=day&" +
                                            "timestamp=" + actualFormattedDate + "&fields=tempAvg,precip,snowfall," +
                                            "windSpdAvg,cldCvrAvg,dewPtAvg,feelsLikeAvg,relHumAvg,sfcPresAvg"))\
                    .read()

                    jsonWeatherObj = json.loads(weatherObj)
                    if len(jsonWeatherObj) > 0:
                        ret["Weather"] = jsonWeatherObj[0]
                except:
                    pass

        #get s&p500 data
        try:
            sandpData = urlopen(Request("https://www.quandl.com/api/v3/datasets/YAHOO/INDEX_GSPC.json?start_date=" +
                                        actualFormattedDate + "&end_date=" +
                                        (nonTouchedDate + datetime.timedelta(days=3)).strftime("%Y-%m-%d"))).read()
            sandpJson = json.loads(sandpData)["dataset"]
            if 'data' in sandpJson and len(sandpJson["data"]) > 0:
                ret["sandp500Open"] = sandpJson["data"][0][1] #1 is open
                ret["sandp500Close"] = sandpJson["data"][0][4] #4 is close
        except:
            print 'too many requests. no data pulled'

    newDoc.model = ret.get("Model")
    newDoc.make = ret.get("Make")
    newDoc.orientation = ret.get("Orientation")
    newDoc.date = datetime.datetime.strptime(ret.get("DateTime"), '%Y:%m:%d %H:%M:%S') if ret.get("DateTime") is not \
                                                                                          None else datetime.datetime.today()
    newDoc.width = ret.get("ExifImageWidth")
    newDoc.height = ret.get("ExifImageHeight")
    newDoc.longitude = ret.get("Longitude")
    newDoc.latitude = ret.get("Latitude")
    newDoc.top100 = json.dumps(ret.get("Top100"))
    newDoc.weather = json.dumps(ret.get("Weather"))
    newDoc.sandp500Open = ret.get("sandp500Open")
    newDoc.sandp500Close = ret.get("sandp500Close")
    newDoc.save(update_fields=["model", "make", "orientation", "date", "width", "height", "longitude", "latitude",
                               "top100", "weather", "sandp500Open", "sandp500Close"])
    return newDoc.id
Beispiel #16
0
def index(request):
    # Handle file upload

    if request.method == 'POST':
        form = DocumentForm(request.POST, request.FILES)
        if form.is_valid():
            newdoc = Document(docfile=request.FILES['docfile'])
            newdoc.save()

            #Process and create a new file
            try:
                id = Document.objects.all()[0].id
                filepath = Document.objects.get(id=id).docfile.file.name
                filename = basename(Document.objects.get(id=id).docfile.name)
                Airtel_AV_Dashboard("Test").process(filepath, filename)

                name = ""
                for l in filename:
                    if l == ".":
                        break
                    else:
                        name += l

                with open(f"myapp/Final Output/{name} modified.xlsx",
                          "rb") as stored_file:
                    #Store the new file in the database
                    new_doc = New_Document(docfile=File(
                        stored_file, name=f"{name} modified.xlsx"))
                    new_doc.save()

                #for each_file in Document.objects.all():
                #each_file.delete()

            except Exception as e:
                print(f"Exception {e}")
                #for each_file in Document.objects.all():
                #each_file.delete()

            # Redirect to the document list after POST
            return HttpResponseRedirect(reverse('index'))
    else:

        form = DocumentForm()  # A empty, unbound form
        #if len(New_Document.objects.all()) > 0:
        #previous_document = New_Document.objects.all()[0]
        #previous_document.delete()

    # Load documents for the list page
    query_set = New_Document.objects.all()
    documents = []
    cnt = len(query_set) - 1
    for i in query_set:
        documents.append(query_set[cnt])
        cnt -= 1
    documents = documents

    # Render file_processing_indexpython manage.py runserver
    #  page with the documents and the form
    return render(request, 'file_processing_index.html', {
        'documents': documents,
        'name': "Download File",
        'form': form
    })
Beispiel #17
0
def encc(request):
    if request.method == 'POST' and (request.POST.get('encrypt') == "Encrypt"):
        # form = DocumentForm(request.POST, request.FILES)
        # if form.is_valid():

        FILENAME0 = request.POST.get('filename')
        # FILENAME1 =FILENAME0[:-12]
        # FILENAME1 =FILENAME1[-20:]
        # user = request.user.username
        # user = user.encode('utf-8')
        testmsg1 = request.POST.get('publickey')

        FILENAME0 = FILENAME0[17:]
        #ENCRYPTFILENAME1 = FILENAME0[:-4]
        ENCRYPTFILENAME1 = FILENAME0

        # FILE0 = os.path.join(BASE_DIR, 'media/documents/%s' % TEMPFILENAME1)
        FILE0 = os.path.join(BASE_DIR, 'media/documents/%s' % FILENAME0)

        # FILENAME = os.path.join(BASE_DIR, 'media/documents/%s.enc' % os.urandom(10).encode('hex'))
        FILENAME = os.path.join(
            BASE_DIR, 'media/documentstemp/%s.enc' % ENCRYPTFILENAME1)
        #FILENAME = os.path.join(BASE_DIR, 'media/documents/%s.enc' % FILENAME1)
        #newdoc = Document(docfile=request.FILES['docfile'])
        #encrypt_file(open(FILE0,'rw'), FILENAME, '%s' % testmsg1) #getPublicKey(request))
        encrypt_file(FILE0, FILENAME, '%s' % testmsg1)
        with open(FILENAME, 'rw') as f:
            mile = File(f)
            current_user = request.user
            newdoc = Document(docfile=mile, uploader=current_user.id)
            newdoc.save()
        #documents = Document.objects.all()
        os.remove(FILENAME)
        os.remove(FILE0)
        # os.remove(FILENAME)

        d = Document.objects.get(docfile='documents/' + FILENAME0)
        #d=get_object_or_404(Document, docfile='documents/'+FILENAME0)
        d.delete()
        return HttpResponseRedirect(reverse('liss'))

    elif request.method == 'POST' and (request.POST.get('decrypt')
                                       == "Decrypt"):
        # FILENAME0 =request.POST.get('filename')[:-12]
        FILENAME0 = request.POST.get('filename')
        FILENAME0 = FILENAME0[17:]
        DECRYPTEDFILENAME = FILENAME0[:-4]
        user = request.user.username
        user = user.encode('utf-8')
        FILENAME = os.path.join(BASE_DIR, 'media/documents/%s' % FILENAME0)
        DECRYPTEDFILENAME = os.path.join(
            BASE_DIR, 'media/documentstemp/%s' % DECRYPTEDFILENAME)
        try:
            decrypt_file(FILENAME, DECRYPTEDFILENAME, b'%s' % user)
        except (AssertionError, IntegrityError):
            raise Http404("invalid private key")
        with open(DECRYPTEDFILENAME, 'rw') as f:
            mile = File(f)
            current_user = request.user
            newdoc = Document(docfile=mile, uploader=current_user.id)
            newdoc.save()
            # documents = Document.objects.all()
            os.remove(FILENAME)
            os.remove(DECRYPTEDFILENAME)
            d = Document.objects.get(docfile='documents/' + FILENAME0)
            #d=get_object_or_404(Document,docfile='documents/'+FILENAME0)
            d.delete()
        return HttpResponseRedirect(reverse('liss'))
    elif request.method == 'POST' and (request.POST.get('delete') == "Delete"):
        FILENAME0 = request.POST.get('filename')
        FILENAME0 = FILENAME0[17:]
        FILENAME = os.path.join(BASE_DIR, 'media/documents/%s' % FILENAME0)
        d = Document.objects.get(docfile='documents/' + FILENAME0)
        d.delete()
        os.remove(FILENAME)
        return HttpResponseRedirect(reverse('liss'))
    else:
        return render(request, 'myapp/list.html')