예제 #1
0
def delete_file( git_name, git_mail, collection_path, entity_id, file_basename, agent='' ):
    """
    @param collection_path: string
    @param entity_id: string
    @param file_basename: string
    @param git_name: Username of git committer.
    @param git_mail: Email of git committer.
    @param agent: (optional) Name of software making the change.
    """
    logger.debug('delete_file(%s,%s,%s,%s,%s,%s)' % (git_name, git_mail, collection_path, entity_id, file_basename, agent))
    gitstatus.lock(settings.MEDIA_BASE, 'delete_file')
    # TODO rm_files list should come from the File model
    file_id = os.path.splitext(file_basename)[0]
    repo,org,cid,eid,role,sha1 = file_id.split('-')
    entity = Entity.from_json(Entity.entity_path(None,repo,org,cid,eid))
    file_ = entity.file(repo, org, cid, eid, role, sha1)
    rm_files = file_.files_rel(collection_path)
    logger.debug('rm_files: %s' % rm_files)
    # remove file from entity.json
    # TODO move this to commands.file_destroy or models.Entity
    for f in entity.files:
        if f.basename == file_basename:
            entity.files.remove(f)
    entity.dump_json()
    updated_files = ['entity.json']
    logger.debug('updated_files: %s' % updated_files)
    status,message = file_destroy(git_name, git_mail, collection_path, entity_id, rm_files, updated_files, agent)
    return status,message,collection_path,file_basename
예제 #2
0
def new_access( request, repo, org, cid, eid, role, sha1 ):
    """Generate a new access file for the specified file.
    
    NOTE: There is no GET for this view.  GET requests will redirect to entity.
    """
    git_name = request.session.get('git_name')
    git_mail = request.session.get('git_mail')
    if not git_name and git_mail:
        messages.error(request, WEBUI_MESSAGES['LOGIN_REQUIRED'])
    collection = Collection.from_json(Collection.collection_path(request,repo,org,cid))
    entity = Entity.from_json(Entity.entity_path(request,repo,org,cid,eid))
    if collection.locked():
        messages.error(request, WEBUI_MESSAGES['VIEWS_COLL_LOCKED'].format(collection.id))
        return HttpResponseRedirect( reverse('webui-entity', args=[repo,org,cid,eid]) )
    collection.repo_fetch()
    if collection.repo_behind():
        messages.error(request, WEBUI_MESSAGES['VIEWS_COLL_BEHIND'].format(collection.id))
        return HttpResponseRedirect( reverse('webui-entity', args=[repo,org,cid,eid]) )
    if entity.locked():
        messages.error(request, WEBUI_MESSAGES['VIEWS_ENT_LOCKED'])
        return HttpResponseRedirect( reverse('webui-entity', args=[repo,org,cid,eid]) )
    file_ = entity.file(repo, org, cid, eid, role, sha1)
    #
    if request.method == 'POST':
        form = NewAccessFileForm(request.POST)
        if form.is_valid():
            src_path = form.cleaned_data['path']
            # start tasks
            result = entity_add_access.apply_async(
                (git_name, git_mail, entity, file_),
                countdown=2)
            result_dict = result.__dict__
            entity.files_log(1,'START task_id %s' % result.task_id)
            entity.files_log(1,'ddrlocal.webui.file.new_access')
            entity.files_log(1,'Locking %s' % entity.id)
            # lock entity
            lockstatus = entity.lock(result.task_id)
            if lockstatus == 'ok':
                entity.files_log(1, 'locked')
            else:
                entity.files_log(0, lockstatus)
            # add celery task_id to session
            celery_tasks = request.session.get(settings.CELERY_TASKS_SESSION_KEY, {})
            # IMPORTANT: 'action' *must* match a message in webui.tasks.TASK_STATUS_MESSAGES.
            task = {'task_id': result.task_id,
                    'action': 'webui-file-new-access',
                    'filename': os.path.basename(src_path),
                    'file_url': file_.url(),
                    'entity_id': entity.id,
                    'start': datetime.now().strftime(settings.TIMESTAMP_FORMAT),}
            celery_tasks[result.task_id] = task
            #del request.session[settings.CELERY_TASKS_SESSION_KEY]
            request.session[settings.CELERY_TASKS_SESSION_KEY] = celery_tasks
            # feedback
            messages.success(request, WEBUI_MESSAGES['VIEWS_FILES_NEWACCESS'] % os.path.basename(src_path))
    # redirect to entity
    return HttpResponseRedirect( reverse('webui-entity', args=[repo,org,cid,eid]) )
