def receive(self): with elevated_privileges(): with as_internal_workflow_transition(): api.content.transition( obj=self.context, transition='proposal-transition-decide') IHistory(self.context).append_record(u'decided') ProposalDecideActivity(self.context, self.request).record() document = super(ReceiveProposalDecided, self).receive() ILockable(document).lock(MEETING_EXCERPT_LOCK) return document
def reject(self, text): assert self.workflow.can_execute_transition(self, 'submitted-pending') self.submitted_physical_path = None self.submitted_admin_unit_id = None self.submitted_int_id = None # set workflow state directly for once, the transition is used to # redirect to a form. self.workflow_state = self.STATE_PENDING.name IHistory(self.resolve_proposal()).append_record(u'rejected', text=text)
def revise(self, agenda_item): assert self.get_state() == self.STATE_DECIDED document = self.resolve_submitted_proposal().get_proposal_document() checkout_manager = getMultiAdapter((document, document.REQUEST), ICheckinCheckoutManager) if checkout_manager.get_checked_out_by() is not None: raise ValueError( 'Cannot revise proposal when proposal document is checked out.' ) IHistory(self.resolve_submitted_proposal()).append_record(u'revised')
def receive(self): document = super(RecieveSubmittedDocumentView, self).receive() history_data = advancedjson.loads(self.request.get('history_data')) with elevated_privileges(): IHistory(self.context).append_record( u'document_submitted', document_title=document.title, submitted_version=history_data['submitted_version'], uuid=history_data['uuid']) ILockable(document).lock(MEETING_SUBMITTED_LOCK) return document
def revise(self, agenda_item): assert self.get_state() == self.STATE_DECIDED if is_word_meeting_implementation_enabled(): document = self.resolve_submitted_proposal().get_proposal_document( ) checkout_manager = getMultiAdapter((document, document.REQUEST), ICheckinCheckoutManager) if checkout_manager.get_checked_out_by() is not None: raise ValueError( 'Cannot revise proposal when proposal document is checked out.' ) else: self.update_excerpt(agenda_item) IHistory(self.resolve_submitted_proposal()).append_record(u'revised')
def get_date_of_submission_from_history(self, proposal): """Find date of submission for (submitted-)proposal in history. Go through history from oldest to newest and return date of submission. If it was rejected after being submitted, return None. """ date_of_submission = None for record in reversed(list(IHistory(proposal))): if record.history_type == 'submitted': date_of_submission = record.created.date() elif record.history_type == 'rejected': date_of_submission = None return date_of_submission
def __call__(self): data = advancedjson.loads(self.request.get('data')) text = data['text'] with elevated_privileges(): with as_internal_workflow_transition(): api.content.transition( obj=self.context, transition='proposal-transition-reject') IHistory(self.context).append_record( u'rejected', text=text) ProposalRejectedActivity(self.context, self.request).record() self.context.date_of_submission = None return ok_response(self.request)
def __call__(self): alsoProvides(self.request, IDisableCSRFProtection) # internal request data = advancedjson.loads(self.request.get('data')) meeting_id = data['meeting_id'] with elevated_privileges(): with as_internal_workflow_transition(): api.content.transition( obj=self.context, transition='proposal-transition-unschedule') IHistory(self.context).append_record( u'remove_scheduled', meeting_id=meeting_id) ProposalRemovedFromScheduleActivity( self.context, self.request, meeting_id).record() return ok_response(self.request)
def remove_scheduled(self, meeting): self.execute_transition('scheduled-submitted') IHistory(self.resolve_submitted_proposal()).append_record( u'remove_scheduled', meeting_id=meeting.meeting_id) request_data = { 'data': advancedjson.dumps({ 'meeting_id': meeting.meeting_id, }) } expect_ok_response( dispatch_request(self.admin_unit_id, '@@receive-proposal-unscheduled', path=self.physical_path, data=request_data), 'Unexpected response {!r} when unscheduling proposal.')
def __call__(self): jsondata = self.request.get(REQUEST_KEY) data = encode_after_json(json.loads(jsondata)) committee = Oguid.parse(data['committee_oguid']).resolve_object() proposal_oguid = Oguid.parse(data['proposal_oguid']) proposal_model = meeting_service().fetch_proposal_by_oguid( proposal_oguid) with elevated_privileges(): submitted_proposal = SubmittedProposal.create( proposal_model, committee) # XXX use Transporter API? collector = getMultiAdapter((submitted_proposal, ), IDataCollector, name='field-data') data['field-data']['ISubmittedProposal'] = data['field-data'].pop( 'IProposal') collector.insert(data['field-data']) # XXX fix data types in transporter submitted_proposal.date_of_submission = date.today() # sync data to proposal after inserting field data proposal_model.submitted_oguid = Oguid.for_object( submitted_proposal) proposal_model.sync_with_submitted_proposal(submitted_proposal) submitted_proposal.create_proposal_document( title=data['title'], filename=data['file']['filename'], content_type=data['file']['contentType'].encode('utf-8'), data=base64.decodestring(data['file']['data'])) history_data = advancedjson.loads(self.request.get('history_data')) IHistory(submitted_proposal).append_record( u'submitted', uuid=history_data['uuid'], text=history_data.get("text")) add_watchers_on_submitted_proposal_created(submitted_proposal) ProposalSubmittedActivity(submitted_proposal, self.request).record() self.request.response.setHeader("Content-type", "application/json") return json.dumps( {'path': '/'.join(submitted_proposal.getPhysicalPath())})
def decide(self, agenda_item): if is_word_meeting_implementation_enabled(): document = self.resolve_submitted_proposal().get_proposal_document( ) checkout_manager = getMultiAdapter((document, document.REQUEST), ICheckinCheckoutManager) if checkout_manager.get_checked_out_by() is not None: raise ValueError( 'Cannot decide proposal when proposal document is checked out.' ) else: self.generate_excerpt(agenda_item) document_intid = self.copy_excerpt_to_proposal_dossier() self.register_excerpt(document_intid) IHistory(self.resolve_submitted_proposal()).append_record(u'decided') self.execute_transition('scheduled-decided')
def copy_document(self, target_path, target_admin_unit_id): submitted_version = self.document.get_current_version_id( missing_as_zero=True) record = IHistory(self.proposal).append_record( u'document_submitted', document_title=self.document.title, submitted_version=submitted_version, ) history_data = advancedjson.dumps({ 'submitted_version': submitted_version, 'uuid': record.uuid, }) return SubmitDocumentCommand( self.document, target_admin_unit_id, target_path, history_data=history_data).execute()
def __call__(self): if not self.context.is_submitted_document(): raise NoSubmittedDocument() if self.context.is_checked_out(): raise Unauthorized() submitted_proposal = aq_parent(aq_inner(self.context)) history_data = advancedjson.loads(self.request.get('history_data')) with elevated_privileges(): transporter = Transporter() transporter.update(self.context, self.request) IHistory(submitted_proposal).append_record( u'document_updated', document_title=self.context.title, submitted_version=history_data['submitted_version'], uuid=history_data['uuid']) ProposalDocumentUpdatedActivity( submitted_proposal, self.request, self.context.title, history_data['submitted_version']).record() portal_path = '/'.join(api.portal.get().getPhysicalPath()) intids = getUtility(IIntIds) comment = translate(_( u"Updated with a newer docment version from proposal's " "dossier."), context=self.request) Versioner(self.context).create_version(comment) data = { 'path': '/'.join(self.context.getPhysicalPath())[len(portal_path) + 1:], 'intid': intids.queryId(self.context) } # Set correct content type for JSON response self.request.response.setHeader("Content-type", "application/json") return json.dumps(data)
def test_api_proposal_cancel_transition(self, browser): self.login(self.dossier_responsible, browser) data = {'text': u'\xc4u\xe4 nid'} url = '{}/@workflow/proposal-transition-cancel'.format( self.draft_proposal.absolute_url()) browser.open(url, method='POST', data=json.dumps(data), headers=self.api_headers) proposal_history = IHistory(self.draft_proposal) proposal_submitted = list(proposal_history)[0] self.assertEqual(u'\xc4u\xe4 nid', proposal_submitted.text) self.assertEqual(u'cancelled', proposal_submitted.history_type) self.assertEqual(Proposal.STATE_CANCELLED, self.draft_proposal.get_state()) self.assert_workflow_state('proposal-state-cancelled', self.draft_proposal)
def test_api_proposal_submit_transition(self, browser): self.login(self.dossier_responsible, browser) self.add_related_item(self.draft_proposal, self.document) data = {'text': 'Fertig!'} url = '{}/@workflow/proposal-transition-submit'.format( self.draft_proposal.absolute_url()) browser.open(url, method='POST', data=json.dumps(data), headers=self.api_headers) proposal_history = IHistory(self.draft_proposal) proposal_submitted = list(proposal_history)[1] self.assertEqual(u'Fertig!', proposal_submitted.text) self.assertEqual(u'submitted', proposal_submitted.history_type) doc_submitted = list(proposal_history)[0] self.assertEqual(u'document_submitted', doc_submitted.history_type) self._assert_proposal_submitted_correctly(browser)
def decide(self, agenda_item, excerpt_document): # Proposals for AgendaItems that were decided before we introduced that # Proposals get decided only when the excerpt is returned can be # already decided even if the proposal has not been returned. Thus we # only decide the proposal if it has not been decided yet. if not self.is_decided(): proposal_document = self.resolve_submitted_proposal( ).get_proposal_document() checkout_manager = getMultiAdapter( (proposal_document, proposal_document.REQUEST), ICheckinCheckoutManager) if checkout_manager.get_checked_out_by() is not None: raise ValueError( 'Cannot decide proposal when proposal document is checked out.' ) submitted_proposal = self.resolve_submitted_proposal() ProposalDecideActivity(submitted_proposal, getRequest()).record() IHistory(submitted_proposal).append_record(u'decided') self.execute_transition('scheduled-decided') self._return_excerpt(excerpt_document)
def execute(self): submitted_version = self.document.get_current_version_id() record = IHistory(self.proposal).append_record( u'document_updated', document_title=self.document.title, submitted_version=submitted_version, ) history_data = advancedjson.dumps({ 'submitted_version': submitted_version, 'uuid': record.uuid, }) Transporter().transport_to( self.document, self.submitted_document.submitted_admin_unit_id, self.submitted_document.submitted_physical_path, view='update-submitted-document', history_data=history_data) submitted_document = SubmittedDocument.query.get_by_source( self.proposal, self.document) submitted_document.submitted_version = submitted_version
def schedule(self, meeting): assert self.can_be_scheduled() self.execute_transition('submitted-scheduled') meeting.agenda_items.append(AgendaItem(proposal=self)) meeting.reorder_agenda_items() submitted_proposal = self.resolve_submitted_proposal() ProposalScheduledActivity(submitted_proposal, getRequest(), meeting.meeting_id).record() IHistory(self.resolve_submitted_proposal()).append_record( u'scheduled', meeting_id=meeting.meeting_id) request_data = { 'data': advancedjson.dumps({ 'meeting_id': meeting.meeting_id, }) } expect_ok_response( dispatch_request(self.admin_unit_id, '@@receive-proposal-scheduled', path=self.physical_path, data=request_data), 'Unexpected response {!r} when scheduling proposal.')
def comment(self, text, uuid=None): ProposalCommentedActivitiy(self, self.REQUEST).record() return IHistory(self).append_record(u'commented', uuid=uuid, text=text)
def history(self): return IHistory(self.context)
def _after_model_created(self, model_instance): IHistory(self).append_record(u'created')
def reopen(self, agenda_item): assert self.is_decided() IHistory(self.resolve_submitted_proposal()).append_record(u'reopened')
def reactivate(self): IHistory(self.resolve_proposal()).append_record(u'reactivated')
def cancel(self): IHistory(self.resolve_proposal()).append_record(u'cancelled')
def reopen(self, agenda_item): assert self.get_state() == self.STATE_DECIDED IHistory(self.resolve_submitted_proposal()).append_record(u'reopened')
def after_transition_hook(self, transition, disable_sync, transition_params): IHistory(self.context).append_record( u'reactivated', text=transition_params.get('text')) ProposalSqlSyncer(self.context, None).sync()
def remove_scheduled(self, meeting): self.execute_transition('scheduled-submitted') IHistory(self.resolve_submitted_proposal()).append_record( u'remove_scheduled', meeting_id=meeting.meeting_id)