Skip to content

Instantly share code, notes, and snippets.

@christianplazas-wf
Last active August 29, 2015 14:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save christianplazas-wf/8aed46b99ba48f7201d1 to your computer and use it in GitHub Desktop.
Save christianplazas-wf/8aed46b99ba48f7201d1 to your computer and use it in GitHub Desktop.
Script to call start_share_calc on element changes
from wf.apps.dc.utils import get_section_ids_for_template_id
from calc.constants import SHARE
from calc.start import start_share_calc
from calc.start import _get_calc_lock
from documents.versioning import get_next_revision
template_id=''
membership_key_str = ''
#step 1 - grab membership for use later
membership = db.get(membership_key_str)
#step 2 - grab element changes that we want to 'share'
element_changes = ndb.Key("DraftGroup", membership.key().id(), "ElementChanges", template_id).get()
#step 3 - grab all possible section ids for the template we are sharing
section_ids = get_section_ids_for_template_id(template_id)
#step 4 - get a revision for share calc
revision = get_next_revision(membership.account.key())
#step 5 - get a calc lock for this batch of changes
_, job_id, name, _ = _get_calc_lock(membership.account.key().id(), SHARE)
#step 6 - call start share calc to 'share' changes to TVES
start_share_calc(
membership.key(), element_changes.changes, revision, section_ids, membership.account.key(),
name, job_id=job_id)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment