Skip to content

Commit

Permalink
Add a way to populate draft lock state from version we're checking
Browse files Browse the repository at this point in the history
  • Loading branch information
Krzysztof Socha committed Jun 21, 2019
1 parent f959c38 commit b4c0514
Showing 1 changed file with 13 additions and 4 deletions.
17 changes: 13 additions & 4 deletions djangocms_version_locking/monkeypatch/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,19 @@ def inner(version, user):

def _is_draft_version_locked(message):
def inner(version, user):
draft_version = get_latest_draft_version(version)
lock = version_is_locked(draft_version)
if lock and lock.created_by != user:
raise ConditionFailed(message.format(user=lock.created_by))
try:
# if there's a prepoluated field on version object
# representing a draft lock, use it
cached_draft_version_user_id = getattr(version, "_draft_version_user_id")
if cached_draft_version_user_id and cached_draft_version_user_id != user.pk:
raise ConditionFailed(
message.format(user="User #{}".format(cached_draft_version_user_id))
)
except AttributeError:
draft_version = get_latest_draft_version(version)
lock = version_is_locked(draft_version)
if lock and lock.created_by != user:
raise ConditionFailed(message.format(user=lock.created_by))
return inner


Expand Down

0 comments on commit b4c0514

Please sign in to comment.