예제 #3
0
def file_json( request, repo, org, cid, eid, role, sha1 ):
    entity = Entity.from_json(Entity.entity_path(request,repo,org,cid,eid))
    file_ = entity.file(repo, org, cid, eid, role, sha1)
    if file_.json_path and os.path.exists(file_.json_path):
        with open(file_.json_path, 'r') as f:
            json = f.read()
        return HttpResponse(json, mimetype="application/json")
    messages.success(request, 'no JSON file. sorry.')
    return HttpResponseRedirect( reverse('webui-file', args=[repo,org,cid,eid,role,sha1]) )
예제 #4
0
def edit( request, repo, org, cid, eid, role, sha1 ):
    git_name = request.session.get('git_name')
    git_mail = request.session.get('git_mail')
    if not git_name and git_mail:
        messages.error(request, WEBUI_MESSAGES['LOGIN_REQUIRED'])
    collection = Collection.from_json(Collection.collection_path(request,repo,org,cid))
    entity = Entity.from_json(Entity.entity_path(request,repo,org,cid,eid))
    if collection.locked():
        messages.error(request, WEBUI_MESSAGES['VIEWS_COLL_LOCKED'].format(collection.id))
        return HttpResponseRedirect( reverse('webui-entity', args=[repo,org,cid,eid]) )
    collection.repo_fetch()
    if collection.repo_behind():
        messages.error(request, WEBUI_MESSAGES['VIEWS_COLL_BEHIND'].format(collection.id))
        return HttpResponseRedirect( reverse('webui-entity', args=[repo,org,cid,eid]) )
    if entity.locked():
        messages.error(request, WEBUI_MESSAGES['VIEWS_ENT_LOCKED'])
        return HttpResponseRedirect( reverse('webui-entity', args=[repo,org,cid,eid]) )
    file_ = entity.file(repo, org, cid, eid, role, sha1)
    #
    if request.method == 'POST':
        form = DDRForm(request.POST, fields=FILE_FIELDS)
        if form.is_valid():
            
            file_.form_post(form)
            file_.dump_json()
            
            # commit files, delete cache, update search index, update git status
            entity_file_edit(request, collection, file_, git_name, git_mail)
            
            return HttpResponseRedirect( file_.url() )
            
    else:
        form = DDRForm(file_.form_prep(), fields=FILE_FIELDS)
    return render_to_response(
        'webui/files/edit-json.html',
        {'repo': file_.repo,
         'org': file_.org,
         'cid': file_.cid,
         'eid': file_.eid,
         'role': file_.role,
         'sha1': file_.sha1,
         'collection': collection,
         'entity': entity,
         'file': file_,
         'form': form,
         },
        context_instance=RequestContext(request, processors=[])
    )
예제 #5
0
def delete_file( git_name, git_mail, collection_path, entity_id, file_basename, agent='' ):
    """
    @param collection_path: string
    @param entity_id: string
    @param file_basename: string
    @param git_name: Username of git committer.
    @param git_mail: Email of git committer.
    @param agent: (optional) Name of software making the change.
    """
    logger.debug('delete_file(%s,%s,%s,%s,%s,%s)' % (git_name, git_mail, collection_path, entity_id, file_basename, agent))
    gitstatus.lock(settings.MEDIA_BASE, 'delete_file')
    file_id = os.path.splitext(file_basename)[0]
    file_ = DDRFile.from_identifier(Identifier(file_id))
    entity = Entity.from_identifier(Identifier(entity_id))
    collection = Collection.from_identifier(Identifier(path=collection_path))
    logger.debug('delete from repository')
    rm_files,updated_files = entity.prep_rm_file(file_)
    status,message = commands.file_destroy(
        git_name, git_mail,
        collection, entity,
        rm_files, updated_files,
        agent
    )
    logger.debug('delete from search index')
    try:
        docstore.delete(settings.DOCSTORE_HOSTS, settings.DOCSTORE_INDEX, file_.id)
    except ConnectionError:
        logger.error('Could not delete document from Elasticsearch.')
    return status,message,collection_path,file_basename
