def collection(request, uuid): c = get_object_or_404(models.Collection, pk=uuid) rescan = request.GET.get("rescan") if rescan is not None: jobs.load_and_import_collection(c.id) return HttpResponseRedirect( reverse('dashboard.views.collection', args=[uuid])) forcescan = request.GET.get("forcescan") if forcescan is not None: jobs.force_load_and_import_collection(c.id) return HttpResponseRedirect( reverse('dashboard.views.collection', args=[uuid])) order = request.GET.get("order") releases = models.MusicbrainzRelease.objects.filter(collection=c) if order == "date": def sortkey(rel): return rel.get_current_state().state_date elif order == "unmatched": def sortkey(rel): return (False if rel.matched_paths() else True, rel.get_current_state().state_date) elif order == "ignored": def sortkey(rel): return rel.ignore elif order == "error": def sortkey(rel): count = 0 for state in rel.get_latest_checker_results(): if state.result == 'b': count += 1 for directory in rel.collectiondirectory_set.all(): for f in directory.collectionfile_set.all(): for state in f.get_latest_checker_results(): if state.result == 'b': count += 1 return count else: def sortkey(obj): pass releases = sorted(releases, key=sortkey, reverse=True) numfinished = sum(1 for _ in (r for r in releases if r.get_current_state().state == 'f')) numtotal = sum(1 for _ in (r for r in releases if len(r.all_files()))) folders = models.CollectionDirectory.objects.filter( collection=c, musicbrainzrelease__isnull=True) log = models.CollectionLogMessage.objects.filter( collection=c).order_by('-datetime') ret = {"collection": c, "log_messages": log, "releases": releases, "folders": folders, \ "numtotal": numtotal, "numfinished": numfinished} return render(request, 'dashboard/collection.html', ret)
def index(request): if request.method == 'POST': form = forms.AddCollectionForm(request.POST) if form.is_valid(): # Import collection id coll_id = form.cleaned_data['collectionid'] path = form.cleaned_data['path'] coll_name = form.cleaned_data['collectionname'] do_import = form.cleaned_data['do_import'] checkers = [] for i in form.cleaned_data['checkers']: checkers.append(get_object_or_404(models.CompletenessChecker, pk=int(i))) new_collection = models.Collection.objects.create(id=coll_id, name=coll_name, root_directory=path, do_import=do_import) new_collection.checkers.add(*checkers) docserver.models.Collection.objects.get_or_create(collectionid=coll_id, defaults={"root_directory":path, "name":coll_name}) jobs.load_and_import_collection(new_collection.id) return HttpResponseRedirect(reverse('dashboard-home')) else: form = forms.AddCollectionForm() collections = models.Collection.objects.all() ret = {'form': form, 'collections': collections} return render(request, 'dashboard/index.html', ret)
def index(request): if request.method == 'POST': form = forms.AddCollectionForm(request.POST) if form.is_valid(): # Import collection id coll_id = form.cleaned_data['collectionid'] path = form.cleaned_data['path'] coll_name = form.cleaned_data['collectionname'] do_import = form.cleaned_data['do_import'] checkers = [] for i in form.cleaned_data['checkers']: checkers.append( get_object_or_404(models.CompletenessChecker, pk=int(i))) new_collection = models.Collection.objects.create( id=coll_id, name=coll_name, root_directory=path, do_import=do_import) new_collection.checkers.add(*checkers) docserver.models.Collection.objects.get_or_create( collectionid=coll_id, defaults={ "root_directory": path, "name": coll_name }) jobs.load_and_import_collection(new_collection.id) return HttpResponseRedirect(reverse('dashboard-home')) else: form = forms.AddCollectionForm() collections = models.Collection.objects.all() ret = {'form': form, 'collections': collections} return render(request, 'dashboard/index.html', ret)
def collection(request, uuid): c = get_object_or_404(models.Collection.objects.prefetch_related('collectionstate_set'), pk=uuid) rescan = request.GET.get("rescan") if rescan is not None: jobs.load_and_import_collection(c.id) return redirect('dashboard-collection', uuid) forcescan = request.GET.get("forcescan") if forcescan is not None: jobs.force_load_and_import_collection(c.id) return redirect('dashboard-collection', uuid) order = request.GET.get("order") releases = models.MusicbrainzRelease.objects.filter(collection=c)\ .prefetch_related('musicbrainzreleasestate_set')\ .prefetch_related('collectiondirectory_set')\ .prefetch_related('collectiondirectory_set__collectionfile_set') if order == "date": def sortkey(rel): return rel.get_current_state().state_date elif order == "unmatched": def sortkey(rel): return (False if rel.matched_paths() else True, rel.get_current_state().state_date) elif order == "ignored": def sortkey(rel): return rel.ignore elif order == "error": def sortkey(rel): count = 0 for state in rel.get_latest_checker_results(): if state.result == 'b': count += 1 for directory in rel.collectiondirectory_set.all(): for f in directory.collectionfile_set.all(): for state in f.get_latest_checker_results(): if state.result == 'b': count += 1 return count else: def sortkey(obj): pass releases = sorted(releases, key=sortkey, reverse=True) numtotal = len(releases) numfinished = 0 nummatched = 0 for r in releases: if r.all_files(): nummatched += 1 if r.get_current_state().state == 'f': numfinished += 1 folders = models.CollectionDirectory.objects.filter(collection=c, musicbrainzrelease__isnull=True) log = models.CollectionLogMessage.objects.filter(collection=c).order_by('-datetime') ret = {"collection": c, "log_messages": log, "releases": releases, "folders": folders, "numtotal": numtotal, "numfinished": numfinished, "nummatched": nummatched} return render(request, 'dashboard/collection.html', ret)