当前位置: 首页>>代码示例>>Python>>正文


Python helpers.clean_instance函数代码示例

本文整理汇总了Python中tunga_utils.helpers.clean_instance函数的典型用法代码示例。如果您正苦于以下问题:Python clean_instance函数的具体用法?Python clean_instance怎么用?Python clean_instance使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了clean_instance函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: notify_paid_invoice_slack_admin

def notify_paid_invoice_slack_admin(invoice):
    invoice = clean_instance(invoice, Invoice)

    if invoice.legacy_id or not invoice.paid:
        # ignore legacy invoices
        return

    project_url = '{}/projects/{}/'.format(TUNGA_URL, invoice.project.id)
    person_url = '{}/network/{}/'.format(TUNGA_URL, invoice.user.username)
    invoice_url = '{}/api/invoices/{}/download/?format=pdf'.format(TUNGA_URL, invoice.id)

    slack_msg = ':tada: A {} of *EUR {}* has been {} *<{}|{}>* for <{}|{}> | <{}|Download Invoice>'.format(
        invoice.type == INVOICE_TYPE_SALE and 'payment' or 'payout',
        invoice.amount,
        invoice.type == INVOICE_TYPE_SALE and 'made by' or 'sent to',
        person_url,
        invoice.user.display_name.encode('utf-8'),
        project_url,
        invoice.full_title,
        invoice_url
    )

    slack_utils.send_incoming_webhook(
        SLACK_STAFF_INCOMING_WEBHOOK,
        {
            slack_utils.KEY_TEXT: slack_msg,
            slack_utils.KEY_CHANNEL: SLACK_STAFF_PAYMENTS_CHANNEL
        }
    )
开发者ID:tunga-io,项目名称:tunga-api,代码行数:29,代码来源:slack.py

示例2: notify_new_task_admin_email

def notify_new_task_admin_email(instance, new_user=False, completed=False, call_scheduled=False):
    instance = clean_instance(instance, Task)

    completed_phrase_subject = ''
    completed_phrase_body = ''
    if call_scheduled:
        completed_phrase_subject = 'availability window shared'
        completed_phrase_body = 'shared an availability window'
    elif completed:
        completed_phrase_subject = 'details completed'
        completed_phrase_body = 'completed the details'

    subject = "New{} {} {} by {}{}".format(
        (completed or call_scheduled) and ' wizard' or '',
        instance.scope == TASK_SCOPE_TASK and 'task' or 'project',
        completed_phrase_subject or 'created',
        instance.user.first_name, new_user and ' (New user)' or ''
    )

    to = TUNGA_STAFF_LOW_LEVEL_UPDATE_EMAIL_RECIPIENTS  # Notified via Slack so limit receiving admins

    ctx = {
        'owner': instance.owner or instance.user,
        'task': instance,
        'task_url': '{}/task/{}/'.format(TUNGA_URL, instance.id),
        'completed_phrase': completed_phrase_body,
    }
    send_mail(subject, 'tunga/email/new_task', to, ctx, **dict(deal_ids=[instance.hubspot_deal_id]))
开发者ID:tunga-io,项目名称:tunga-api,代码行数:28,代码来源:email.py

示例3: notify_new_task_community_email

def notify_new_task_community_email(instance):
    instance = clean_instance(instance, Task)

    # Notify Devs or PMs
    community_receivers = None
    if instance.is_developer_ready:
        # Notify developers
        if instance.approved and instance.visibility in [VISIBILITY_DEVELOPER, VISIBILITY_MY_TEAM]:
            community_receivers = get_suggested_community_receivers(instance, user_type=USER_TYPE_DEVELOPER)
    elif instance.is_project and not instance.pm:
        community_receivers = get_suggested_community_receivers(instance, user_type=USER_TYPE_PROJECT_MANAGER)

    if instance.is_project and instance.pm:
        community_receivers = [instance.pm]

    subject = "New {} created by {}".format(
        instance.scope == TASK_SCOPE_TASK and 'task' or 'project',
        instance.user.first_name
    )

    if community_receivers:
        to = [community_receivers[0].email]
        bcc = None
        if len(community_receivers) > 1:
            bcc = [user.email for user in community_receivers[1:]] if community_receivers[1:] else None
        ctx = {
            'owner': instance.owner or instance.user,
            'task': instance,
            'task_url': '{}/work/{}/'.format(TUNGA_URL, instance.id)
        }
        send_mail(subject, 'tunga/email/new_task', to, ctx, bcc=bcc, **dict(deal_ids=[instance.hubspot_deal_id]))