예제 #6
0
파일: entity.py 프로젝트: densho/ddr-local
def entity_edit(collection_path, entity_id, form_data, git_name, git_mail, agent=''):
    """The time-consuming parts of entity-edit.
    
    @param collection_path: str Absolute path to collection
    @param entity_id: str
    @param form_data: dict
    @param git_name: Username of git committer.
    @param git_mail: Email of git committer.
    @param agent: (optional) Name of software making the change.
    """
    logger.debug('tasks.entity.entity_edit(%s,%s,%s,%s,%s)' % (
        git_name, git_mail, collection_path, entity_id, agent))
    collection = Collection.from_identifier(Identifier(path=collection_path))
    entity = Entity.from_identifier(Identifier(id=entity_id))
    gitstatus.lock(settings.MEDIA_BASE, 'entity_edit')
    
    exit,status,updated_files = entity.save(
        git_name, git_mail,
        collection,
        form_data
    )
    
    dvcs_tasks.gitstatus_update.apply_async(
        (collection.path,),
        countdown=2
    )
    return status,collection_path,entity_id
예제 #7
0
def changelog( request, eid ):
    entity = Entity.from_identifier(Identifier(eid))
    check_object(entity, request, check_locks=False)
    collection = entity.collection()
    return render(request, 'webui/entities/changelog.html', {
        'collection': collection,
        'entity': entity,
    })
예제 #8
0
def browse( request, repo, org, cid, eid, role='master' ):
    """Browse for a file in vbox shared folder.
    """
    collection = Collection.from_json(Collection.collection_path(request,repo,org,cid))
    entity = Entity.from_json(Entity.entity_path(request,repo,org,cid,eid))
    path = request.GET.get('path')
    home = None
    parent = None
    if path:
        path_abs = os.path.join(settings.VIRTUALBOX_SHARED_FOLDER, path)
        parent = os.path.dirname(path)
        home = settings.VIRTUALBOX_SHARED_FOLDER
    else:
        path_abs = settings.VIRTUALBOX_SHARED_FOLDER
    listdir = []
    if os.path.exists(path_abs):
        for x in os.listdir(path_abs):
            xabs = os.path.join(path_abs, x)
            rel = xabs.replace(settings.VIRTUALBOX_SHARED_FOLDER, '')
            if rel and rel[0] == '/':
                rel = rel[1:]
            isdir = os.path.isdir(xabs)
            if isdir:
                x = '%s/' % x
            mtime = datetime.fromtimestamp(os.path.getmtime(xabs))
            size = None
            if not isdir:
                size = os.path.getsize(xabs)
            attribs = {'basename':x, 'rel':rel, 'path':xabs, 'isdir':isdir, 'size':size, 'mtime':mtime}
            if os.path.exists(xabs):
                listdir.append(attribs)
    return render_to_response(
        'webui/files/browse.html',
        {'repo': repo,
         'org': org,
         'cid': cid,
         'eid': eid,
         'collection_uid': collection.id,
         'collection': collection,
         'entity': entity,
         'role': role,
         'listdir': listdir,
         'parent': parent,
         'home': home,},
        context_instance=RequestContext(request, processors=[])
    )
예제 #9
0
def changelog( request, repo, org, cid, eid ):
    entity = Entity.from_request(request)
    collection = entity.collection()
    return render_to_response(
        'webui/entities/changelog.html',
        {'collection': collection,
         'entity': entity,},
        context_instance=RequestContext(request, processors=[])
    )
