Skip to content

Commit

Permalink
Add transcription count to ES index for User, submission count for Asset
Browse files Browse the repository at this point in the history
  • Loading branch information
rstorey committed Jun 26, 2019
1 parent de85e7c commit 7ee116b
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 26 deletions.
43 changes: 22 additions & 21 deletions concordia/documents.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,11 @@
from django.contrib.auth.models import User
from django.db.models import Count
from django_elasticsearch_dsl import DocType, Index, fields

from .models import (
Asset,
SiteReport,
Transcription,
UserAssetTagCollection,
UserProfile,
)
from .models import Asset, SiteReport, Transcription, UserAssetTagCollection

user_profile = Index("user_profiles")
user_profile.settings(number_of_shards=1, number_of_replicas=0)
user = Index("users")
user.settings(number_of_shards=1, number_of_replicas=0)

tag_collection = Index("tags")
tag_collection.settings(number_of_shards=1, number_of_replicas=0)
Expand All @@ -24,20 +20,18 @@
asset.settings(number_of_shards=1, number_of_replicas=0)


@user_profile.doc_type
class UserProfileDocument(DocType):
transcription_count = fields.IntegerField(attr="transcription_count")
user = fields.ObjectField(
properties={
"last_login": fields.DateField(),
"date_joined": fields.DateField(),
"username": fields.KeywordField(),
"is_active": fields.BooleanField(),
}
)
@user.doc_type
class UserDocument(DocType):
transcription_count = fields.IntegerField()

def prepare_transcription_count(self, instance):
qs = User.objects.filter(id=instance.id).annotate(Count("transcription"))
return qs[0].transcription__count

class Meta:
model = UserProfile
model = User

fields = ["last_login", "date_joined", "username", "is_active"]


@site_report.doc_type
Expand Down Expand Up @@ -189,6 +183,13 @@ class AssetDocument(DocType):
}
)

submission_count = fields.IntegerField()

def prepare_submission_count(self, instance):
return Transcription.objects.filter(
asset=instance, submitted__isnull=True
).count()

class Meta:
model = Asset
fields = ["published", "difficulty", "slug", "sequence", "year"]
Expand Down
5 changes: 0 additions & 5 deletions concordia/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,6 @@
class UserProfile(MetricsModelMixin("userprofile"), models.Model):
user = models.ForeignKey(User, on_delete=models.CASCADE)

def transcription_count(self):
user_qs = User.get(self.user.id)
user_qs = user_qs.annotate(Count("transcription"))
return user_qs.transcription_count


class TranscriptionStatus(object):
"""
Expand Down

0 comments on commit 7ee116b

Please sign in to comment.