开发者ID:tunga-io,项目名称:tunga-api,代码行数:31,代码来源:email.py

示例4: trigger_schedule_call_automation

def trigger_schedule_call_automation(user):
    user = clean_instance(user, get_user_model())
    mailchimp_utils.add_email_to_automation_queue(
        email_address=user.email,
        workflow_id=MAILCHIMP_NEW_USER_AUTOMATION_WORKFLOW_ID,
        email_id=MAILCHIMP_NEW_USER_AUTOMATION_EMAIL_ID
    )
开发者ID:tunga-io,项目名称:tunga-api,代码行数:7,代码来源:tasks.py

示例5: notify_payment_link_client_email

def notify_payment_link_client_email(instance):
    instance = clean_instance(instance, Task)

    to = [instance.user.email]
    if instance.owner and instance.owner.email != instance.user.email:
        to.append(instance.owner.email)

    task_url = '{}/task/{}/'.format(TUNGA_URL, instance.id)
    payment_link = '{}pay/'.format(task_url)

    owner = instance.owner or instance.user

    merge_vars = [
        mandrill_utils.create_merge_var(MANDRILL_VAR_FIRST_NAME, owner.first_name),
        mandrill_utils.create_merge_var('payment_title', instance.summary),
        mandrill_utils.create_merge_var('payment_link', payment_link),
    ]

    mandrill_response = mandrill_utils.send_email('70-payment-link-ready', to, merge_vars=merge_vars)
    if mandrill_response:
        instance.payment_link_sent = True
        instance.payment_link_sent_at = datetime.datetime.utcnow()
        instance.save()

        mandrill_utils.log_emails.delay(mandrill_response, to, deal_ids=[instance.hubspot_deal_id])
开发者ID:tunga-io,项目名称:tunga-api,代码行数:25,代码来源:email.py

示例6: notify_parties_of_low_rating_email

def notify_parties_of_low_rating_email(instance):
    instance = clean_instance(instance, ProgressReport)
    is_client_report = instance.event.type in [LEGACY_PROGRESS_EVENT_TYPE_CLIENT, LEGACY_PROGRESS_EVENT_TYPE_CLIENT_MID_SPRINT]

    if is_client_report:
        subject = "Work Rating For {}".format(instance.event.task.summary)
        ctx = {
            'owner': instance.event.task.owner or instance.event.task.user,
            'event': instance,
            'update_url': '{}/work/{}/event/{}/'.format(TUNGA_URL, instance.event.task.id, instance.event.id)
        }
        # send to client
        if instance.task.owner:
            to = [instance.event.task.owner.email]
            email_template = 'low_rating_client'
            send_mail(
                subject, 'tunga/email/{}'.format(email_template), to, ctx,
                **dict(deal_ids=[instance.event.task.hubspot_deal_id])
            )
        # send to pm
        if instance.event.task.pm:
            to = [instance.event.task.pm.email]
            email_template = 'low_rating_pm'
            send_mail(
                subject, 'tunga/email/{}'.format(email_template), to, ctx,
                **dict(deal_ids=[instance.event.task.hubspot_deal_id])
            )
        # send to user
        if instance.event.task.user:
            to = [instance.event.task.user.email]
            email_template = 'low_rating_user'
            send_mail(
                subject, 'tunga/email/{}'.format(email_template), to, ctx,
                **dict(deal_ids=[instance.event.task.hubspot_deal_id])
            )
开发者ID:tunga-io,项目名称:tunga-api,代码行数:35,代码来源:email.py

示例7: notify_missed_progress_event_slack