예제 #10
0
파일: entity.py 프로젝트: densho/ddr-local
 def after_return(self, status, retval, task_id, args, kwargs, einfo):
     logger.debug('EntityReloadTask.after_return(%s, %s, %s, %s, %s)' % (status, retval, task_id, args, kwargs))
     collection_path = args[0]
     collection = Collection.from_identifier(Identifier(path=collection_path))
     entity_id = args[1]
     entity = Entity.from_identifier(Identifier(id=entity_id))
     lockstatus = entity.unlock(task_id)
     gitstatus.update(settings.MEDIA_BASE, collection_path)
     gitstatus.unlock(settings.MEDIA_BASE, 'reload_files')
예제 #11
0
def file_edit(collection_path, file_id, git_name, git_mail):
    """The time-consuming parts of file-edit.
    
    @param collection_path: str Absolute path to collection
    @param file_id: str
    @param git_name: Username of git committer.
    @param git_mail: Email of git committer.
    """
    logger.debug('file_edit(%s,%s,%s,%s)' % (git_name, git_mail, collection_path, file_id))
    
    model,repo,org,cid,eid,role,sha1 = models.split_object_id(file_id)
    entity = Entity.from_json(Entity.entity_path(None,repo,org,cid,eid))
    file_ = entity.file(repo, org, cid, eid, role, sha1)
    
    gitstatus.lock(settings.MEDIA_BASE, 'file_edit')
    exit,status = file_.save(git_name, git_mail)
    gitstatus_update.apply_async((collection_path,), countdown=2)
    
    return status,collection_path,file_id
예제 #12
0
def files_dedupe( request, repo, org, cid, eid ):
    git_name = request.session.get('git_name')
    git_mail = request.session.get('git_mail')
    if not (git_name and git_mail):
        messages.error(request, WEBUI_MESSAGES['LOGIN_REQUIRED'])
    entity = Entity.from_request(request)
    collection = entity.collection()
    if collection.locked():
        messages.error(request, WEBUI_MESSAGES['VIEWS_COLL_LOCKED'].format(collection.id))
        return HttpResponseRedirect(collection.absolute_url())
    duplicate_masters = entity.detect_file_duplicates('master')
    duplicate_mezzanines = entity.detect_file_duplicates('mezzanine')
    duplicates = duplicate_masters + duplicate_mezzanines
    if request.method == 'POST':
        form = RmDuplicatesForm(request.POST)
        if form.is_valid() and form.cleaned_data.get('confirmed',None) \
                and (form.cleaned_data['confirmed'] == True):
            # remove duplicates
            entity.rm_file_duplicates()
            # update metadata files
            entity.write_json()
            entity.write_mets()
            updated_files = [entity.json_path, entity.mets_path,]
            success_msg = WEBUI_MESSAGES['VIEWS_ENT_UPDATED']
            exit,status = commands.entity_update(
                git_name, git_mail,
                collection, entity,
                updated_files,
                agent=settings.AGENT
            )
            collection.cache_delete()
            if exit:
                messages.error(request, WEBUI_MESSAGES['ERROR'].format(status))
            else:
                # update search index
                try:
                    entity.post_json(settings.DOCSTORE_HOSTS, settings.DOCSTORE_INDEX)
                except ConnectionError:
                    logger.error('Could not post to Elasticsearch.')
                gitstatus_update.apply_async((collection.path,), countdown=2)
                # positive feedback
                messages.success(request, success_msg)
                return HttpResponseRedirect(entity.absolute_url())
    else:
        data = {}
        form = RmDuplicatesForm()
    return render_to_response(
        'webui/entities/files-dedupe.html',
        {'collection': collection,
         'entity': entity,
         'duplicates': duplicates,
         'form': form,},
        context_instance=RequestContext(request, processors=[])
    )
예제 #13
0
파일: densho.py 프로젝트: densho/ddr-local
def test_entities(headers, rows):
    """Test-loads Entities mentioned in rows; crashes if any are missing.
    
    @param headers: List of field names
    @param rows: List of rows (each with list of fields, not dict)
    @returns list of invalid entities
    """
    bad_entities = []
    for row in rows:
        rowd = make_row_dict(headers, row)
        entity_id = rowd.pop("entity_id")
        repo, org, cid, eid = entity_id.split("-")
        entity_path = Entity.entity_path(None, repo, org, cid, eid)
        try:
            entity = Entity.from_json(entity_path)
        except:
            entity = None
        if not entity:
            bad_entities.append(entity_id)
    return bad_entities
