def collections( request ): """ We are displaying collection status vis-a-vis the project Gitolite server. It takes too long to run git-status on every repo so, if repo statuses are not cached they will be updated by jQuery after page load has finished. """ collections = [] collection_status_urls = [] for object_id in gitolite.get_repos_orgs(): identifier = Identifier(object_id) # TODO Identifier: Organization object instead of repo and org repo,org = identifier.parts.values() collection_paths = Collection.collection_paths(settings.MEDIA_BASE, repo, org) colls = [] for collection_path in collection_paths: if collection_path: identifier = Identifier(path=collection_path) collection = Collection.from_identifier(identifier) colls.append(collection) gitstatus = collection.gitstatus() if gitstatus and gitstatus.get('sync_status'): collection.sync_status = gitstatus['sync_status'] else: collection_status_urls.append( "'%s'" % collection.sync_status_url()) collections.append( (object_id,repo,org,colls) ) # load statuses in random order random.shuffle(collection_status_urls) return render_to_response( 'webui/collections/index.html', {'collections': collections, 'collection_status_urls': ', '.join(collection_status_urls),}, context_instance=RequestContext(request, processors=[]) )
def new_manual( request, oid ): """Ask for Entity ID, then create new 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']) oidentifier = Identifier(oid).object() idparts = oidentifier.idparts collection_ids = sorted([ os.path.basename(cpath) for cpath in Collection.collection_paths( settings.MEDIA_BASE, idparts['repo'], idparts['org'] ) ]) collection_ids.reverse() if request.method == 'POST': form = NewCollectionForm(request.POST) if form.is_valid(): # TODO get this from Entity class or something idparts['model'] = 'collection' idparts['cid'] = str(form.cleaned_data['cid']) cidentifier = Identifier(parts=idparts) if not cidentifier: messages.error(request, "Could not generate a legal ID from your input. Try again.") elif cidentifier.parent_id(stubs=True) != oidentifier.id: messages.error(request, "Can only create collections for this organization. Try again.") elif cidentifier.id in collection_ids: messages.error(request, "Object ID %s already exists. Try again." % cidentifier.id) else: # Create collection and redirect to edit page collection = _create_collection(request, cidentifier, git_name, git_mail) if collection: messages.warning(request, 'IMPORTANT: Register this ID with the ID service as soon as possible!') return HttpResponseRedirect(reverse('webui-collection-edit', args=[collection.id])) else: data = { 'repo': idparts['repo'], 'org': idparts['org'], } form = NewCollectionForm(data) return render(request, 'webui/collections/new-manual.html', { 'form': form, 'collection_ids': collection_ids, })
def newexpert( request, repo, org ): """Ask for Entity ID, then create new 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']) if request.method == 'POST': form = NewCollectionForm(request.POST) if form.is_valid(): idparts = { 'model':'collection', 'repo':repo, 'org':org, 'cid':str(form.cleaned_data['cid']) } identifier = Identifier(parts=idparts) collection_id = identifier.id collection_ids = [ os.path.basename(cpath) for cpath in Collection.collection_paths(settings.MEDIA_BASE, repo, org) ] already_exists = False if collection_id in collection_ids: already_exists = True messages.error(request, "That collection ID already exists. Try again.") if collection_id and not already_exists: collection_new_expert( request, settings.MEDIA_BASE, collection_id, git_name, git_mail ) return HttpResponseRedirect(reverse('webui-collections')) else: data = { 'repo':repo, 'org':org, } form = NewCollectionForm(data) return render_to_response( 'webui/collections/new.html', {'form': form, }, context_instance=RequestContext(request, processors=[]) )