Skip to content

Commit 5d89ba2

Browse files
Merge pull request #2858 from LibraryOfCongress/CONCD-1185-jstegmaier-ajax-docs
Added docs for ajax.py and updated other docs to new format
2 parents 6a15c31 + e0e844b commit 5d89ba2

File tree

3 files changed

+699
-295
lines changed

3 files changed

+699
-295
lines changed

concordia/models.py

Lines changed: 58 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -741,20 +741,22 @@ def can_rollback(
741741
transcription that precedes the current latest transcription, excluding any
742742
transcriptions that are rollforwards or are sources of rollforwards.
743743
744-
Returns:
745-
tuple:
746-
- (True, target, original) if a rollback is possible, where:
747-
* target is the transcription to roll back to.
748-
* original is the current latest transcription.
749-
- (False, reason, None) if a rollback is not possible, where:
750-
* reason is a string explaining why.
751-
752744
A rollback is only possible if:
753-
- There is more than one transcription.
754-
- There is a prior transcription that is not a rollforward
755-
or a source of one.
745+
- There is more than one transcription.
746+
- There is a prior transcription that is not a rollforward or source of one.
756747
757748
This method does not perform the rollback, only checks feasibility.
749+
750+
Returns:
751+
result (tuple): A (bool, value, latest) tuple describing rollback
752+
possibility.
753+
754+
Return Behavior:
755+
- If no transcriptions exist: returns (False, reason_string, None).
756+
- If no eligible rollback target exists: returns (False, reason_string,
757+
None).
758+
- If rollback is possible: returns (True, target_transcription,
759+
latest_transcription).
758760
"""
759761
# original_latest_transcription holds the actual latest transcription
760762
# latest_transcription starts by holding the actual latest transcription,
@@ -822,19 +824,21 @@ def rollback_transcription(self, user: User) -> Transcription:
822824
as rolled back. It also updates the original latest transcription to reflect
823825
that it has been superseded.
824826
825-
Args:
826-
user (User): The user initiating the rollback.
827-
828-
Returns:
829-
Transcription: The newly created rollback transcription.
830-
831-
Raises:
832-
ValueError: If rollback is not possible (e.g. no eligible transcription).
827+
If rollback is not possible, raises a `ValueError`.
833828
834829
The new transcription will:
835830
- Have `rolled_back=True`.
836831
- Set its `source` to the transcription it is rolled back to.
837832
- Set `supersedes` to the current latest transcription.
833+
834+
Args:
835+
user (User): The user performing the rollback.
836+
837+
Returns:
838+
transcription (Transcription): The newly created rollback transcription.
839+
840+
Raises:
841+
ValueError: If rollback is not possible due to invalid or missing history.
838842
"""
839843
results = self.can_rollback()
840844
if results[0] is not True:
@@ -878,21 +882,25 @@ def can_rollforward(
878882
This checks whether the most recent transcription is a rollback transcription
879883
and whether the transcription it replaced (its `supersedes`) can be restored.
880884
881-
Returns:
882-
tuple:
883-
- (True, target, original) if rollforward is possible, where:
884-
* target is the transcription to roll forward to.
885-
* original is the current latest transcription.
886-
- (False, reason, None) if rollforward is not possible, where:
887-
* reason is a string explaining why.
888-
889885
This method handles cases where multiple rollforwards were applied,
890886
walking backward through the transcription chain to find the appropriate
891887
rollback origin.
892888
893889
A rollforward is only possible if:
894-
- The latest transcription is a rollback.
895-
- The rollback's superseded transcription exists and can be restored.
890+
- The latest transcription is a rollback.
891+
- The rollback’s superseded transcription still exists and can be restored.
892+
893+
This method does not perform the rollforward, only checks feasibility.
894+
895+
Returns:
896+
result (tuple): A (bool, value, latest) tuple describing rollforward
897+
possibility.
898+
899+
Return Behavior:
900+
- If no transcriptions exist: returns (False, reason_string, None).
901+
- If the rollback chain is malformed: returns (False, reason_string, None).
902+
- If rollforward is possible: returns (True, target_transcription,
903+
latest_transcription).
896904
"""
897905
# original_latest_transcription holds the actual latest transcription
898906
# latest_transcription starts by holding the actual latest transcription,
@@ -999,23 +1007,34 @@ def rollforward_transcription(self, user: User) -> Transcription:
9991007
"""
10001008
Perform a rollforward of the most recent rollback transcription.
10011009
1002-
This creates a new transcription that restores the text from the
1003-
rollback's superseded transcription and marks it as a rollforward.
1010+
This creates a new transcription that restores the text from the rollback's
1011+
superseded transcription and marks it as a rollforward. A rollforward is only
1012+
possible if the latest transcription is a rollback and the replaced
1013+
transcription still exists.
1014+
1015+
If rollforward is not possible, raises a `ValueError`.
1016+
1017+
The new transcription will:
1018+
- Have `rolled_forward=True`.
1019+
- Set its `source` to the transcription being rolled forward to.
1020+
- Set `supersedes` to the current latest transcription.
10041021
10051022
Args:
10061023
user (User): The user initiating the rollforward.
10071024
10081025
Returns:
1009-
Transcription: The newly created rollforward transcription.
1026+
transcription (Transcription): The newly created rollforward transcription.
10101027
10111028
Raises:
1012-
ValueError: If rollforward is not possible (e.g. no valid rollback
1013-
history or malformed transcription chain).
1014-
1015-
The new transcription will:
1016-
- Have `rolled_forward=True`.
1017-
- Set its `source` to the transcription being rolled forward to.
1018-
- Set `supersedes` to the current latest transcription.
1029+
ValueError: If rollforward is not possible, such as when no rollback
1030+
exists or the history is malformed.
1031+
1032+
Return Behavior:
1033+
- If rollforward is possible:
1034+
- Creates a new transcription restoring the original text.
1035+
- Marks it with `rolled_forward=True`.
1036+
- If rollforward is not possible:
1037+
- Raises `ValueError` with a descriptive message.
10191038
"""
10201039
results = self.can_rollforward()
10211040
if results[0] is not True:

0 commit comments

Comments
 (0)