예제 #14
0
파일: files.py 프로젝트: densho/ddr-local
def batch( request, rid ):
    """Add multiple files to entity.
    """
    file_role = Stub.from_identifier(Identifier(rid))
    entity = Entity.from_request(request)
    collection = entity.collection()
    check_parents(entity, collection)
    return render(request, 'webui/files/new.html', {
        'collection': collection,
        'entity': entity,
    })
예제 #15
0
def files_dedupe( request, eid ):
    git_name,git_mail = enforce_git_credentials(request)
    entity = Entity.from_identifier(Identifier(eid))
    check_object(entity, request)
    collection = entity.collection()
    check_parent(collection)
    
    duplicate_masters = entity.detect_file_duplicates('master')
    duplicate_mezzanines = entity.detect_file_duplicates('mezzanine')
    duplicates = duplicate_masters + duplicate_mezzanines
    
    if request.method == 'POST':
        form = RmDuplicatesForm(request.POST)
        if form.is_valid() and form.cleaned_data.get('confirmed',None) \
                and (form.cleaned_data['confirmed'] == True):
            # remove duplicates
            entity.rm_file_duplicates()
            # update metadata files
            entity.write_json()
            entity.write_mets()
            updated_files = [entity.json_path, entity.mets_path,]
            success_msg = WEBUI_MESSAGES['VIEWS_ENT_UPDATED']
            exit,status = commands.entity_update(
                git_name, git_mail,
                collection, entity,
                updated_files,
                agent=settings.AGENT
            )
            collection.cache_delete()
            if exit:
                messages.error(request, WEBUI_MESSAGES['ERROR'].format(status))
            else:
                # update search index
                try:
                    entity.post_json()
                except ConnectionError:
                    logger.error('Could not post to Elasticsearch.')
                dvcs_tasks.gitstatus_update.apply_async(
                    (collection.path,),
                    countdown=2
                )
                # positive feedback
                messages.success(request, success_msg)
                return HttpResponseRedirect(entity.absolute_url())
    else:
        data = {}
        form = RmDuplicatesForm()
    return render(request, 'webui/entities/files-dedupe.html', {
        'collection': collection,
        'entity': entity,
        'duplicates': duplicates,
        'form': form,
    })
예제 #16
0
def batch( request, repo, org, cid, eid, role='master' ):
    """Add multiple files to entity.
    """
    collection = Collection.from_json(Collection.collection_path(request,repo,org,cid))
    entity = Entity.from_json(Entity.entity_path(request,repo,org,cid,eid))
    if collection.locked():
        messages.error(request, WEBUI_MESSAGES['VIEWS_COLL_LOCKED'].format(collection.id))
        return HttpResponseRedirect( reverse('webui-entity', args=[repo,org,cid,eid]) )
    collection.repo_fetch()
    if collection.repo_behind():
        messages.error(request, WEBUI_MESSAGES['VIEWS_COLL_BEHIND'].format(collection.id))
        return HttpResponseRedirect( reverse('webui-entity', args=[repo,org,cid,eid]) )
    if entity.locked():
        messages.error(request, WEBUI_MESSAGES['VIEWS_ENT_LOCKED'])
        return HttpResponseRedirect( reverse('webui-entity', args=[repo,org,cid,eid]) )
    return render_to_response(
        'webui/files/new.html',
        {'collection': collection,
         'entity': entity,},
        context_instance=RequestContext(request, processors=[])
    )
예제 #17
0
def unlock( request, eid, task_id ):
    """Provides a way to remove entity lockfile through the web UI.
    """
    git_name,git_mail = enforce_git_credentials(request)
    entity = Entity.from_identifier(Identifier(eid))
    check_object(entity, request)
    collection = entity.collection()
    
    if task_id and entity.locked() and (task_id == entity.locked()):
        entity.unlock(task_id)
        messages.success(request, 'Object <b>%s</b> unlocked.' % entity.id)
    return HttpResponseRedirect(entity.absolute_url())
예제 #18
0
def detail( request, repo, org, cid, eid, role, sha1 ):
    """Add file to entity.
    """
    collection = Collection.from_json(Collection.collection_path(request,repo,org,cid))
    entity = Entity.from_json(Entity.entity_path(request,repo,org,cid,eid))
    file_ = entity.file(repo, org, cid, eid, role, sha1)
    formdata = {'path':file_.path_rel}
    return render_to_response(
        'webui/files/detail.html',
        {'repo': file_.repo,
         'org': file_.org,
         'cid': file_.cid,
         'eid': file_.eid,
         'role': file_.role,
         'sha1': file_.sha1,
         'collection_uid': collection.id,
         'collection': collection,
         'entity': entity,
         'file': file_,
         'new_access_form': NewAccessFileForm(formdata),},
        context_instance=RequestContext(request, processors=[])
    )
예제 #19
0
def entity_edit(collection_path, entity_id, updated_files, git_name, git_mail, agent=''):
    """The time-consuming parts of entity-edit.
    
    @param collection_path: str Absolute path to collection
    @param entity_id: str
    @param git_name: Username of git committer.
    @param git_mail: Email of git committer.
    @param agent: (optional) Name of software making the change.
    """
    logger.debug('collection_entity_edit(%s,%s,%s,%s,%s)' % (
        git_name, git_mail, collection_path, entity_id, agent))
    
    collection = Collection.from_json(collection_path)
    repo,org,cid,eid = entity_id.split('-')
    entity_path = Entity.entity_path(None,repo,org,cid,eid)
    entity = Entity.from_json(entity_path)
    
    gitstatus.lock(settings.MEDIA_BASE, 'entity_edit')
    exit,status = entity.save_part2(updated_files, collection, git_name, git_mail)
    gitstatus_update.apply_async((collection.path,), countdown=2)

    return status,collection_path,entity_id
예제 #20
0
def unlock( request, repo, org, cid, eid, task_id ):
    """Provides a way to remove entity lockfile through the web UI.
    """
    git_name = request.session.get('git_name')
    git_mail = request.session.get('git_mail')
    if not git_name and git_mail:
        messages.error(request, WEBUI_MESSAGES['LOGIN_REQUIRED'])
    entity = Entity.from_request(request)
    collection = entity.collection()
    if task_id and entity.locked() and (task_id == entity.locked()):
        entity.unlock(task_id)
        messages.success(request, 'Object <b>%s</b> unlocked.' % entity.id)
    return HttpResponseRedirect(entity.absolute_url())
예제 #21
0
def edit_json( request, repo, org, cid, eid ):
    """
    NOTE: will permit editing even if entity is locked!
    (which you need to do sometimes).
    """
    entity = Entity.from_request(request)
    collection = entity.collection()
    #if collection.locked():
    #    messages.error(request, WEBUI_MESSAGES['VIEWS_COLL_LOCKED'].format(collection.id))
    #    return HttpResponseRedirect(entity.absolute_url())
    #collection.repo_fetch()
    #if collection.repo_behind():
    #    messages.error(request, WEBUI_MESSAGES['VIEWS_COLL_BEHIND'].format(collection.id))
    #    return HttpResponseRedirect(entity.absolute_url())
    #if entity.locked():
    #    messages.error(request, WEBUI_MESSAGES['VIEWS_ENT_LOCKED'])
    #    return HttpResponseRedirect(entity.absolute_url())
    #
    if request.method == 'POST':
        form = JSONForm(request.POST)
        if form.is_valid():
            git_name = request.session.get('git_name')
            git_mail = request.session.get('git_mail')
            if git_name and git_mail:
                json_text = form.cleaned_data['json']
                fileio.write_text(json_text, entity.json_path)
                
                exit,status = commands.entity_update(
                    git_name, git_mail,
                    collection, entity,
                    [entity.json_path],
                    agent=settings.AGENT
                )
                
                collection.cache_delete()
                if exit:
                    messages.error(request, WEBUI_MESSAGES['ERROR'].format(status))
                else:
                    gitstatus_update.apply_async((collection.path,), countdown=2)
                    messages.success(request, WEBUI_MESSAGES['VIEWS_ENT_UPDATED'])
                    return HttpResponseRedirect(entity.absolute_url())
            else:
                messages.error(request, WEBUI_MESSAGES['LOGIN_REQUIRED'])
    else:
        form = JSONForm({'json': entity.dump_json(),})
    return render_to_response(
        'webui/entities/edit-raw.html',
        {'entity': entity,
         'form': form,},
        context_instance=RequestContext(request, processors=[])
    )
