Ejemplo n.º 1
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=[])
    )
Ejemplo n.º 2
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'])
    file_ = DDRFile.from_request(request)
    module = file_.identifier.fields_module()
    entity = file_.parent()
    collection = file_.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())
    file_.model_def_commits()
    file_.model_def_fields()
    #
    if request.method == 'POST':
        form = DDRForm(request.POST, fields=module.FIELDS)
        if form.is_valid():
            
            file_.form_post(form)
            file_.write_json()
            
            # commit files, delete cache, update search index, update git status
            entity_file_edit(request, collection, file_, git_name, git_mail)
            
            return HttpResponseRedirect( file_.absolute_url() )
            
    else:
        form = DDRForm(file_.form_prep(), fields=module.FIELDS)
    return render_to_response(
        'webui/files/edit-json.html',
        {'collection': collection,
         'entity': entity,
         'role': role,
         'file': file_,
         'form': form,
         },
        context_instance=RequestContext(request, processors=[])
    )
Ejemplo n.º 3
0
def edit( request, repo, org, cid ):
    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))
    if collection.locked():
        messages.error(request, WEBUI_MESSAGES['VIEWS_COLL_LOCKED'].format(collection.id))
        return HttpResponseRedirect( reverse('webui-collection', args=[repo,org,cid]) )
    collection.repo_fetch()
    if collection.repo_behind():
        messages.error(request, WEBUI_MESSAGES['VIEWS_COLL_BEHIND'].format(collection.id))
        return HttpResponseRedirect( reverse('webui-collection', args=[repo,org,cid]) )
    if request.method == 'POST':
        form = DDRForm(request.POST, fields=COLLECTION_FIELDS)
        if form.is_valid():
            
            collection.form_post(form)
            collection.dump_json()
            collection.dump_ead()
            updated_files = [collection.json_path, collection.ead_path,]
            
            # if inheritable fields selected, propagate changes to child objects
            inheritables = collection.selected_inheritables(form.cleaned_data)
            modified_ids,modified_files = collection.update_inheritables(inheritables, form.cleaned_data)
            if modified_files:
                updated_files = updated_files + modified_files
            
            # commit files, delete cache, update search index, update git status
            collection_edit(request, collection, updated_files, git_name, git_mail)
            
            return HttpResponseRedirect(collection.url())
        
    else:
        form = DDRForm(collection.form_prep(), fields=COLLECTION_FIELDS)
    return render_to_response(
        'webui/collections/edit-json.html',
        {'repo': repo,
         'org': org,
         'cid': cid,
         'collection': collection,
         'form': form,
         },
        context_instance=RequestContext(request, processors=[])
    )
Ejemplo n.º 4
0
def edit( request, cid ):
    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_identifier(Identifier(cid))
    module = collection.identifier.fields_module()
    collection.model_def_commits()
    collection.model_def_fields()
    if collection.locked():
        messages.error(request, WEBUI_MESSAGES['VIEWS_COLL_LOCKED'].format(collection.id))
        return HttpResponseRedirect(collection.absolute_url())
    collection.repo_fetch()
    if collection.repo_behind():
        messages.error(request, WEBUI_MESSAGES['VIEWS_COLL_BEHIND'].format(collection.id))
        return HttpResponseRedirect(collection.absolute_url())
    if request.method == 'POST':
        form = DDRForm(request.POST, fields=module.FIELDS)
        if form.is_valid():
            
            collection.form_post(form.cleaned_data)
            # write these so we see a change on refresh
            # will be rewritten in collection.save()
            collection.write_json()
            
            # commit files, delete cache, update search index, update git status
            collection_tasks.edit(
                request,
                collection, form.cleaned_data,
                git_name, git_mail
            )
            
            return HttpResponseRedirect(collection.absolute_url())
        
    else:
        form = DDRForm(collection.form_prep(), fields=module.FIELDS)
    return render(request, 'webui/collections/edit-json.html', {
        'collection': collection,
        'form': form,
    })
Ejemplo n.º 5
0
def edit( request, fid ):
    enforce_git_credentials(request)
    file_ = DDRFile.from_identifier(Identifier(fid))
    check_file(file_)
    entity = file_.parent()
    collection = file_.collection()
    check_parents(entity, collection)
    file_.model_def_commits()
    file_.model_def_fields()
    module = file_.identifier.fields_module()
    #
    if request.method == 'POST':
        form = DDRForm(request.POST, fields=module.FIELDS)
        if form.is_valid():
            
            file_.form_post(form.cleaned_data)
            # write these so we see a change on refresh
            # will be rewritten in file_.save()
            file_.write_json()
            
            # commit files, delete cache, update search index, update git status
            file_tasks.edit(
                request,
                collection, file_, form.cleaned_data,
                request.session['git_name'], request.session['git_mail'],
            )
            
            return HttpResponseRedirect( file_.absolute_url() )
            
    else:
        form = DDRForm(file_.form_prep(), fields=module.FIELDS)
    return render(request, 'webui/files/edit-json.html', {
        'collection': collection,
        'entity': entity,
        'role': file_.identifier.parts['role'],
        'file': file_,
        'form': form,
    })
