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

Python models.SiteConfiguration类代码示例

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

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



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

示例1: test_cleanup_expired_sms

 def test_cleanup_expired_sms(self, smsin):
     config = SiteConfiguration.get_solo()
     config.sms_expiration_date = None
     config.save()
     for sms in SmsInbound.objects.all():
         # move back in time so they can be deleted
         sms.time_received = sms.time_received - timedelta(days=5)
         sms.save()
     cleanup_expired_sms()
     assert SmsInbound.objects.count() == len(smsin)
     config = SiteConfiguration.get_solo()
     config.sms_expiration_date = timezone.localdate()
     config.save()
     cleanup_expired_sms()
     assert SmsInbound.objects.count() == 0
开发者ID:nikolay,项目名称:apostello,代码行数:15,代码来源:test_tasks.py


示例2: test_cleanup_expiry_date

 def test_cleanup_expiry_date(self):
     config = SiteConfiguration.get_solo()
     config.sms_expiration_date = None
     config.save()
     logs.check_incoming_log()
     logs.check_outgoing_log()
     num_sms = models.SmsInbound.objects.count() + models.SmsOutbound.objects.count()
     logs.cleanup_expired_sms()
     assert num_sms > 0
     assert models.SmsInbound.objects.count() + models.SmsOutbound.objects.count() == num_sms
     config = SiteConfiguration.get_solo()
     config.sms_expiration_date = today + timedelta(days=1)
     config.save()
     logs.cleanup_expired_sms()
     assert models.SmsInbound.objects.count() + models.SmsOutbound.objects.count() == 0
开发者ID:nikolay,项目名称:apostello,代码行数:15,代码来源:test_logs.py


示例3: fetch_elvanto_groups

def fetch_elvanto_groups(force=False):
    """Fetch all Elvanto groups."""
    from site_config.models import SiteConfiguration
    config = SiteConfiguration.get_solo()
    if force or config.sync_elvanto:
        from elvanto.models import ElvantoGroup
        ElvantoGroup.fetch_all_groups()
开发者ID:nikolay,项目名称:apostello,代码行数:7,代码来源:tasks.py


示例4: calculate_cost

 def calculate_cost(self):
     """Calculate the cost of sending to this group."""
     try:
         cost = SiteConfiguration.get_twilio_settings()['sending_cost']
     except ConfigurationError:
         cost = 0
     return cost * self.all_recipients.count()
开发者ID:nikolay,项目名称:apostello,代码行数:7,代码来源:models.py


示例5: get_person_or_ask_for_name

def get_person_or_ask_for_name(from_, sms_body, keyword_obj):
    """
    Return the Recipient object for the sender of the message.

    Perform a look up on the sender of the message.
    If they exist in the system, they are returned.
    Otherwise a message is queued to ask them for their name.
    """
    try:
        person_from = Recipient.objects.get(number=from_)
    except Recipient.DoesNotExist:
        person_from = Recipient.objects.create(
            number=from_,
            first_name='Unknown',
            last_name='Person'
        )
        person_from.save()
        if keyword_obj == "name":
            pass
        else:
            from site_config.models import SiteConfiguration
            config = SiteConfiguration.get_solo()
            if not config.disable_all_replies:
                person_from.send_message(
                    content=fetch_default_reply('auto_name_request'),
                    sent_by="auto name request"
                )
                notify_office_mail.delay(
                    '[Apostello] Unknown Contact!',
                    'SMS: {0}\nFrom: {1}\n\n\nThis person is unknown and has been asked for their name.'.format(
                        sms_body, from_
                    ),
                )

    return person_from
开发者ID:gitter-badger,项目名称:apostello,代码行数:35,代码来源:reply.py


示例6: test_import_outgoing_rolling

 def test_import_outgoing_rolling(self):
     config = SiteConfiguration.get_solo()
     config.sms_expiration_date = None
     config.sms_rolling_expiration_days = 0
     config.save()
     logs.check_outgoing_log()
     assert models.SmsOutbound.objects.filter(time_sent__lt=today).count() == 0
开发者ID:nikolay,项目名称:apostello,代码行数:7,代码来源:test_logs.py


示例7: pull_elvanto_groups

def pull_elvanto_groups(force=False):
    """Pull all the Elvanto groups that are set to sync."""
    from site_config.models import SiteConfiguration
    config = SiteConfiguration.get_solo()
    if force or config.sync_elvanto:
        from elvanto.models import ElvantoGroup
        ElvantoGroup.pull_all_groups()
开发者ID:nikolay,项目名称:apostello,代码行数:7,代码来源:tasks.py


