• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Python helpers.clean_instance函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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


示例16: notify_missed_progress_event_slack

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

    is_client_report = instance.type in [LEGACY_PROGRESS_EVENT_TYPE_CLIENT, LEGACY_PROGRESS_EVENT_TYPE_CLIENT_MID_SPRINT]

    if instance.task.archived or instance.status != "missed" or not instance.last_reminder_at:
        return

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

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

    task_url = '{}/work/{}'.format(TUNGA_URL, instance.task.id)
    slack_msg = "`Alert (!):` {} {} for \"{}\" | <{}|View on Tunga>".format(
        target_user and '{} missed a'.format(target_user.short_name) or 'Missed',
        is_client_report and 'weekly survey' or 'progress report',
        instance.task.summary,
        task_url
    )

    attachments = [
        {
            slack_utils.KEY_TITLE: instance.task.summary,
            slack_utils.KEY_TITLE_LINK: task_url,
            slack_utils.KEY_TEXT: '\n\n'.join(
                [
                    '*Due Date:* {}\n\n'
                    '*Name:* {}\n'
                    '*Email:* {}{}'.format(
                        instance.due_at.strftime("%d %b, %Y"),
                        user.display_name.encode('utf-8'),
                        user.email,
                        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
    instance.missed_notification_at = datetime.datetime.now()
    instance.save()
开发者ID:tunga-io,项目名称:tunga-api,代码行数:59,代码来源:slack.py


示例17: trigger_progress_report_actionable_events

def trigger_progress_report_actionable_events(instance):
    # Trigger actionable event notifications
    instance = clean_instance(instance, ProgressReport)
    is_pm_report = instance.event.type in [LEGACY_PROGRESS_EVENT_TYPE_PM, LEGACY_PROGRESS_EVENT_TYPE_MILESTONE_INTERNAL]
    is_client_report = instance.event.type in [LEGACY_PROGRESS_EVENT_TYPE_CLIENT, LEGACY_PROGRESS_EVENT_TYPE_CLIENT_MID_SPRINT]
    is_pm_or_client_report = is_pm_report or is_client_report
    is_dev_report = not is_pm_or_client_report

    task = instance.event.task
    has_pm = instance.event.task.pm

    # Deadline wasn't met
    if instance.last_deadline_met is not None and not instance.last_deadline_met:
        if is_pm_report or is_dev_report:
            notify_progress_report_deadline_missed_admin(instance)

            notify_progress_report_deadline_missed_client(instance)

            if has_pm:
                notify_progress_report_deadline_missed_pm(instance)

            if is_dev_report:
                notify_progress_report_deadline_missed_dev(instance)

    # More than 20% difference between time passed and accomplished
    if task.deadline:
        if is_dev_report and instance.started_at and task.deadline > instance.started_at:
            right_now = datetime.datetime.utcnow()
            spent_percentage = ((right_now - instance.started_at)/(task.deadline - right_now))*100
            if ((instance.percentage or 0) + 20) < spent_percentage:
                notify_progress_report_behind_schedule_by_algo_admin(instance)

                if has_pm:
                    notify_progress_report_behind_schedule_by_algo_pm(instance)

                notify_progress_report_behind_schedule_by_algo_dev(instance)

    # Client not satisfied with deliverable
    if instance.deliverable_satisfaction is not None and not instance.deliverable_satisfaction:
        if is_client_report:
            notify_progress_report_client_not_satisfied_admin(instance)

            notify_progress_report_client_not_satisfied_client(instance)

            if has_pm:
                notify_progress_report_client_not_satisfied_pm(instance)

            notify_progress_report_client_not_satisfied_dev(instance)

    # Stuck and/ or not progressing
    if instance.status in [LEGACY_PROGRESS_REPORT_STATUS_STUCK, LEGACY_PROGRESS_REPORT_STATUS_BEHIND_AND_STUCK]:
        if is_pm_report or is_dev_report:
            notify_progress_report_stuck_admin(instance)

            if has_pm:
                notify_progress_report_stuck_pm(instance)

            if is_dev_report:
                notify_progress_report_stuck_dev(instance)
开发者ID:tunga-io,项目名称:tunga-api,代码行数:59,代码来源:generic.py


示例18: distribute_multi_task_payment

def distribute_multi_task_payment(multi_task_key):
    multi_task_key = clean_instance(multi_task_key, MultiTaskPaymentKey)
    if not multi_task_key.paid:
        return

    # Distribute connected tasks
    for task in multi_task_key.tasks.all():
        distribute_task_payment_payoneer(task)
开发者ID:tunga-io,项目名称:tunga-api,代码行数:8,代码来源:tasks.py


示例19: sync_exact_invoices

def sync_exact_invoices(task, invoice_types=('client', 'tunga', 'developer'), developers=None):
    task = clean_instance(task, Task)
    invoice = task.invoice
    client = task.owner or task.user

    admin_emails = ['[email protected]', '[email protected]', '[email protected]']

    if 'client' in invoice_types and task.paid and client.type == USER_TYPE_PROJECT_OWNER \
            and client.email not in admin_emails:
        # Only sync paid invoices whose project owner is not a Tunga admin
        invoice_file_client = HTML(
            string=process_invoices(task.id, invoice_types=['client'], user_id=client.id, is_admin=False),
            encoding='utf-8'
        ).write_pdf()
        exact_utils.upload_invoice(
            task, client, 'client', invoice_file_client,
            float(invoice.amount.get('total_invoice_client', 0)),
            vat_location=invoice.vat_location_client
        )

    participation_shares = task.get_participation_shares()
    for share_info in participation_shares:
        participant = share_info['participant']
        dev = participant.user

        if participant.status != STATUS_ACCEPTED or share_info['share'] <= 0:
            continue

        if developers and dev.id not in developers:
            continue

        if ParticipantPayment.objects.filter(participant=participant):
            amount_details = invoice.get_amount_details(share=share_info['share'])

            if 'tunga' in invoice_types:
                invoice_file_tunga = HTML(
                    string=process_invoices(
                        task.id, invoice_types=['tunga'], user_id=dev.id, developer_ids=[dev.id], is_admin=False
                    ),
                    encoding='utf-8'
                ).write_pdf()
                exact_utils.upload_invoice(
                    task, dev, 'tunga', invoice_file_tunga,
                    float(amount_details.get('total_invoice_tunga', 0))
                )

            if 'developer' in invoice_types and invoice.version == 1:
                # Developer (tunga invoicing dev) invoices are only part of the old invoice scheme
                invoice_file_dev = HTML(
                    string=process_invoices(
                        task.id, invoice_types=['developer'], user_id=dev.id, developer_ids=[dev.id], is_admin=False
                    ),
                    encoding='utf-8'
                ).write_pdf()
                exact_utils.upload_invoice(
                    task, dev, 'developer', invoice_file_dev,
                    float(amount_details.get('total_invoice_developer', 0))
                )
开发者ID:tunga-io,项目名称:tunga-api,代码行数:58,代码来源:tasks.py


示例20: notify_estimate_status_email

def notify_estimate_status_email(instance, estimate_type='estimate', target_admins=False):
    instance = clean_instance(instance, estimate_type == 'quote' and Quote or Estimate)
    if instance.status == STATUS_INITIAL:
        return

    actor = None
    target = None
    action_verb = VERB_MAP_STATUS_CHANGE.get(instance.status, None)
    recipients = None

    if instance.status in [STATUS_SUBMITTED]:
        actor = instance.user
        recipients = TUNGA_STAFF_UPDATE_EMAIL_RECIPIENTS
    elif instance.status in [STATUS_APPROVED, STATUS_DECLINED]:
        actor = instance.moderated_by
        target = instance.user
        recipients = [instance.user.email]
    elif instance.status in [STATUS_ACCEPTED, STATUS_REJECTED]:
        actor = instance.reviewed_by
        if target_admins:
            recipients = TUNGA_STAFF_UPDATE_EMAIL_RECIPIENTS
        else:
            target = instance.user
            recipients = [instance.user.email]

            # Notify staff in a separate email
            notify_estimate_status_email.delay(instance.id, estimate_type=estimate_type, target_admins=True)

    subject = "{} {} {}".format(
        actor.first_name,
        action_verb,
        estimate_type == 'estimate' and 'an estimate' or 'a quote'
    )
    to = recipients

    ctx = {
        'owner': instance.user,
        'estimate': instance,
        'task': instance.task,
        'estimate_url': '{}/work/{}/{}/{}'.format(TUNGA_URL, instance.task.id, estimate_type, instance.id),
        'actor': actor,
        'target': target,
        'verb': action_verb,
        'noun': estimate_type
    }

    if send_mail(
            subject, 'tunga/email/estimate_status', to, ctx, **dict(deal_ids=[instance.task.hubspot_deal_id])
    ):
        if instance.status == STATUS_SUBMITTED:
            instance.moderator_email_at = datetime.datetime.utcnow()
            instance.save()
        if instance.status in [STATUS_ACCEPTED, STATUS_REJECTED]:
            instance.reviewed_email_at = datetime.datetime.utcnow()
            instance.save()

    if instance.status == STATUS_APPROVED:
        notify_estimate_approved_client_email(instance, estimate_type=estimate_type)
开发者ID:tunga-io,项目名称:tunga-api,代码行数:58,代码来源:email.py



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python turbogears.flash函数代码示例发布时间:2022-05-27
下一篇:
Python utils.upload_path函数代码示例发布时间:2022-05-27
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap