コード例 #1
0
def new():
    '''Create a new opportunity
    '''
    form = OpportunityForm()

    if form.validate_on_submit():
        opportunity_data = form.data_cleanup()
        opportunity = Opportunity.create(
            opportunity_data, current_user,
            form.documents, request.form.get('save_type') == 'publish'
        )
        db.session.add(opportunity)
        db.session.commit()

        opportunity.send_publish_email()
        db.session.commit()
        flash('Opportunity post submitted to OMB!', 'alert-success')
        return redirect(url_for('opportunities_admin.edit', opportunity_id=opportunity.id))

    form.display_cleanup()

    return render_template(
        'opportunities/admin/opportunity.html', form=form, opportunity=None,
        subcategories=form.get_subcategories(),
        categories=form.get_categories()
    )
コード例 #2
0
def new():
    '''Create a new opportunity

    :status 200: Render the opportunity create/edit template
    :status 302: Post data for a new opportunity via the
        :py:class:`~purchasing.opportunities.forms.OpportunityForm`
        and redirect to the edit view of the created opportunity
    '''
    form = OpportunityForm()

    if form.validate_on_submit():
        opportunity_data = form.data_cleanup()
        opportunity = Opportunity.create(
            opportunity_data, current_user,
            form.documents, request.form.get('save_type') == 'publish'
        )
        db.session.add(opportunity)
        db.session.commit()

        opportunity.send_publish_email()
        db.session.commit()
        flash('Opportunity post submitted to OMB!', 'alert-success')
        return redirect(url_for('opportunities_admin.edit', opportunity_id=opportunity.id))

    form.display_cleanup()

    return render_template(
        'opportunities/admin/opportunity.html', form=form, opportunity=None,
        subcategories=form.get_subcategories(),
        categories=form.get_categories()
    )
コード例 #3
0
def new():
    '''Create a new opportunity

    :status 200: Render the opportunity create/edit template
    :status 302: Post data for a new opportunity via the
        :py:class:`~purchasing.opportunities.forms.OpportunityForm`
        and redirect to the edit view of the created opportunity
    '''
    form = OpportunityForm()

    if form.validate_on_submit():
        opportunity_data = form.data_cleanup()
        opportunity = Opportunity.create(
            opportunity_data, current_user, form.documents,
            request.form.get('save_type') == 'publish')
        db.session.add(opportunity)
        db.session.commit()

        opportunity.send_publish_email()
        db.session.commit()
        flash('Opportunity post submitted to OMB!', 'alert-success')
        return redirect(
            url_for('opportunities_admin.edit', opportunity_id=opportunity.id))

    form.display_cleanup()

    return render_template('opportunities/admin/opportunity.html',
                           form=form,
                           opportunity=None,
                           subcategories=form.get_subcategories(),
                           categories=form.get_categories())
コード例 #4
0
    def post_validate_action(self, action, contract, current_stage):
        '''Post the opportunity to Beacon

        Arguments:
            action: A
                :py:class:`~purchasing.data.contract_stages.ContractStageActionItem`
                that needs to be updated with details for the action
                log
            contract: A :py:class:`~purchasing.data.contracts.ContractBase` object
            current_stage: The current
                :py:class:`~purchasing.data.contract_stages.ContractStage`

        Returns:
            The modified
            :py:class:`~purchasing.data.contract_stages.ContractStageActionItem`
            with the action detail updated to include the form's data
        '''
        current_app.logger.info(
            'CONDUCTOR BEACON POST | Beacon posting on stage "{}" from contract "{}" (ID: {})'.format(
                current_stage.name, contract.description, contract.id
            )
        )

        opportunity_data = self.data_cleanup()
        opportunity_data['created_from_id'] = contract.id

        if contract.opportunity:
            label = 'updated'
            contract.opportunity.update(
                opportunity_data, current_user,
                self.documents, True
            )
            opportunity = contract.opportunity

        else:
            label = 'created'
            opportunity = Opportunity.create(
                opportunity_data, current_user,
                self.documents, True
            )
            db.session.add(opportunity)
            db.session.commit()

        action.action_detail = {
            'opportunity_id': opportunity.id, 'title': opportunity.title,
            'label': label
        }

        return action
