Example #1
0
def update_collections(request):
    # need a time option here
    """ActiveCollection = 'TestTexts_000'
    filehandle = open('not_really_a_file.txt','w')
    CIVET_utilities.write_YAML_file(ActiveCollection, filehandle)
    filehandle.close()
    return HttpResponse("So far so good")"""
    tempdirname = 'update'
    CollectionList = ['TestTexts_000','TestTexts_001']
    filenames = []
    thedir = ''
    print('UC-1:',CollectionList)
    if not os.path.exists(tempdirname):
        os.mkdir(tempdirname)
    for collst in CollectionList:
        thecoll = Collection.objects.get(collid__exact=collst)
        fdir, filename = os.path.split(thecoll.collfilename)
        filename = tempdirname + '/' + filename + '.yml'
        if len(thedir) == 0:
            thedir = fdir
        filehandle = open(filename,'w')
        CIVET_utilities.write_YAML_file(thecoll, filehandle)
        filehandle.close()
        filenames.append(filename)
        
# code below shamelessly copied from:
#http://stackoverflow.com/questions/67454/serving-dynamically-generated-zip-archives-in-django    

    # Folder name in ZIP archive which contains the above files
    zip_subdir = thedir
    zip_filename = "%s.zip" % zip_subdir

    # Open StringIO to grab in-memory ZIP contents
    s = StringIO.StringIO()

    # The zip compressor
    zf = zipfile.ZipFile(s, "w")

    for fpath in filenames:
        # Calculate path for file in zip
        fdir, fname = os.path.split(fpath)
        zip_path = os.path.join(zip_subdir, fname)

        # Add file, at correct path
        zf.write(fpath, zip_path)

    # Must close zip for all contents to be written
    zf.close()
    
    shutil.rmtree(tempdirname, ignore_errors=True)

    # Grab ZIP file from in-memory, make response with correct MIME-type
    resp = HttpResponse(s.getvalue(), content_type = "application/x-zip-compressed")
    # ..and correct content-disposition
    resp['Content-Disposition'] = 'attachment; filename=%s' % zip_filename

    return resp
Example #2
0
def read_collection_directory(request, dirname):
    """ Loads a set of collections from dirname; replaces anything already in Collection, Text  """
    global CollectionForm, CollectionList
    
    Collection.objects.all().delete()
    Text.objects.all().delete()
    Case.objects.all().delete()     # <15.07.09: Warn first on this?
    CollectionForm = ''    
    ka = 0
#    CIVET_utilities.hello()
    filelist = os.listdir(dirname)
    for file in filelist:
        ka += 1
        if file.endswith('.yml'):
            if ka <= 4:            # DEBUG
#                print('RCD-1:',file)
                collinfo, textlist = CIVET_utilities.get_YAML_file(dirname + '/' + file)
                collentry = Collection.objects.create_coll(
                    collid = collinfo['collid'],
                    collfilename = collinfo['collfilename'],
                    colldate = collinfo['colldate'],
                    colledit = collinfo['colledit'],
                    collcmt = collinfo['collcmt']
                    )
                collentry.save()
 
                for dc in textlist:
                    textentry = Text.objects.create_text(
                        textparent = dc['textparent'],
                        textid = dc['textid'],
                        textdate = dc['textdate'],
                        textpublisher = dc['textpublisher'],
                        textpubid = dc['textpubid'],
                        textlicense = dc['textlicense'],
                        textlede = dc['textlede'],
                        textcmt = dc['textcmt'],
                        textoriginal = dc['textoriginal'],
                        textmkup = dc['textmkup'],
                        textmkupdate = dc['textmkupdate'],
                        textmkupcoder = dc['textmkupcoder']
                        )
                    textentry.save()
                
                    # NEED TO ADD READING CASES HERE!
                
        elif file.startswith('form'):
            CollectionForm = dirname + '/' + file
#            print('RCD-2:',CollectionForm)
        
        # otherwise ignore file, so other things can be in there
        # error check on empty CollectionForm 

    CollectionList = []  # list of available collections   
    for tup in Collection.objects.values_list('collid'):
        CollectionList.append(tup[0])
Example #3
0
def apply_markup(request):
    """ calls CIVET_utilities.do_markup() for each text block in the collection. """
    textblock = get_blocks(request.POST['editor1'])
    newstr = ''
    for st in textblock:
        newstr += make_markup_string([st,textblock[st][0],CIVET_utilities.do_markup(textblock[st][1])])
    context = {}
    context['current_collection'] = 'marked document'
    
    context['thetext'] = newstr
#    context['thetext'] = 'This is <span style="class:date;color:red">some</span> text with a <span class="date">date</span> and a <span style="class:nament;color:blue">Named Entity</span>'
    return render(request,'djciv_data/civet_ckeditor.html',context)