Skip to content

Commit

Permalink
Merge pull request #636 from LibraryOfCongress/status-refactor
Browse files Browse the repository at this point in the history
Status refactor
  • Loading branch information
rstorey committed Nov 15, 2018
2 parents c4301a1 + cdb000a commit 71ca550
Show file tree
Hide file tree
Showing 12 changed files with 97 additions and 32 deletions.
26 changes: 26 additions & 0 deletions concordia/migrations/0014_auto_20181115_1411.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# Generated by Django 2.0.9 on 2018-11-15 19:11

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [("concordia", "0013_auto_20181031_1305")]

operations = [
migrations.AlterField(
model_name="asset",
name="transcription_status",
field=models.CharField(
choices=[
("not_started", "Not Started"),
("in_progress", "In Progress"),
("submitted", "Submitted for Review"),
("completed", "Completed"),
],
default="not_started",
editable=False,
max_length=20,
),
)
]
23 changes: 23 additions & 0 deletions concordia/migrations/0015_auto_20181115_1436.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# Generated by Django 2.0.9 on 2018-11-15 19:36

from django.db import migrations
from concordia.models import TranscriptionStatus


def split_edit_statuses(apps, schema_editor):
Transcription = apps.get_model("concordia", "Transcription")
Asset = apps.get_model("concordia", "Asset")

Asset.objects.filter(
pk__in=Transcription.objects.values("asset_id"), transcription_status="edit"
).update(transcription_status=TranscriptionStatus.IN_PROGRESS)
Asset.objects.filter(transcription_status="edit").update(
transcription_status=TranscriptionStatus.NOT_STARTED
)


class Migration(migrations.Migration):

dependencies = [("concordia", "0014_auto_20181115_1411")]

