def METHOD_NAME(request, post, election):
    # If you're a user who's trusted to toggle the constituency lock,
    # they're allowed to edit candidacy:
    if user_in_group(request.user, TRUSTED_TO_LOCK_GROUP_NAME):
        return
    # Otherwise, if the constituency is locked, raise an exception:
    if post.ballot_set.get(election=election).candidates_locked:
        raise Exception("Attempt to edit a candidacy in a locked constituency")