예제 #22
0
def delete( request, repo, org, cid, eid, role, sha1 ):
    try:
        entity = Entity.from_json(Entity.entity_path(request,repo,org,cid,eid))
        file_ = entity.file(repo, org, cid, eid, role, sha1)
    except:
        raise Http404
    collection = Collection.from_json(file_.collection_path)
    if entity.locked():
        messages.error(request, WEBUI_MESSAGES['VIEWS_ENT_LOCKED'])
        return HttpResponseRedirect( reverse('webui-entity', args=[repo,org,cid,eid]) )
    if collection.locked():
        messages.error(request, WEBUI_MESSAGES['VIEWS_COLL_LOCKED'].format(collection.id))
        return HttpResponseRedirect( reverse('webui-entity', args=[repo,org,cid,eid]) )
    git_name = request.session.get('git_name')
    git_mail = request.session.get('git_mail')
    if not git_name and git_mail:
        messages.error(request, WEBUI_MESSAGES['LOGIN_REQUIRED'])
    #
    if request.method == 'POST':
        form = DeleteFileForm(request.POST)
        if form.is_valid() and form.cleaned_data['confirmed']:
            entity_delete_file(request, git_name, git_mail, collection, entity, file_, settings.AGENT)
            return HttpResponseRedirect( reverse('webui-collection', args=[repo,org,cid]) )
    else:
        form = DeleteFileForm()
    return render_to_response(
        'webui/files/delete.html',
        {'repo': file_.repo,
         'org': file_.org,
         'cid': file_.cid,
         'eid': file_.eid,
         'role': file_.role,
         'sha1': file_.sha1,
         'file': file_,
         'form': form,
         },
        context_instance=RequestContext(request, processors=[])
    )
예제 #23
0
def _create_entity(request, eidentifier, collection, git_name, git_mail):
    """used by both new_idservice and new_manual
    """
    # load Entity object, inherit values from parent, write back to file
    exit,status = Entity.new(eidentifier, git_name, git_mail, agent=settings.AGENT)
    entity = Entity.from_identifier(eidentifier)
    
    collection.cache_delete()
    if exit:
        logger.error(exit)
        logger.error(status)
        messages.error(request, WEBUI_MESSAGES['ERROR'].format(status))
    else:
        # update search index
        try:
            entity.post_json()
        except ConnectionError:
            logger.error('Could not post to Elasticsearch.')
        dvcs_tasks.gitstatus_update.apply_async(
            (collection.path,),
            countdown=2
        )
    return entity
예제 #24
0
def detail( request, repo, org, cid, eid ):
    entity = Entity.from_request(request)
    collection = entity.collection()
    entity.model_def_commits()
    entity.model_def_fields()
    tasks = request.session.get('celery-tasks', [])
    return render_to_response(
        'webui/entities/detail.html',
        {'collection': collection,
         'entity': entity,
         'children_urls': entity.children_urls(),
         'tasks': tasks,
         'entity_unlock_url': entity.unlock_url(entity.locked()),},
        context_instance=RequestContext(request, processors=[])
    )
예제 #25
0
def detail( request, eid ):
    entity = Entity.from_identifier(Identifier(eid))
    check_object(entity, request, check_locks=False)
    collection = entity.collection()
    entity.model_def_commits()
    entity.model_def_fields()
    tasks = request.session.get('celery-tasks', [])
    return render(request, 'webui/entities/detail.html', {
        'collection': collection,
        'entity': entity,
        'children_urls': entity.children_urls(),
        'tasks': tasks,
        'entity_unlock_url': entity.unlock_url(entity.locked()),
        # cache this for later
        'annex_info': annex_info(repository(collection.path_abs)),
    })