def notify_missed_progress_event_slack(progress_event):
    progress_event = clean_instance(progress_event, ProgressEvent)

    if progress_event.project.archived or progress_event.status != "missed" or not progress_event.last_reminder_at or progress_event.missed_notification_at:
        return

    participants = progress_event.participants
    if not participants:
        # No one to report or project is now closed
        return

    target_user = None
    if participants and len(participants) == 1:
        target_user = participants[0]

    project_url = '{}/projects/{}'.format(TUNGA_URL, progress_event.project.id)
    slack_msg = "`Alert (!):` {} {} for \"{}\" | <{}|View on Tunga>".format(
        target_user and '{} missed a'.format(target_user.short_name) or 'Missed',
        (progress_event.type == PROGRESS_EVENT_CLIENT and 'progress survey') or
        (progress_event.type == PROGRESS_EVENT_MILESTONE and 'milestone report') or
        'progress report',
        progress_event.project.title,
        project_url
    )

    attachments = [
        {
            slack_utils.KEY_TITLE: progress_event.project.title,
            slack_utils.KEY_TITLE_LINK: project_url,
            slack_utils.KEY_TEXT: '*Due Date:* {}\n\n{}'.format(
                progress_event.due_at.strftime("%d %b, %Y"),
                '\n\n'.join(
                    [
                        '*Name:* {}\n'
                        '*Email:* {}{}'.format(
                            user.display_name.encode('utf-8'),
                            user.email,
                            not user.is_project_owner and user.profile and user.profile.phone_number and
                            '\n*Phone Number:* {}'.format(user.profile.phone_number) or '')
                        for user in participants
                    ]
                )
            ),
            slack_utils.KEY_MRKDWN_IN: [slack_utils.KEY_TEXT],
            slack_utils.KEY_COLOR: SLACK_ATTACHMENT_COLOR_TUNGA
        }
    ]

    slack_utils.send_incoming_webhook(
        SLACK_STAFF_INCOMING_WEBHOOK,
        {
            slack_utils.KEY_TEXT: slack_msg,
            slack_utils.KEY_ATTACHMENTS: attachments,
            slack_utils.KEY_CHANNEL: SLACK_STAFF_MISSED_UPDATES_CHANNEL
        }
    )

    # Save notification time
    progress_event.missed_notification_at = datetime.datetime.now()
    progress_event.save()
开发者ID:tunga-io,项目名称:tunga-api,代码行数:60,代码来源:slack.py

示例8: notify_estimate_approved_client_email

def notify_estimate_approved_client_email(instance, estimate_type='estimate'):
    instance = clean_instance(instance, estimate_type == 'quote' and Quote or Estimate)
    if instance.status != STATUS_APPROVED:
        return
    subject = "{} submitted {}".format(
        instance.user.first_name,
        estimate_type == 'estimate' and 'an estimate' or 'a quote'
    )
    to = [instance.task.user.email]
    if instance.task.owner:
        to.append(instance.task.owner.email)
    ctx = {
        'owner': instance.user,
        'estimate': instance,
        'task': instance.task,
        'estimate_url': '{}/work/{}/{}/{}'.format(TUNGA_URL, instance.task.id, estimate_type, instance.id),
        'actor': instance.user,
        'target': instance.task.owner or instance.task.user,
        'verb': 'submitted',
        'noun': estimate_type
    }

    if instance.task.source == TASK_SOURCE_NEW_USER and not instance.task.user.is_confirmed:
        url_prefix = '{}/reset-password/confirm/{}/{}?new_user=true&next='.format(
            TUNGA_URL, instance.user.uid, instance.user.generate_reset_token()
        )
        ctx['estimate_url'] = '{}{}'.format(url_prefix, ctx['estimate_url'])

    if send_mail(
            subject, 'tunga/email/estimate_status', to, ctx, **dict(deal_ids=[instance.task.hubspot_deal_id])
    ):
        instance.reviewer_email_at = datetime.datetime.utcnow()
        instance.save()
开发者ID:tunga-io,项目名称:tunga-api,代码行数:33,代码来源:email.py

示例9: notify_paid_invoice_email_dev

def notify_paid_invoice_email_dev(invoice):
    invoice = clean_instance(invoice, Invoice)

    if invoice.legacy_id or invoice.type != INVOICE_TYPE_PURCHASE or not invoice.paid:
        # ignore legacy invoices and only notify about developer invoices
        return

    to = [invoice.user.email]

    merge_vars = [
        mandrill_utils.create_merge_var(MANDRILL_VAR_FIRST_NAME, invoice.user.first_name),
        mandrill_utils.create_merge_var('payout_title', invoice.full_title),
    ]

    pdf_file_contents = base64.b64encode(invoice.pdf)

    attachments = [
        dict(
            content=pdf_file_contents,
            name='Invoice - {}.pdf'.format(invoice.full_title),
            type='application/pdf'
        )
    ]

    mandrill_utils.send_email('87-payout-made', to, merge_vars=merge_vars, attachments=attachments)
开发者ID:tunga-io,项目名称:tunga-api,代码行数:25,代码来源:email.py

示例10: notify_progress_report_deadline_missed_slack_admin

