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=[]) )
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, })
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=[]) )
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())
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=[]) )
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=[]) )
def batch( request, repo, org, cid, eid, role='master' ): """Add multiple files to entity. """ 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()) return render_to_response( 'webui/files/new.html', {'collection': collection, 'entity': entity,}, context_instance=RequestContext(request, processors=[]) )
def delete( request, repo, org, cid, eid, confirm=False ): """Delete the requested entity from the collection. """ try: entity = Entity.from_request(request) except: raise Http404 collection = entity.collection() if collection.locked(): messages.error(request, WEBUI_MESSAGES['VIEWS_COLL_LOCKED'].format(collection.id)) return HttpResponseRedirect(entity.absolute_url()) if entity.locked(): messages.error(request, WEBUI_MESSAGES['VIEWS_ENT_LOCKED']) return HttpResponseRedirect(entity.absolute_url()) 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 = DeleteEntityForm(request.POST) if form.is_valid() and form.cleaned_data['confirmed']: collection_delete_entity(request, git_name, git_mail, collection, entity, settings.AGENT) return HttpResponseRedirect(collection.absolute_url()) else: form = DeleteEntityForm() return render_to_response( 'webui/entities/delete.html', {'entity': entity, 'form': form, }, context_instance=RequestContext(request, processors=[]) )
def children( request, repo, org, cid, eid, role ): entity = Entity.from_request(request) collection = entity.collection() duplicates = entity.detect_file_duplicates(role) if duplicates: url = reverse('webui-entity-files-dedupe', args=entity.idparts) messages.error(request, 'Duplicate files detected. <a href="%s">More info</a>' % url) files = entity.children(role) # paginate thispage = request.GET.get('page', 1) paginator = Paginator(files, settings.RESULTS_PER_PAGE) page = paginator.page(thispage) return render_to_response( 'webui/entities/files.html', {'collection': collection, 'entity': entity, 'children_urls': entity.children_urls(active=role), 'browse_url': entity.file_browse_url(role), 'batch_url': entity.file_browse_url(role), 'paginator': paginator, 'page': page, 'thispage': thispage,}, context_instance=RequestContext(request, processors=[]) )
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=[]) )
def mets_xml( request, repo, org, cid, eid ): entity = Entity.from_request(request) collection = entity.collection() soup = BeautifulSoup(entity.mets().xml, 'xml') return HttpResponse(soup.prettify(), content_type="application/xml")
def entity_json( request, repo, org, cid, eid ): entity = Entity.from_request(request) collection = entity.collection() return HttpResponse(entity.dump_json(), content_type="application/json")