2017-02-04 00:08:12 +00:00
|
|
|
from szurubooru import errors, rest, model
|
2016-08-14 18:30:48 +00:00
|
|
|
|
|
|
|
|
2017-02-04 00:08:12 +00:00
|
|
|
def verify_version(
|
|
|
|
entity: model.Base,
|
|
|
|
context: rest.Context,
|
2017-04-24 21:30:53 +00:00
|
|
|
field_name: str = 'version') -> None:
|
2017-02-04 00:08:12 +00:00
|
|
|
actual_version = context.get_param_as_int(field_name)
|
2016-08-14 18:30:48 +00:00
|
|
|
expected_version = entity.version
|
|
|
|
if actual_version != expected_version:
|
2016-09-10 08:37:28 +00:00
|
|
|
raise errors.IntegrityError(
|
2016-08-14 18:30:48 +00:00
|
|
|
'Someone else modified this in the meantime. ' +
|
|
|
|
'Please try again.')
|
|
|
|
|
|
|
|
|
2017-02-04 00:08:12 +00:00
|
|
|
def bump_version(entity: model.Base) -> None:
|
2016-08-14 18:30:48 +00:00
|
|
|
entity.version = entity.version + 1
|