operations = [migrations.RunPython(split_edit_statuses)]
16 changes: 9 additions & 7 deletions concordia/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,14 @@ class TranscriptionStatus(object):
to avoid needing to do nested queries in views
"""

EDIT = "edit"
NOT_STARTED = "not_started"
IN_PROGRESS = "in_progress"
SUBMITTED = "submitted"
COMPLETED = "completed"

CHOICES = (
(EDIT, "Open for Edit"),
(NOT_STARTED, "Not Started"),
(IN_PROGRESS, "In Progress"),
(SUBMITTED, "Submitted for Review"),
(COMPLETED, "Completed"),
)
Expand Down Expand Up @@ -195,8 +197,8 @@ class Asset(MetricsModelMixin("asset"), models.Model):
# be directly modified except by the Transcription signal handler:
transcription_status = models.CharField(
editable=False,
max_length=10,
default=TranscriptionStatus.EDIT,
max_length=20,
default=TranscriptionStatus.NOT_STARTED,
choices=TranscriptionStatus.CHOICES,
)

Expand Down Expand Up @@ -289,11 +291,11 @@ def clean(self):
@property
def status(self):
if self.accepted:
return "Completed"
return TranscriptionStatus.CHOICE_MAP[TranscriptionStatus.COMPLETED]
elif self.submitted and not self.rejected:
return "Submitted"
return TranscriptionStatus.CHOICE_MAP[TranscriptionStatus.SUBMITTED]
else:
return "Edit"
return TranscriptionStatus.CHOICE_MAP[TranscriptionStatus.IN_PROGRESS]


class AssetTranscriptionReservation(models.Model):
Expand Down
2 changes: 1 addition & 1 deletion concordia/signals/handlers.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ def add_user_to_newsletter(sender, user, request, **kwargs):

@receiver(post_save, sender=Transcription)
def update_asset_status(sender, *, instance, **kwargs):
new_status = TranscriptionStatus.EDIT
new_status = TranscriptionStatus.IN_PROGRESS

if instance.accepted:
new_status = TranscriptionStatus.COMPLETED
Expand Down
11 changes: 8 additions & 3 deletions concordia/static/css/base.css
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@
--bg-loading: rgba(51, 51, 51, 0.5); /* #333333 */
--bg-completed: #00618e;
--bg-submitted: #2e91bf;
--bg-edit: #80cef3;
--bg-in_progress: #80cef3;
--bg-not_started: #e9ecef;

--shadow-color: rgba(51, 51, 51, 0.8); /* #333333 */
--light-shadow-color: rgba(51, 51, 51, 0.4); /* #333333 */
Expand Down Expand Up @@ -280,8 +281,12 @@ p.hero-secondary.offwhite-text {
background-color: var(--bg-submitted);
}

.bg-edit {
background-color: var(--bg-edit);
.bg-in_progress {
background-color: var(--bg-in_progress);
}

.bg-not_started {
background-color: var(--bg-not_started);
}

input {
Expand Down
14 changes: 11 additions & 3 deletions concordia/static/js/contribute.js
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,11 @@ $transcriptionEditor

var data = $transcriptionEditor.data();

if (!data.hasReservation || data.transcriptionStatus != 'edit') {
if (
!data.hasReservation ||
(data.transcriptionStatus != 'in_progress' &&
data.transcriptionStatus != 'not_started')
) {
lockControls($transcriptionEditor);
} else {
var $textarea = $transcriptionEditor.find('textarea');
Expand Down Expand Up @@ -203,7 +207,11 @@ $transcriptionEditor
}
}

if (!data.hasReservation && data.transcriptionStatus == 'edit') {
if (
!data.hasReservation &&
(data.transcriptionStatus == 'in_progress' ||
data.transcriptionStatus == 'not_started')
) {
$('.tx-status-display')
.children()
.attr('hidden', 'hidden')
Expand Down Expand Up @@ -255,7 +263,7 @@ $submitButton.on('click', function(evt) {
$('.tx-status-display')
.children()
.attr('hidden', 'hidden')
.has('.tx-submitted')
.filter('.tx-submitted')
.removeAttr('hidden');
$('#successful-submission-modal')
.modal()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
</div>
<div title="Submitted for Review" class="progress-bar bg-submitted" role="progressbar" style="width: {{ submitted_percent }}%" aria-valuenow="{{ submitted_percent }}" aria-valuemin="0" aria-valuemax="100">
</div>
<div title="In Progress" class="progress-bar bg-edit" role="progressbar" style="width: {{ edit_percent }}%" aria-valuenow="{{ edit_percent }}" aria-valuemin="0" aria-valuemax="100">
<div title="In Progress" class="progress-bar bg-edit" role="progressbar" style="width: {{ in_progress_percent }}%" aria-valuenow="{{ in_progress_percent }}" aria-valuemin="0" aria-valuemax="100">
</div>
</div>
<div class="table-responsive-md">
Expand Down
14 changes: 9 additions & 5 deletions concordia/templates/transcriptions/asset_detail.html
Original file line number Diff line number Diff line change
Expand Up @@ -131,9 +131,13 @@
<span class="fas fa-check"></span>
Completed
</span>
<span class="tx-edit" {% if transcription_status != "edit" %}hidden{% endif %}>
<span class="tx-edit" {% if transcription_status != "not_started" %}hidden{% endif %}>
<span class="fas fa-edit"></span>
Open for edit
Not started
</span>
<span class="tx-edit" {% if transcription_status != "in_progress" %}hidden{% endif %}>
<span class="fas fa-edit"></span>
In progress
</span>
<span class="tx-edit-conflict" hidden>
<span class="fas fa-exclamation-triangle"></span>
Expand All @@ -148,12 +152,12 @@
<h2>Transcription</h2>

{% spaceless %}
<textarea readonly class="form-control w-100 rounded flex-grow-1" name="text" id="transcription-input" placeholder="{% if transcription_status == 'edit' %}Go ahead, start typing. You got this!{% else %}Nothing to transcribe{% endif %}" aria-label="Transcription input">
<textarea readonly class="form-control w-100 rounded flex-grow-1" name="text" id="transcription-input" placeholder="{% if transcription_status == 'not_started' or transcription_status == 'in_progress' %}Go ahead, start typing. You got this!{% else %}Nothing to transcribe{% endif %}" aria-label="Transcription input">
{{ transcription.text }}
</textarea>

<div class="my-3 d-flex flex-wrap justify-content-around align-items-center btn-row">
{% if transcription_status == 'edit' %}
{% if transcription_status == 'not_started' or transcription_status == 'in_progress' %}
<div class="form-check w-100 text-center mt-0 mb-3">
<input id="nothing-to-transcribe" type="checkbox" class="form-check-input" />
<label class="form-check-label" for="nothing-to-transcribe">
Expand Down Expand Up @@ -480,7 +484,7 @@ <h5 class="modal-title">Please confirm you are not a robot</h5>
});
</script>

{% if transcription_status == "edit" %}
{% if transcription_status == "not_started" or transcription_status == "in_progress" %}
<script>
attemptToReserveAsset("{% url 'reserve-asset-for-transcription' asset.pk %}");
</script>
Expand Down
2 changes: 1 addition & 1 deletion concordia/templates/transcriptions/campaign_detail.html
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ <h4>Related Links</h4>
<div class="progress w-100 my-2">
<div title="Completed" class="progress-bar bg-completed" role="progressbar" style="width: {{ project.completed_percent }}%" aria-valuenow="{{ project.completed_percent }}" aria-valuemin="0" aria-valuemax="100"></div>
<div title="Submitted for Review" class="progress-bar bg-submitted" role="progressbar" style="width: {{ project.submitted_percent }}%" aria-valuenow="{{ project.submitted_percent }}" aria-valuemin="0" aria-valuemax="100"></div>
<div title="In Progress" class="progress-bar bg-edit" role="progressbar" style="width: {{ project.edit_percent }}%" aria-valuenow="{{ project.edit_percent }}" aria-valuemin="0" aria-valuemax="100"></div>
<div title="In Progress" class="progress-bar bg-edit" role="progressbar" style="width: {{ project.in_progress_percent }}%" aria-valuenow="{{ project.in_progress_percent }}" aria-valuemin="0" aria-valuemax="100"></div>
</div>

<h6 class="text-center primary-text">
Expand Down
2 changes: 1 addition & 1 deletion concordia/templates/transcriptions/project_detail.html
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ <h1 class="m-3">{{ project.title }}</h1>
<div class="progress w-100 my-2">
<div title="Completed" class="progress-bar bg-completed" role="progressbar" style="width: {{ item.completed_percent }}%" aria-valuenow="{{ item.completed_percent }}" aria-valuemin="0" aria-valuemax="100"></div>
<div title="Submitted for Review" class="progress-bar bg-submitted" role="progressbar" style="width: {{ item.submitted_percent }}%" aria-valuenow="{{ item.submitted_percent }}" aria-valuemin="0" aria-valuemax="100"></div>
<div title="In Progress" class="progress-bar bg-edit" role="progressbar" style="width: {{ item.edit_percent }}%" aria-valuenow="{{ item.edit_percent }}" aria-valuemin="0" aria-valuemax="100"></div>
<div title="In Progress" class="progress-bar bg-edit" role="progressbar" style="width: {{ item.in_progress_percent }}%" aria-valuenow="{{ item.in_progress_percent }}" aria-valuemin="0" aria-valuemax="100"></div>
</div>

<h6 class="text-center primary-text">
Expand Down
6 changes: 4 additions & 2 deletions concordia/tests/test_view.py
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,8 @@ def test_empty_item_detail_view(self):
)
self.assertContains(response, item.title)

self.assertEqual(0, response.context["edit_percent"])
self.assertEqual(0, response.context["not_started_percent"])
self.assertEqual(0, response.context["in_progress_percent"])
self.assertEqual(0, response.context["submitted_percent"])
self.assertEqual(0, response.context["completed_percent"])

Expand Down Expand Up @@ -201,7 +202,8 @@ def test_item_detail_view(self):

# We have 10 total, 6 of which have transcription records and of those
# 6, 3 have been submitted and one of those was accepted:
self.assertEqual(30, response.context["edit_percent"])
self.assertEqual(40, response.context["not_started_percent"])
self.assertEqual(30, response.context["in_progress_percent"])
self.assertEqual(20, response.context["submitted_percent"])
self.assertEqual(10, response.context["completed_percent"])

Expand Down
11 changes: 3 additions & 8 deletions concordia/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -305,11 +305,6 @@ def calculate_asset_stats(asset_qs, ctx):
asset_state_qs = asset_state_qs.annotate(Count("transcription_status")).order_by()
status_counts_by_key = dict(asset_state_qs)

if "edit" in status_counts_by_key:
# Correct semantic difference between our normal “open for edit”
# including assets with no progress at all:
status_counts_by_key["edit"] -= asset_qs.filter(transcription=None).count()

ctx["transcription_status_counts"] = labeled_status_counts = []

for status_key, status_label in TranscriptionStatus.CHOICES:
Expand Down Expand Up @@ -535,12 +530,12 @@ def get_context_data(self, **kwargs):
)

# We'll handle the case where an item with no transcriptions should be
# shown as status=edit here so the logic doesn't need to be repeated in
# shown as status=not_started here so the logic doesn't need to be repeated in
# templates:
if transcription:
transcription_status = transcription.status.lower()
else:
transcription_status = "edit"
transcription_status = TranscriptionStatus.NOT_STARTED
ctx["transcription_status"] = transcription_status

previous_asset = (
Expand Down Expand Up @@ -1041,7 +1036,7 @@ def redirect_to_next_transcribable_asset(request, *, campaign_slug):
potential_assets = Asset.objects.select_for_update(skip_locked=True, of=("self",))
potential_assets = potential_assets.filter(
item__project__campaign=campaign,
transcription_status=TranscriptionStatus.EDIT,
transcription_status=TranscriptionStatus.NOT_STARTED,
item__project__published=True,
item__published=True,
published=True,
Expand Down

0 comments on commit 71ca550

Please sign in to comment.