示例8: test_cleanup

 def test_cleanup(self):
     # setup
     config = SiteConfiguration.get_solo()
     config.sms_rolling_expiration_days = None
     config.sms_expiration_date = today - timedelta(days=100)
     config.save()
     sms = models.SmsInbound.objects.create(
         content='test message',
         time_received=timezone.now() - timedelta(50),
         sender_name="John Calvin",
         sender_num="+447927401749",
         matched_keyword="test",
         sid='12345'
     )
     sms.save()
     assert models.SmsInbound.objects.count() == 1  # we have one sms
     logs.cleanup_expired_sms()
     assert models.SmsInbound.objects.count() == 1  # cleanup should leave it untouched
     config.sms_rolling_expiration_days = 50
     config.save()
     logs.cleanup_expired_sms()
     assert models.SmsInbound.objects.count() == 1  # cleanup should leave it untouched
     config.sms_rolling_expiration_days = 49
     config.save()
     logs.cleanup_expired_sms()
     assert models.SmsInbound.objects.count() == 0  # cleanup should remove sms
开发者ID:nikolay,项目名称:apostello,代码行数:26,代码来源:test_logs.py


示例9: elm_settings

def elm_settings(user):
    try:
        profile = user.profile
    except AttributeError:
        profile = UserProfile.nullProfile()

    config = SiteConfiguration.get_solo()
    try:
        twilio_settings = config.get_twilio_settings()
        # remove sensitive settings:
        del twilio_settings['auth_token']
        del twilio_settings['sid']
    except ConfigurationError:
        twilio_settings = None

    bk_key = f'blocked_keywords_user_{user.pk}'
    blocked_keywords = cache.get(bk_key)
    if blocked_keywords is None:
        blocked_keywords = [
            x.keyword for x in Keyword.objects.all().prefetch_related('owners') if not x.can_user_access(user)
        ]
        cache.set(bk_key, blocked_keywords, 120)

    elm = {
        'userPerms': UserProfileSerializer(profile).data,
        'twilio': twilio_settings,
        'isEmailSetup': config.is_email_setup(),
        'smsCharLimit': config.sms_char_limit,
        'defaultNumberPrefix': config.default_number_prefix,
        'noAccessMessage': config.not_approved_msg,
        'blockedKeywords': blocked_keywords,
    }
    return mark_safe(json.dumps(elm))
开发者ID:nikolay,项目名称:apostello,代码行数:33,代码来源:apostello_extras.py


示例10: recipient_send_message_task

def recipient_send_message_task(recipient_pk, body, group, sent_by):
    """Send a message asynchronously."""
    from apostello.models import Recipient
    from site_config.models import SiteConfiguration
    recipient = Recipient.objects.get(pk=recipient_pk)
    if recipient.is_archived:
        # if recipient is not active, fail silently
        return

    from apostello.models import SmsOutbound, RecipientGroup
    # if %name% is present, replace:
    body = recipient.personalise(body)
    # send twilio message
    try:
        message = get_twilio_client().messages.create(
            body=body, to=str(recipient.number), from_=str(SiteConfiguration.get_solo().twilio_from_num)
        )
        # add to sms out table
        sms = SmsOutbound(sid=message.sid, content=body, time_sent=timezone.now(), recipient=recipient, sent_by=sent_by)
        if group is not None:
            sms.recipient_group = RecipientGroup.objects.filter(name=group)[0]
        sms.save()
    except TwilioRestException as e:
        if e.code == 21610:
            recipient.is_blocking = True
            recipient.save()
            async('apostello.tasks.blacklist_notify', recipient.pk, '', 'stop')
        else:
            raise e
开发者ID:nikolay,项目名称:apostello,代码行数:29,代码来源:tasks.py


示例11: global_settings

def global_settings(request):
    """Expose TWILIO_FROM_NUM, DEBUG and site config in templates."""
    return {
        'CONFIG': SiteConfiguration.get_solo(),
        'DISPLAY_GOOGLE_LOGIN': SocialApp.objects.filter(provider='google').count(),
        'ROLLBAR_ACCESS_TOKEN_CLIENT': settings.ROLLBAR_ACCESS_TOKEN_CLIENT,
    }
开发者ID:nikolay,项目名称:apostello,代码行数:7,代码来源:context_processors.py


示例12: send_async_mail

def send_async_mail(subject, body, to):
    """Send email."""
    # read email settings from DB
    from site_config.models import SiteConfiguration
    s = SiteConfiguration.get_solo()
    from_ = s.email_from
    send_mail(subject, body, from_, to)
开发者ID:nikolay,项目名称:apostello,代码行数:7,代码来源:tasks.py


