def test_anonymous_transcription_submission(self): asset = create_asset() anon = get_anonymous_user() transcription = Transcription(asset=asset, user=anon, text="previous entry") transcription.full_clean() transcription.save() resp = self.client.post( reverse("submit-transcription", args=(transcription.pk, ))) data = self.assertValidJSON(resp, expected_status=401) self.assertIn("key", data) self.assertIn("image", data) self.assertFalse( Transcription.objects.filter(submitted__isnull=False).exists()) self.completeCaptcha(data["key"]) self.client.post( reverse("submit-transcription", args=(transcription.pk, ))) self.assertTrue( Transcription.objects.filter(submitted__isnull=False).exists())
def test_transcription_review_asset_status_updates(self): """ Confirm that the Asset.transcription_status field is correctly updated throughout the review process """ asset = create_asset() anon = get_anonymous_user() # We should see NOT_STARTED only when no transcription records exist: self.assertEqual(asset.transcription_set.count(), 0) self.assertEqual( Asset.objects.get(pk=asset.pk).transcription_status, TranscriptionStatus.NOT_STARTED, ) t1 = Transcription(asset=asset, user=anon, text="test", submitted=now()) t1.full_clean() t1.save() self.assertEqual( Asset.objects.get(pk=asset.pk).transcription_status, TranscriptionStatus.SUBMITTED, ) # “Login” so we can review the anonymous transcription: self.login_user() self.assertEqual( 1, Transcription.objects.filter(pk=t1.pk, accepted__isnull=True).count()) resp = self.client.post(reverse("review-transcription", args=(t1.pk, )), data={"action": "reject"}) self.assertValidJSON(resp, expected_status=200) # After rejecting a transcription, the asset status should be reset to # in-progress: self.assertEqual( 1, Transcription.objects.filter(pk=t1.pk, accepted__isnull=True, rejected__isnull=False).count(), ) self.assertEqual( Asset.objects.get(pk=asset.pk).transcription_status, TranscriptionStatus.IN_PROGRESS, ) # We'll simulate a second attempt: t2 = Transcription(asset=asset, user=anon, text="test", submitted=now(), supersedes=t1) t2.full_clean() t2.save() self.assertEqual( Asset.objects.get(pk=asset.pk).transcription_status, TranscriptionStatus.SUBMITTED, ) resp = self.client.post(reverse("review-transcription", args=(t2.pk, )), data={"action": "accept"}) self.assertValidJSON(resp, expected_status=200) self.assertEqual( 1, Transcription.objects.filter(pk=t2.pk, accepted__isnull=False).count()) self.assertEqual( Asset.objects.get(pk=asset.pk).transcription_status, TranscriptionStatus.COMPLETED, )
def site_report(): report = { "assets_not_started": 0, "assets_in_progress": 0, "assets_submitted": 0, "assets_completed": 0, } asset_count_qs = Asset.objects.values_list("transcription_status").annotate( Count("transcription_status") ) for status, count in asset_count_qs: logger.debug("Assets %s: %d", status, count) report[f"assets_{status}"] = count assets_total = Asset.objects.count() assets_published = Asset.objects.published().count() assets_unpublished = Asset.objects.unpublished().count() items_published = Item.objects.published().count() items_unpublished = Item.objects.unpublished().count() projects_published = Project.objects.published().count() projects_unpublished = Project.objects.unpublished().count() campaigns_published = Campaign.objects.published().count() campaigns_unpublished = Campaign.objects.unpublished().count() users_registered = User.objects.all().count() users_activated = User.objects.filter(is_active=True).count() anonymous_transcriptions = Transcription.objects.filter( user=get_anonymous_user() ).count() transcriptions_saved = Transcription.objects.all().count() stats = UserAssetTagCollection.objects.aggregate(Count("tags")) tag_count = stats["tags__count"] distinct_tag_count = Tag.objects.all().count() site_report = SiteReport() site_report.assets_total = assets_total site_report.assets_published = assets_published site_report.assets_not_started = report["assets_not_started"] site_report.assets_in_progress = report["assets_in_progress"] site_report.assets_waiting_review = report["assets_submitted"] site_report.assets_completed = report["assets_completed"] site_report.assets_unpublished = assets_unpublished site_report.items_published = items_published site_report.items_unpublished = items_unpublished site_report.projects_published = projects_published site_report.projects_unpublished = projects_unpublished site_report.anonymous_transcriptions = anonymous_transcriptions site_report.transcriptions_saved = transcriptions_saved site_report.distinct_tags = distinct_tag_count site_report.tag_uses = tag_count site_report.campaigns_published = campaigns_published site_report.campaigns_unpublished = campaigns_unpublished site_report.users_registered = users_registered site_report.users_activated = users_activated site_report.save() for campaign in Campaign.objects.all(): campaign_report(campaign) for topic in Topic.objects.all(): topic_report(topic)
def campaign_report(campaign): report = { "assets_not_started": 0, "assets_in_progress": 0, "assets_submitted": 0, "assets_completed": 0, } asset_count_qs = ( Asset.objects.filter(item__project__campaign=campaign) .values_list("transcription_status") .annotate(Count("transcription_status")) ) for status, count in asset_count_qs: logger.debug("Campaign %s assets %s: %d", campaign.slug, status, count) report[f"assets_{status}"] = count assets_total = Asset.objects.filter(item__project__campaign=campaign).count() assets_published = ( Asset.objects.published().filter(item__project__campaign=campaign).count() ) assets_unpublished = ( Asset.objects.unpublished().filter(item__project__campaign=campaign).count() ) items_published = ( Item.objects.published().filter(project__campaign=campaign).count() ) items_unpublished = ( Item.objects.published().filter(project__campaign=campaign).count() ) projects_published = Project.objects.published().filter(campaign=campaign).count() projects_unpublished = ( Project.objects.unpublished().filter(campaign=campaign).count() ) anonymous_transcriptions = Transcription.objects.filter( asset__item__project__campaign=campaign, user=get_anonymous_user() ).count() transcriptions_saved = Transcription.objects.filter( asset__item__project__campaign=campaign ).count() asset_tag_collections = UserAssetTagCollection.objects.filter( asset__item__project__campaign=campaign ) stats = asset_tag_collections.order_by().aggregate(tag_count=Count("tags")) tag_count = stats["tag_count"] distinct_tag_list = set() for tag_collection in asset_tag_collections: distinct_tag_list.update(tag_collection.tags.values_list("pk", flat=True)) distinct_tag_count = len(distinct_tag_list) site_report = SiteReport() site_report.campaign = campaign site_report.assets_total = assets_total site_report.assets_published = assets_published site_report.assets_not_started = report["assets_not_started"] site_report.assets_in_progress = report["assets_in_progress"] site_report.assets_waiting_review = report["assets_submitted"] site_report.assets_completed = report["assets_completed"] site_report.assets_unpublished = assets_unpublished site_report.items_published = items_published site_report.items_unpublished = items_unpublished site_report.projects_published = projects_published site_report.projects_unpublished = projects_unpublished site_report.anonymous_transcriptions = anonymous_transcriptions site_report.transcriptions_saved = transcriptions_saved site_report.distinct_tags = distinct_tag_count site_report.tag_uses = tag_count site_report.save()