Ejemplo n.º 6
0
def edit( request, repo, org, cid, eid ):
    """
    UI for Entity topics uses TagManager to represent topics as tags,
    and typeahead.js so users only have to type part of a topic.
    """
    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)
    module = entity.identifier.fields_module()
    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())
    #
    # load topics choices data
    # TODO This should be baked into models somehow.
    topics_terms = tagmanager_terms('topics')
    facility_terms = tagmanager_terms('facility')
    entity.model_def_commits()
    entity.model_def_fields()
    if request.method == 'POST':
        form = DDRForm(request.POST, fields=module.FIELDS)
        if form.is_valid():
            
            # clean up after TagManager
            hidden_topics = request.POST.get('hidden-topics', None)
            if hidden_topics:
                form.cleaned_data['topics'] = tagmanager_process_tags(hidden_topics)
            hidden_facility = request.POST.get('hidden-facility', None)
            if hidden_facility:
                form.cleaned_data['facility'] = tagmanager_process_tags(hidden_facility)
            
            # run module_functions on raw form data
            entity.form_post(form)
            inheritables = entity.selected_inheritables(form.cleaned_data)
            
            # write basic changes to disk (this is quick)
            entity.write_json()
            entity.write_mets()
            updated_files = [entity.json_path, entity.mets_path,]
            
            # do the rest in the background:
            # update inheriable fields, commit files, delete cache,
            # update search index, update git status
            collection_entity_edit(
                request,
                collection, entity, updated_files, form.cleaned_data,
                git_name, git_mail, settings.AGENT
            )
            
            return HttpResponseRedirect(entity.absolute_url())
    else:
        form = DDRForm(entity.form_prep(), fields=module.FIELDS)
    
    topics_prefilled = tagmanager_prefilled_terms(entity.topics, topics_terms)
    facility_prefilled = tagmanager_prefilled_terms(entity.facility, facility_terms)
    # selected terms that don't appear in field_terms
    topics_legacy = tagmanager_legacy_terms(entity.topics, topics_terms)
    facility_legacy = tagmanager_legacy_terms(entity.facility, facility_terms)
    return render_to_response(
        'webui/entities/edit-json.html',
        {'collection': collection,
         'entity': entity,
         'form': form,
         # data for TagManager
         'topics_terms': topics_terms,
         'facility_terms': facility_terms,
         'topics_prefilled': topics_prefilled,
         'facility_prefilled': facility_prefilled,
         },
        context_instance=RequestContext(request, processors=[])
    )
Ejemplo n.º 7
0
def edit( request, eid ):
    """
    UI for Entity topics uses TagManager to represent topics as tags,
    and typeahead.js so users only have to type part of a topic.
    """
    git_name,git_mail = enforce_git_credentials(request)
    entity = Entity.from_identifier(Identifier(eid))
    check_object(entity, request)
    module = entity.identifier.fields_module()
    collection = entity.collection()
    check_parent(collection)
    
    # load topics choices data
    # TODO This should be baked into models somehow.
    topics_terms = tagmanager_terms('topics')
    facility_terms = tagmanager_terms('facility')
    entity.model_def_commits()
    entity.model_def_fields()
    if request.method == 'POST':
        form = DDRForm(request.POST, fields=module.FIELDS)
        if form.is_valid():
            
            # clean up after TagManager
            hidden_topics = request.POST.get('hidden-topics', None)
            hidden_facility = request.POST.get('hidden-facility', None)
            if hidden_topics:
                form.cleaned_data['topics'] = tagmanager_process_tags(hidden_topics)
            if hidden_facility:
                form.cleaned_data['facility'] = tagmanager_process_tags(hidden_facility)

            entity.form_post(form.cleaned_data)
            # write these so we see a change on refresh
            # will be rewritten in entity.save()
            entity.write_json()
            
            # do the rest in the background:
            # update inheriable fields, commit files, delete cache,
            # update search index, update git status
            entity_tasks.edit(
                request,
                collection, entity, form.cleaned_data,
                git_name, git_mail, settings.AGENT
            )
            
            return HttpResponseRedirect(entity.absolute_url())
    else:
        form = DDRForm(entity.form_prep(), fields=module.FIELDS)

    # coerce term:id dicts into old-style "term [id]" strings
    entity_topics = [
        converters.dict_to_textbracketid(item, ['term','id'])
        for item in entity.topics
    ]
    entity_facility = [
        converters.dict_to_textbracketid(item, ['term','id'])
        for item in entity.facility
    ]

    topics_prefilled = tagmanager_prefilled_terms(entity_topics, topics_terms)
    facility_prefilled = tagmanager_prefilled_terms(entity_facility, facility_terms)
    # selected terms that don't appear in field_terms
    topics_legacy = tagmanager_legacy_terms(entity_topics, topics_terms)
    facility_legacy = tagmanager_legacy_terms(entity_facility, facility_terms)
    return render(request, 'webui/entities/edit-json.html', {
        'collection': collection,
        'entity': entity,
        'form': form,
        # data for TagManager
        'topics_terms': topics_terms,
        'facility_terms': facility_terms,
        'topics_prefilled': topics_prefilled,
        'facility_prefilled': facility_prefilled,
    })