def stats_view(request): collections_by_journals = {} for collection in Collection.objects.filter( private=False).exclude(Q(DOI__isnull=True) | Q(DOI__exact='')): if not collection.journal_name: _, _, _, _, collection.journal_name = get_paper_properties( collection.DOI) collection.save() if collection.journal_name not in collections_by_journals.keys(): collections_by_journals[collection.journal_name] = 1 else: collections_by_journals[collection.journal_name] += 1 collections_by_journals = OrderedDict( sorted(collections_by_journals.items(), key=lambda t: t[1], reverse=True)) non_empty_collections_count = Collection.objects.annotate( num_submissions=Count('image')).filter(num_submissions__gt=0).count() public_collections_count = Collection.objects.filter( private=False).annotate(num_submissions=Count('image')).filter( num_submissions__gt=0).count() public_collections_with_DOIs_count = Collection.objects.filter( private=False).exclude(Q(DOI__isnull=True) | Q(DOI__exact='')).annotate( num_submissions=Count('image')).filter( num_submissions__gt=0).count() context = { 'collections_by_journals': collections_by_journals, 'non_empty_collections_count': non_empty_collections_count, 'public_collections_count': public_collections_count, 'public_collections_with_DOIs_count': public_collections_with_DOIs_count } return render(request, 'statmaps/stats.html.haml', context)
def clean(self): cleaned_data = super(CollectionForm, self).clean() doi = self.cleaned_data['DOI'] if doi.strip() == '': self.cleaned_data['DOI'] = None if self.cleaned_data['DOI']: self.cleaned_data['DOI'] = self.cleaned_data['DOI'].strip() try: self.cleaned_data["name"], self.cleaned_data[ "authors"], self.cleaned_data[ "paper_url"], _, self.cleaned_data[ "journal_name"] = get_paper_properties( self.cleaned_data['DOI'].strip()) except: self._errors["DOI"] = self.error_class( ["Could not resolve DOI"]) else: if "name" in self._errors: del self._errors["name"] elif "name" not in cleaned_data or not cleaned_data["name"]: self._errors["name"] = self.error_class( ["You need to set the name or the DOI"]) self._errors["DOI"] = self.error_class( ["You need to set the name or the DOI"]) return cleaned_data
def validate(self, data): doi = strip(data.get('DOI')) name = strip(data.get('name')) if not self.instance: if not (logical_xor(doi, name)): raise serializers.ValidationError( 'Specify either "name" or "DOI"') if doi: try: (name, authors, paper_url, _, journal_name) = get_paper_properties(doi) data['name'] = name data['authors'] = authors data['paper_url'] = paper_url data['journal_name'] = journal_name except: raise serializers.ValidationError('Could not resolve DOI') return data
def validate(self, data): doi = strip(data.get('DOI')) name = strip(data.get('name')) if not self.instance: if not (logical_xor(doi, name)): raise serializers.ValidationError( 'Specify either "name" or "DOI"' ) if doi: try: (name, authors, paper_url, _, journal_name) = get_paper_properties(doi) data['name'] = name data['authors'] = authors data['paper_url'] = paper_url data['journal_name'] = journal_name except: raise serializers.ValidationError('Could not resolve DOI') return data
def stats_view(request): collections_by_journals = {} for collection in Collection.objects.filter( private=False).exclude(Q(DOI__isnull=True) | Q(DOI__exact='')): if not collection.journal_name: _,_,_,_, collection.journal_name = get_paper_properties(collection.DOI) collection.save() if collection.journal_name not in collections_by_journals.keys(): collections_by_journals[collection.journal_name] = 1 else: collections_by_journals[collection.journal_name] += 1 collections_by_journals = OrderedDict(sorted(collections_by_journals.items( ), key=lambda t: t[1], reverse=True)) non_empty_collections_count = Collection.objects.annotate(num_submissions=Count('image')).filter(num_submissions__gt = 0).count() public_collections_count = Collection.objects.filter(private=False).annotate(num_submissions=Count('image')).filter(num_submissions__gt = 0).count() public_collections_with_DOIs_count = Collection.objects.filter(private=False).exclude(Q(DOI__isnull=True) | Q(DOI__exact='')).annotate(num_submissions=Count('image')).filter(num_submissions__gt = 0).count() context = {'collections_by_journals': collections_by_journals, 'non_empty_collections_count': non_empty_collections_count, 'public_collections_count': public_collections_count, 'public_collections_with_DOIs_count': public_collections_with_DOIs_count} return render(request, 'statmaps/stats.html.haml', context)
def clean(self): cleaned_data = super(CollectionForm, self).clean() doi = self.cleaned_data['DOI'] if doi.strip() == '': self.cleaned_data['DOI'] = None if self.cleaned_data['DOI']: try: self.cleaned_data["name"], self.cleaned_data["authors"], self.cleaned_data[ "paper_url"], _, self.cleaned_data["journal_name"] = get_paper_properties(self.cleaned_data['DOI'].strip()) except: self._errors["DOI"] = self.error_class( ["Could not resolve DOI"]) else: if "name" in self._errors: del self._errors["name"] elif "name" not in cleaned_data or not cleaned_data["name"]: self._errors["name"] = self.error_class( ["You need to set the name or the DOI"]) self._errors["DOI"] = self.error_class( ["You need to set the name or the DOI"]) return cleaned_data