コード例 #5
0
    def post_validate_action(self, action, contract, current_stage):
        '''Post the opportunity to Beacon

        Arguments:
            action: A
                :py:class:`~purchasing.data.contract_stages.ContractStageActionItem`
                that needs to be updated with details for the action
                log
            contract: A :py:class:`~purchasing.data.contracts.ContractBase` object
            current_stage: The current
                :py:class:`~purchasing.data.contract_stages.ContractStage`

        Returns:
            The modified
            :py:class:`~purchasing.data.contract_stages.ContractStageActionItem`
            with the action detail updated to include the form's data
        '''
        current_app.logger.info(
            'CONDUCTOR BEACON POST | Beacon posting on stage "{}" from contract "{}" (ID: {})'
            .format(current_stage.name, contract.description, contract.id))

        opportunity_data = self.data_cleanup()
        opportunity_data['created_from_id'] = contract.id

        if contract.opportunity:
            label = 'updated'
            contract.opportunity.update(opportunity_data, current_user,
                                        self.documents, True)
            opportunity = contract.opportunity

        else:
            label = 'created'
            opportunity = Opportunity.create(opportunity_data, current_user,
                                             self.documents, True)
            db.session.add(opportunity)
            db.session.commit()

        action.action_detail = {
            'opportunity_id': opportunity.id,
            'title': opportunity.title,
            'label': label
        }

        return action
コード例 #6
0
def handle_form(form, form_name, stage_id, user, contract, current_stage):
    if form.validate_on_submit():
        action = ContractStageActionItem(
            contract_stage_id=stage_id, action_type=form_name,
            taken_by=user.id, taken_at=datetime.datetime.utcnow()
        )
        if form_name == 'activity':
            current_app.logger.info(
                'CONDUCTOR NOTE | New note on stage "{}" from contract "{}" (ID: {})'.format(
                    current_stage.name, contract.description, contract.id
                )
            )

            action.action_detail = {
                'note': form.data.get('note', ''),
                'stage_name': current_stage.name
            }

        elif form_name == 'update':
            current_app.logger.info(
                'CONDUCTOR EMAIL UPDATE | New update on stage "{}" from contract "{}" (ID: {})'.format(
                    current_stage.name, contract.description, contract.id
                )
            )

            action.action_detail = {
                'sent_to': form.data.get('send_to', ''),
                'body': form.data.get('body'),
                'subject': form.data.get('subject'),
                'stage_name': current_stage.name,
                'attachments': get_attachment_filenames(form.attachments.entries)
            }

            Notification(
                to_email=[i.strip() for i in form.data.get('send_to').split(';') if i != ''],
                from_email=current_app.config['CONDUCTOR_SENDER'],
                reply_to=current_user.email,
                cc_email=[i.strip() for i in form.data.get('send_to_cc').split(';') if i != ''],
                subject=form.data.get('subject'),
                html_template='conductor/emails/email_update.html',
                body=form.data.get('body'),
                attachments=[i.upload.data for i in form.attachments.entries]
            ).send(multi=False)

        elif form_name == 'post':
            current_app.logger.info(
                'CONDUCTOR BEACON POST | Beacon posting on stage "{}" from contract "{}" (ID: {})'.format(
                    current_stage.name, contract.description, contract.id
                )
            )

            label = 'created'
            if contract.opportunity:
                label = 'updated'

            opportunity_data = form.data_cleanup()
            opportunity_data['created_from_id'] = contract.id
            opportunity = Opportunity.create(
                opportunity_data, current_user,
                form.documents, request.form.get('save_type') == 'publish'
            )
            db.session.add(opportunity)
            db.session.commit()

            action.action_detail = {
                'opportunity_id': opportunity.id, 'title': opportunity.title,
                'label': label
            }

        elif form_name == 'update-metadata':
            current_app.logger.info(
                'CONDUCTOR UPDATE METADATA | Contract update metadata on stage "{}" from contract "{}" (ID: {})'.format(
                    current_stage.name, contract.description, contract.id
                )
            )

            # remove the blank hidden field -- we don't need it
            data = form.data
            del data['all_blank']

            contract.update_with_spec_number(data)
            # this process pops off the spec number, so get it back
            data['spec_number'] = form.data.get('spec_number')

            # get department
            if form.data.get('department', None):
                data['department'] = form.data.get('department').name

            action.action_detail = data

        else:
            return False

        db.session.add(action)
        db.session.commit()
        return True

    return False