Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test_comment_max_len_invalid(self):
"""
Restrict comment len
"""
comment = 'a' * (settings.ST_COMMENT_MAX_LEN + 1)
form_data = {'comment': comment, }
form = CommentForm(data=form_data)
self.assertEqual(form.is_valid(), False)
def user_model_content_type(apps, schema_editor):
from ...core.conf import settings
if not hasattr(settings, 'AUTH_USER_MODEL'):
return
user = apps.get_model(settings.AUTH_USER_MODEL)
if user._meta.db_table == 'spirit_user_user':
app_label, model = settings.AUTH_USER_MODEL.split('.')
content_types = apps.get_model('contenttypes.ContentType')
(content_types.objects
.filter(
app_label='spirit_user',
model='User'.lower())
.update(
app_label=app_label,
model=model.lower()))
def cx_text_input(*args, **kwargs):
if settings.ST_CASE_INSENSITIVE_USERNAMES:
return CITextInput(*args, **kwargs)
return forms.TextInput(*args, **kwargs)
'site_name': site.name,
'domain': site.domain,
'protocol': 'https' if request.is_secure() else 'http'
})
message = render_to_string(template_name, context)
# todo: remove in Spirit 0.5 (use DEFAULT_FROM_EMAIL)
from_email = "{site_name} <{name}@{domain}>".format(
name="noreply",
domain=site.domain,
site_name=site.name
)
# todo: remove
if settings.DEFAULT_FROM_EMAIL != 'webmaster@localhost':
from_email = settings.DEFAULT_FROM_EMAIL
for recipient in to:
try:
send_mail(
subject=subject,
message=message,
from_email=from_email,
recipient_list=[recipient]
)
except OSError as err:
logger.exception(err)
def validate_cache_config():
try:
cache = settings.CACHES[settings.ST_RATELIMIT_CACHE]
except KeyError:
# Django will raise later when using
# this cache so we do nothing
return
if (not settings.ST_RATELIMIT_SKIP_TIMEOUT_CHECK and
cache.get('TIMEOUT', 1) is not None):
# todo: ConfigurationError in next version
warn(
'settings.ST_RATELIMIT_CACHE cache\'s TIMEOUT '
'must be None (never expire) and it may '
def is_limited(self, increment=True):
if not settings.ST_RATELIMIT_ENABLE:
return False
if increment:
cache_values = self.incr()
else:
cache_values = self._get_cache_values()
return any(
count > self.limit
for count in cache_values)
def process_request(self, request):
if not request.user.is_authenticated:
return
threshold = settings.ST_USER_LAST_SEEN_THRESHOLD_MINUTES * 60
delta = timezone.now() - request.user.st.last_seen
if delta.total_seconds() < threshold:
return
(UserProfile.objects
.filter(pk=request.user.st.pk)
.update(last_seen=timezone.now()))
def index_queryset(self, using=None):
return (self.get_model().objects
.all()
.exclude(category_id=settings.ST_TOPIC_PRIVATE_CATEGORY_PK)
.select_related('category__parent'))
def clean_q(self):
q = self.cleaned_data['q']
if len(q) < settings.ST_SEARCH_QUERY_MIN_LEN:
raise forms.ValidationError(
_("Your search must contain at "
"least %(length)s characters.") % {
'length': settings.ST_SEARCH_QUERY_MIN_LEN})
return q
def get_allowed_image_types():
return ", ".join(
'.%s' % ext
for ext in sorted(settings.ST_ALLOWED_UPLOAD_IMAGE_FORMAT))