示例13: check_user_cost_limit

 def check_user_cost_limit(recipients, limit, msg):
     """Check the user has not exceeded their per SMS cost limit."""
     cost = SiteConfiguration.get_twilio_settings()['sending_cost']
     num_sms = ceil(len(msg) / 160)
     if limit == 0:
         return
     if limit < len(recipients) * cost * num_sms:
         raise ValidationError('Sorry, you can only send messages that cost no more than ${0}.'.format(limit))
开发者ID:nikolay,项目名称:apostello,代码行数:8,代码来源:models.py


示例14: test_no_name_raises

 def test_no_name_raises(self):
     """Test shorter limit imposed with %name% present."""
     s = SiteConfiguration.get_solo()
     with pytest.raises(ValidationError):
         less_than_sms_char_limit(
             't %name%' *
             (s.sms_char_limit - settings.MAX_NAME_LENGTH + len('%name%'))
         )
开发者ID:monty5811,项目名称:apostello,代码行数:8,代码来源:test_validators.py


示例15: send_async_mail

def send_async_mail(subject, body, to):
    """Send email."""
    # read email settings from DB, if they are empty, they will be read from
    # settings.py instead
    from site_config.models import SiteConfiguration
    s = SiteConfiguration.get_solo()
    from_ = s.email_from or settings.EMAIL_FROM
    send_mail(subject, body, from_, to)
开发者ID:mrphishxxx,项目名称:apostello,代码行数:8,代码来源:tasks.py


示例16: __init__

 def __init__(self, *args, **kwargs):
     super(ApostelloEmailBackend, self).__init__(*args, **kwargs)
     from site_config.models import SiteConfiguration
     s = SiteConfiguration.get_solo()
     self.host = s.email_host
     self.port = s.email_port
     self.username = s.email_username
     self.password = s.email_password
开发者ID:nikolay,项目名称:apostello,代码行数:8,代码来源:mail.py


示例17: post_to_slack

def post_to_slack(attachments):
    """Post message to slack webhook."""
    from site_config.models import SiteConfiguration
    config = SiteConfiguration.get_solo()
    url = config.slack_url
    if url:
        data = {'username': 'apostello', 'icon_emoji': ':speech_balloon:', 'attachments': attachments}
        headers = {'Content-type': 'application/json', 'Accept': 'text/plain'}
        requests.post(url, data=json.dumps(data), headers=headers)
开发者ID:nikolay,项目名称:apostello,代码行数:9,代码来源:tasks.py


示例18: global_settings

def global_settings(request):
    """Expose TWILIO_FROM_NUM, DEBUG and site config in templates."""
    return {
        'TWILIO_FROM_NUM': settings.TWILIO_FROM_NUM,
        'TWILIO_SENDING_COST': settings.TWILIO_SENDING_COST,
        'DEBUG': settings.DEBUG,
        'CONFIG': SiteConfiguration.get_solo(),
        'DISPLAY_GOOGLE_LOGIN':
        SocialApp.objects.filter(provider='google').count(),
    }
开发者ID:icodebuster,项目名称:apostello,代码行数:10,代码来源:context_processors.py


示例19: add_new_contact_to_groups

def add_new_contact_to_groups(contact_pk):
    """Add contact to any groups that are in "auto populate with new contacts."""
    logger.info('Adding new person to designated groups')
    from apostello.models import Recipient
    from site_config.models import SiteConfiguration
    contact = Recipient.objects.get(pk=contact_pk)
    for grp in SiteConfiguration.get_solo().auto_add_new_groups.all():
        logger.info('Adding %s to %s', contact.full_name, grp.name)
        contact.groups.add(grp)
        contact.save()
        logger.info('Added %s to %s', contact.full_name, grp.name)
开发者ID:nikolay,项目名称:apostello,代码行数:11,代码来源:tasks.py


示例20: less_than_sms_char_limit

def less_than_sms_char_limit(value):
    """Ensure message is less than the maximum character limit."""
    from site_config.models import SiteConfiguration
    s = SiteConfiguration.get_solo()
    sms_char_lim = s.sms_char_limit - settings.MAX_NAME_LENGTH + len('%name%')
    if len(value) > sms_char_lim:
        raise ValidationError(
            'You have exceeded the maximum char limit of {0}.'.format(
                sms_char_lim
            )
        )
开发者ID:mrphishxxx,项目名称:apostello,代码行数:11,代码来源:validators.py



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

专题导读
上一篇:
Python site_helper.getDBHelper函数代码示例发布时间:2022-05-27
下一篇:
Python siteUtils.getUnitId函数代码示例发布时间: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