def notify_progress_report_deadline_missed_slack_admin(instance):
    instance = clean_instance(instance, ProgressReport)

    task_url = '{}/work/{}'.format(TUNGA_URL, instance.event.task.id)
    slack_msg = "`Alert (!):` Follow up on missed deadline for \"{}\" | <{}|View on Tunga>".format(
        instance.event.task.summary,
        task_url
    )

    attachments = [
        {
            slack_utils.KEY_TITLE: instance.event.task.summary,
            slack_utils.KEY_TITLE_LINK: task_url,
            slack_utils.KEY_TEXT: 'A deadline has been missed on the "{}" {}\n'
                                  '*Was the client informed before hand?:* {}\n'
                                  'Please contact the stakeholders.'.format(
                instance.event.task.summary,
                instance.event.task.is_task and 'task' or 'project',
                instance.deadline_miss_communicated and 'Yes' or 'No'
            ),
            slack_utils.KEY_MRKDWN_IN: [slack_utils.KEY_TEXT],
            slack_utils.KEY_COLOR: SLACK_ATTACHMENT_COLOR_TUNGA
        },
        create_task_stakeholders_attachment_slack(instance.event.task, show_title=False)
    ]

    slack_utils.send_incoming_webhook(
        SLACK_STAFF_INCOMING_WEBHOOK,
        {
            slack_utils.KEY_TEXT: slack_msg,
            slack_utils.KEY_ATTACHMENTS: attachments,
            slack_utils.KEY_CHANNEL: SLACK_STAFF_UPDATES_CHANNEL
        }
    )
开发者ID:tunga-io,项目名称:tunga-api,代码行数:34,代码来源:slack.py

示例11: notify_progress_report_client_not_satisfied_slack_admin

def notify_progress_report_client_not_satisfied_slack_admin(instance):
    instance = clean_instance(instance, ProgressReport)

    task_url = '{}/work/{}/event/{}'.format(TUNGA_URL, instance.event.task.id, instance.event.id)
    slack_msg = "`Alert (!):` Client dissatisfied | <{}|View on Tunga>".format(task_url)

    attachments = [
        {
            slack_utils.KEY_TITLE: instance.event.task.summary,
            slack_utils.KEY_TITLE_LINK: task_url,
            slack_utils.KEY_TEXT: 'The project owner of \"{}\" {} is unsatisfied with the deliverable.\n '
                                  'Please contact all stakeholders.'.format(
                instance.event.task.summary,
                instance.event.task.is_task and 'task' or 'project'
            ),
            slack_utils.KEY_MRKDWN_IN: [slack_utils.KEY_TEXT],
            slack_utils.KEY_COLOR: SLACK_ATTACHMENT_COLOR_TUNGA
        },
        create_task_stakeholders_attachment_slack(instance.event.task, show_title=False)
    ]

    slack_utils.send_incoming_webhook(
        SLACK_STAFF_INCOMING_WEBHOOK,
        {
            slack_utils.KEY_TEXT: slack_msg,
            slack_utils.KEY_ATTACHMENTS: attachments,
            slack_utils.KEY_CHANNEL: SLACK_STAFF_UPDATES_CHANNEL
        }
    )
开发者ID:tunga-io,项目名称:tunga-api,代码行数:29,代码来源:slack.py

示例12: notify_progress_report_stuck_slack_admin

def notify_progress_report_stuck_slack_admin(instance):
    instance = clean_instance(instance, ProgressReport)

    task_url = '{}/work/{}/event/{}'.format(TUNGA_URL, instance.event.task.id, instance.event.id)
    slack_msg = "`Alert (!):` The status for the \"{}\" {} has been classified as stuck | <{}|View on Tunga>".format(
        instance.event.task.summary,
        instance.event.task.is_task and 'task' or 'project',
        task_url
    )

    attachments = [
        {
            slack_utils.KEY_TITLE: instance.event.task.summary,
            slack_utils.KEY_TITLE_LINK: task_url,
            slack_utils.KEY_TEXT: 'Please contact all stakeholders.',
            slack_utils.KEY_MRKDWN_IN: [slack_utils.KEY_TEXT],
            slack_utils.KEY_COLOR: SLACK_ATTACHMENT_COLOR_TUNGA
        },
        create_task_stakeholders_attachment_slack(instance.event.task, show_title=False)
    ]

    slack_utils.send_incoming_webhook(
        SLACK_STAFF_INCOMING_WEBHOOK,
        {
            slack_utils.KEY_TEXT: slack_msg,
            slack_utils.KEY_ATTACHMENTS: attachments,
            slack_utils.KEY_CHANNEL: SLACK_STAFF_UPDATES_CHANNEL
        }
    )
开发者ID:tunga-io,项目名称:tunga-api,代码行数:29,代码来源:slack.py

示例13: notify_progress_report_wont_meet_deadline_slack_admin