예제 #26
0
def entity_newexpert(collection_path, entity_id, git_name, git_mail):
    """Create new entity using known entity ID.
    
    @param collection_path: str Absolute path to collection
    @param entity_id: str
    @param git_name: Username of git committer.
    @param git_mail: Email of git committer.
    """
    logger.debug('collection_entity_newexpert(%s,%s,%s,%s)' % (
        collection_path, entity_id, git_name, git_mail))
    
    collection = Collection.from_identifier(Identifier(path=collection_path))
    
    gitstatus.lock(settings.MEDIA_BASE, 'entity_newexpert')
    entity = Entity.create(collection, entity_id, git_name, git_mail)
    gitstatus_update.apply_async((collection.path,), countdown=2)

    return 'status',collection_path,entity.id
예제 #27
0
파일: entity.py 프로젝트: densho/ddr-local
def reload_files(collection_path, entity_id, git_name, git_mail, agent=''):
    """Regenerate entity.json's list of child files.
    
    @param collection_path: string
    @param entity_id: string
    @param git_name: Username of git committer.
    @param git_mail: Email of git committer.
    @param agent: (optional) Name of software making the change.
    """
    logger.debug('tasks.entity.reload_files(%s,%s,%s,%s,%s)' % (collection_path, entity_id, git_name, git_mail, agent))
    gitstatus.lock(settings.MEDIA_BASE, 'reload_files')
    entity = Entity.from_identifier(Identifier(entity_id))
    collection = Collection.from_identifier(Identifier(path=collection_path))
    
    exit,status,updated_files = entity.save(
        git_name, git_mail,
        collection,
        {}
    )

    return status,collection_path,entity_id
예제 #28
0
def delete( request, eid, confirm=False ):
    """Delete the requested entity from the collection.
    """
    git_name,git_mail = enforce_git_credentials(request)
    entity = Entity.from_identifier(Identifier(eid))
    check_object(entity, request)
    collection = entity.collection()
    check_parent(collection)
    
    if request.method == 'POST':
        form = DeleteEntityForm(request.POST)
        if form.is_valid() and form.cleaned_data['confirmed']:
            entity_tasks.delete(
                collection, entity, git_name, git_mail, settings.AGENT
            )
            return HttpResponseRedirect(collection.absolute_url())
    else:
        form = DeleteEntityForm()
    return render(request, 'webui/entities/delete.html', {
        'entity': entity,
        'form': form,
    })
예제 #29
0
def files_reload( request, eid ):
    """Regenerates list of file info dicts with list of File objects
    """
    git_name,git_mail = enforce_git_credentials(request)
    entity = Entity.from_identifier(Identifier(eid))
    check_object(entity, request)
    collection = entity.collection()
    check_parent(collection)
    
    entity_tasks.reload_files(
        request,
        collection, entity,
        git_name, git_mail, settings.AGENT
    )
    
    messages.success(
        request,
        'Regenerating files list for <a href="%s">%s</a>.' % (
            entity.absolute_url(), entity.id
        )
    )
    return HttpResponseRedirect(entity.absolute_url())
예제 #30
0
def children(request, eid):
    entity = Entity.from_identifier(Identifier(eid))
    check_object(entity, request, check_locks=False)
    collection = entity.collection()
    
    # models that are under entity but are not nodes (i.e. files)
    
    # paginate
    thispage = request.GET.get('page', 1)
    paginator = Paginator(
        [c for c in entity.children() if c.identifier.model != 'file'],
        settings.RESULTS_PER_PAGE
    )
    page = paginator.page(thispage)
    return render(request, 'webui/entities/children.html', {
        'collection': collection,
        'entity': entity,
        'children_models': [m for m in CHILDREN['entity'] if m not in NODES],
        'children_urls': entity.children_urls(active='children'),
        'paginator': paginator,
        'page': page,
        'thispage': thispage,
    })