本文整理汇总了Python中site_config.models.SiteConfiguration类的典型用法代码示例。如果您正苦于以下问题:Python SiteConfiguration类的具体用法?Python SiteConfiguration怎么用?Python SiteConfiguration使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了SiteConfiguration类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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
示例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
示例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()
示例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()
示例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
示例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
示例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()
示例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
示例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))
示例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
示例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,
}
示例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)
示例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))
示例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%'))
)
示例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)