def notify_progress_report_wont_meet_deadline_slack_admin(instance):
    instance = clean_instance(instance, ProgressReport)

    task_url = '{}/work/{}/event/{}'.format(TUNGA_URL, instance.event.task.id, instance.event.id)
    slack_msg = "`Alert (!):` {} doesn't expect to meet the deadline | <{}|View on Tunga>".format(
        instance.event.type in [LEGACY_PROGRESS_EVENT_TYPE_PM, LEGACY_PROGRESS_EVENT_TYPE_MILESTONE_INTERNAL] and 'PM' or 'Developer',
        task_url
    )

    attachments = [
        {
            slack_utils.KEY_TITLE: instance.event.task.summary,
            slack_utils.KEY_TITLE_LINK: task_url,
            slack_utils.KEY_TEXT: 'The {} on the \"{}\" {} has indicated that they might not meet the coming deadline.\n'
                                  'Please contact all stakeholders.'.format(
                instance.event.type in [LEGACY_PROGRESS_EVENT_TYPE_PM,
                                        LEGACY_PROGRESS_EVENT_TYPE_MILESTONE_INTERNAL] and 'PM' or 'Developer',
                instance.event.task.summary,
                instance.event.task.is_task and 'task' or 'project'
            ),
            slack_utils.KEY_MRKDWN_IN: [slack_utils.KEY_TEXT],
            slack_utils.KEY_COLOR: SLACK_ATTACHMENT_COLOR_TUNGA
        },
        create_task_stakeholders_attachment_slack(instance.event.task, show_title=False)
    ]

    slack_utils.send_incoming_webhook(
        SLACK_STAFF_INCOMING_WEBHOOK,
        {
            slack_utils.KEY_TEXT: slack_msg,
            slack_utils.KEY_ATTACHMENTS: attachments,
            slack_utils.KEY_CHANNEL: SLACK_STAFF_UPDATES_CHANNEL
        }
    )
开发者ID:tunga-io,项目名称:tunga-api,代码行数:34,代码来源:slack.py

示例14: notify_interest_poll_email

def notify_interest_poll_email(interest_poll, reminder=False):
    interest_poll = clean_instance(interest_poll, InterestPoll)

    to = [interest_poll.user.email]

    poll_url = '{}/poll/{}/{}'.format(TUNGA_URL, interest_poll.id, interest_poll.token)

    merge_vars = [
        mandrill_utils.create_merge_var(MANDRILL_VAR_FIRST_NAME, interest_poll.user.first_name),
        mandrill_utils.create_merge_var('opportunity_title', interest_poll.project.title),
        mandrill_utils.create_merge_var('skills', str(interest_poll.project.skills)),
        mandrill_utils.create_merge_var('description', interest_poll.project.description),
        mandrill_utils.create_merge_var('scope', interest_poll.project.get_expected_duration_display()),
        mandrill_utils.create_merge_var('yes_url', '{}?status=interested'.format(poll_url)),
        mandrill_utils.create_merge_var('no_url', '{}?status=uninterested'.format(poll_url)),
    ]

    mandrill_response = mandrill_utils.send_email(
        reminder and '90-availability-for-project-reminder' or '89-availability-for-project',
        to, merge_vars=merge_vars
    )
    if mandrill_response:
        if reminder:
            interest_poll.reminded_at = datetime.datetime.utcnow()
        else:
            interest_poll.sent_at = datetime.datetime.utcnow()
        interest_poll.save()

        mandrill_utils.log_emails.delay(mandrill_response, to)
开发者ID:tunga-io,项目名称:tunga-api,代码行数:29,代码来源:email.py

示例15: notify_progress_report_wont_meet_deadline_email_pm

def notify_progress_report_wont_meet_deadline_email_pm(instance):
    instance = clean_instance(instance, ProgressReport)

    subject = "`Alert (!):` {} doesn't expect to meet the deadline".format(
        instance.event.type in [LEGACY_PROGRESS_EVENT_TYPE_PM, LEGACY_PROGRESS_EVENT_TYPE_MILESTONE_INTERNAL] and 'PM' or 'Developer'
    )

    pm = instance.event.task.pm
    if not pm:
        return

    to = [pm.email]

    ctx = {
        'owner': instance.event.task.owner or instance.event.task.user,
        'reporter': instance.user,
        'pm': pm,
        'event': instance.event,
        'report': instance,
        'update_url': '{}/work/{}/event/{}/'.format(TUNGA_URL, instance.event.task.id, instance.event.id)
    }

    send_mail(
        subject, 'tunga/email/wont_meet_deadline_pm', to, ctx,
        **dict(deal_ids=[instance.event.task.hubspot_deal_id])
    )
开发者ID:tunga-io,项目名称:tunga-api,代码行数:26,代码来源:email.py


注:本文中的tunga_utils.helpers.clean_instance函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。