本文整理汇总了Python中seahub.utils.normalize_cache_key函数的典型用法代码示例。如果您正苦于以下问题:Python normalize_cache_key函数的具体用法?Python normalize_cache_key怎么用?Python normalize_cache_key使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了normalize_cache_key函数的17个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: incr_login_failed_attempts
def incr_login_failed_attempts(username=None, ip=None):
"""Increase login failed attempts by 1 for both username and ip.
Arguments:
- `username`:
- `ip`:
Returns new value of failed attempts.
"""
timeout = settings.LOGIN_ATTEMPT_TIMEOUT
username_attempts = 1
ip_attempts = 1
if username:
cache_key = normalize_cache_key(username, prefix=LOGIN_ATTEMPT_PREFIX)
try:
username_attempts = cache.incr(cache_key)
except ValueError:
cache.set(cache_key, 1, timeout)
if ip:
cache_key = normalize_cache_key(ip, prefix=LOGIN_ATTEMPT_PREFIX)
try:
ip_attempts = cache.incr(cache_key)
except ValueError:
cache.set(cache_key, 1, timeout)
return max(username_attempts, ip_attempts)
开发者ID:haiwen,项目名称:seahub,代码行数:28,代码来源:utils.py
示例2: clear_login_failed_attempts
def clear_login_failed_attempts(request, username):
"""Clear login failed attempts records.
Arguments:
- `request`:
"""
ip = get_remote_ip(request)
cache.delete(normalize_cache_key(username, prefix=LOGIN_ATTEMPT_PREFIX))
cache.delete(normalize_cache_key(ip, prefix=LOGIN_ATTEMPT_PREFIX))
p = Profile.objects.get_profile_by_user(username)
if p and p.login_id:
cache.delete(normalize_cache_key(p.login_id, prefix=LOGIN_ATTEMPT_PREFIX))
开发者ID:haiwen,项目名称:seahub,代码行数:13,代码来源:utils.py
示例3: refresh_cache
def refresh_cache(username):
"""
Function to be called when change user nickname.
"""
profile = get_first_object_or_none(Profile.objects.filter(user=username))
nickname = profile.nickname if profile else username.split('@')[0]
contactemail = profile.contact_email if profile else ''
key = normalize_cache_key(username, NICKNAME_CACHE_PREFIX)
cache.set(key, nickname, NICKNAME_CACHE_TIMEOUT)
contact_key = normalize_cache_key(username, CONTACT_CACHE_PREFIX)
cache.set(contact_key, contactemail, CONTACT_CACHE_TIMEOUT)
开发者ID:haiwen,项目名称:seahub,代码行数:13,代码来源:utils.py
示例4: _get_cache_key
def _get_cache_key(request, prefix):
"""Return cache key of certain ``prefix``. If user is logged in, use
username, otherwise use combination of request ip and user agent.
Arguments:
- `prefix`:
"""
if request.user.is_authenticated():
key = normalize_cache_key(request.user.username, 'SharedLink_')
else:
ip = get_remote_ip(request)
# Memcached key length limit is 250 chars, and user agent somethings may
# be long which will cause error.
agent = request.META.get('HTTP_USER_AGENT', '')[:150]
key = normalize_cache_key(ip + agent, 'SharedLink_')
return key
开发者ID:ggkitsas,项目名称:seahub,代码行数:17,代码来源:models.py
示例5: char2pinyin
def char2pinyin(value):
"""Convert Chinese character to pinyin."""
key = normalize_cache_key(value, 'CHAR2PINYIN_')
py = cache.get(key)
if not py:
py = cc.convert(value)
cache.set(key, py, 365 * 24 * 60 * 60)
return py
开发者ID:saqebakhter,项目名称:seahub,代码行数:10,代码来源:seahub_tags.py
示例6: get_login_failed_attempts
def get_login_failed_attempts(username=None, ip=None):
"""Get login failed attempts base on username and ip.
If both username and ip are provided, return the max value.
Arguments:
- `username`:
- `ip`:
"""
if username is None and ip is None:
return 0
username_attempts = ip_attempts = 0
if username:
cache_key = normalize_cache_key(username, prefix=LOGIN_ATTEMPT_PREFIX)
username_attempts = cache.get(cache_key, 0)
if ip:
cache_key = normalize_cache_key(ip, prefix=LOGIN_ATTEMPT_PREFIX)
ip_attempts = cache.get(cache_key, 0)
return max(username_attempts, ip_attempts)
开发者ID:haiwen,项目名称:seahub,代码行数:22,代码来源:utils.py
示例7: email2nickname
def email2nickname(value):
"""
Return nickname or short email.
"""
if not value:
return ''
key = normalize_cache_key(value, NICKNAME_CACHE_PREFIX)
nickname = cache.get(key)
if not nickname:
profile = get_first_object_or_none(Profile.objects.filter(user=value))
nickname = profile.nickname if profile else value.split('@')[0]
cache.set(key, nickname, NICKNAME_CACHE_TIMEOUT)
return nickname
开发者ID:saqebakhter,项目名称:seahub,代码行数:14,代码来源:seahub_tags.py
示例8: ajax_get_link_audit_code
def ajax_get_link_audit_code(request):
"""
Generate a token, and record that token with email in cache, expires in
one hour, send token to that email address.
User provide token and email at share link page, if the token and email
are valid, record that email in session.
"""
content_type = 'application/json; charset=utf-8'
token = request.POST.get('token')
email = request.POST.get('email')
if not is_valid_email(email):
return HttpResponse(json.dumps({
'error': _('Email address is not valid')
}), status=400, content_type=content_type)
dfs = FileShare.objects.get_valid_file_link_by_token(token)
ufs = UploadLinkShare.objects.get_valid_upload_link_by_token(token)
fs = dfs if dfs else ufs
if fs is None:
return HttpResponse(json.dumps({
'error': _('Share link is not found')
}), status=400, content_type=content_type)
cache_key = normalize_cache_key(email, 'share_link_audit_')
timeout = 60 * 60 # one hour
code = gen_token(max_length=6)
cache.set(cache_key, code, timeout)
# send code to user via email
subject = _("Verification code for visiting share links")
c = {
'code': code,
}
try:
send_html_email_with_dj_template(
email, dj_template='share/audit_code_email.html',
context=c, subject=subject, priority=MAIL_PRIORITY.now
)
return HttpResponse(json.dumps({'success': True}), status=200,
content_type=content_type)
except Exception as e:
logger.error('Failed to send audit code via email to %s')
logger.error(e)
return HttpResponse(json.dumps({
"error": _("Failed to send a verification code, please try again later.")
}), status=500, content_type=content_type)
开发者ID:TanLian,项目名称:seahub,代码行数:49,代码来源:views.py
示例9: email2contact_email
def email2contact_email(value):
"""
Return contact_email if it exists and it's not an empty string,
otherwise return username(login email).
"""
if not value:
return ''
key = normalize_cache_key(value, CONTACT_CACHE_PREFIX)
contact_email = cache.get(key)
if contact_email and contact_email.strip():
return contact_email
contact_email = Profile.objects.get_contact_email_by_user(value)
cache.set(key, contact_email, CONTACT_CACHE_TIMEOUT)
return contact_email
开发者ID:haiwen,项目名称:seahub,代码行数:16,代码来源:seahub_tags.py
示例10: _decorated
def _decorated(request, token, *args, **kwargs):
assert token is not None # Checked by URLconf
fileshare = FileShare.objects.get_valid_file_link_by_token(token) or \
FileShare.objects.get_valid_dir_link_by_token(token) or \
UploadLinkShare.objects.get_valid_upload_link_by_token(token)
if fileshare is None:
raise Http404
if not is_pro_version() or not settings.ENABLE_SHARE_LINK_AUDIT:
return func(request, fileshare, *args, **kwargs)
# no audit for authenticated user, since we've already got email address
if request.user.is_authenticated():
return func(request, fileshare, *args, **kwargs)
# anonymous user
if request.session.get('anonymous_email') is not None:
request.user.username = request.session.get('anonymous_email')
return func(request, fileshare, *args, **kwargs)
if request.method == 'GET':
return render_to_response('share/share_link_audit.html', {
'token': token,
}, context_instance=RequestContext(request))
elif request.method == 'POST':
code = request.POST.get('code', '')
email = request.POST.get('email', '')
cache_key = normalize_cache_key(email, 'share_link_audit_')
if code == cache.get(cache_key):
# code is correct, add this email to session so that he will
# not be asked again during this session, and clear this code.
request.session['anonymous_email'] = email
request.user.username = request.session.get('anonymous_email')
cache.delete(cache_key)
return func(request, fileshare, *args, **kwargs)
else:
return render_to_response('share/share_link_audit.html', {
'err_msg': 'Invalid token, please try again.',
'email': email,
'code': code,
'token': token,
}, context_instance=RequestContext(request))
else:
assert False, 'TODO'
开发者ID:RaphaelWimmer,项目名称:seahub,代码行数:47,代码来源:decorators.py
示例11: group_id_to_name
def group_id_to_name(group_id):
group_id = str(group_id)
key = normalize_cache_key(group_id, GROUP_ID_CACHE_PREFIX)
cached_group_name = cache.get(key)
if cached_group_name:
return cached_group_name
group = ccnet_api.get_group(int(group_id))
if not group:
return ''
group_name = group.group_name
cache.set(key, group_name, GROUP_ID_CACHE_TIMEOUT)
return group_name
开发者ID:haiwen,项目名称:seahub,代码行数:17,代码来源:utils.py
示例12: test_anonymous_user_post_correct_token
def test_anonymous_user_post_correct_token(self, mock_is_pro_version):
"""
Check that anonnymous user input email and correct verification code.
"""
mock_is_pro_version.return_value = True
code = gen_token(max_length=6)
email = '[email protected]'
cache_key = normalize_cache_key(email, 'share_link_audit_')
cache.set(cache_key, code, timeout=60)
assert cache.get(cache_key) == code
anon_req = self._anon_post_request(data={'code': code, 'email': email})
self.assertEqual(anon_req.session.get('anonymous_email'), None)
resp = self._fake_view_shared_file(anon_req, self.fs.token)
self.assertEqual(resp.status_code, 200)
self.assertEqual(anon_req.session.get('anonymous_email'), email) # email is set in session
assert cache.get(cache_key) is None # token is delete after used
开发者ID:AviorAlong,项目名称:haiwen-5.1.3,代码行数:19,代码来源:test_decorators.py
示例13: email2id
def email2id(value):
"""
Return the user id of an email. User id can be 0(ldap user),
positive(registered user) or negtive(unregistered user).
"""
if not value:
return -1
key = normalize_cache_key(value, EMAIL_ID_CACHE_PREFIX)
user_id = cache.get(key)
if not user_id:
try:
user = User.objects.get(email=value)
user_id = user.id
except User.DoesNotExist:
user_id = -1
cache.set(key, user_id, EMAIL_ID_CACHE_TIMEOUT)
return user_id
开发者ID:saqebakhter,项目名称:seahub,代码行数:19,代码来源:seahub_tags.py
示例14: email2nickname
def email2nickname(value):
"""
Return nickname if it exists and it's not an empty string,
otherwise return short email.
"""
if not value:
return ''
key = normalize_cache_key(value, NICKNAME_CACHE_PREFIX)
cached_nickname = cache.get(key)
if cached_nickname and cached_nickname.strip():
return cached_nickname.strip()
profile = get_first_object_or_none(Profile.objects.filter(user=value))
if profile is not None and profile.nickname and profile.nickname.strip():
nickname = profile.nickname.strip()
else:
nickname = value.split('@')[0]
cache.set(key, nickname, NICKNAME_CACHE_TIMEOUT)
return nickname
开发者ID:AviorAlong,项目名称:haiwen-5.1.3,代码行数:21,代码来源:seahub_tags.py
示例15: clean_email_id_cache
def clean_email_id_cache(sender, **kwargs):
from seahub.utils import normalize_cache_key
user = kwargs['user']
key = normalize_cache_key(user.email, EMAIL_ID_CACHE_PREFIX)
cache.set(key, user.id, EMAIL_ID_CACHE_TIMEOUT)
开发者ID:hangshisitu,项目名称:seahub,代码行数:6,代码来源:models.py
示例16: update_user_info
def update_user_info(request, user):
# update basic user info
password = request.data.get("password")
if password:
user.set_password(password)
is_staff = request.data.get("is_staff")
if is_staff:
is_staff = to_python_boolean(is_staff)
user.is_staff = is_staff
is_active = request.data.get("is_active")
if is_active:
is_active = to_python_boolean(is_active)
user.is_active = is_active
# update user
user.save()
email = user.username
# update additional user info
if is_pro_version():
role = request.data.get("role")
if role:
User.objects.update_role(email, role)
nickname = request.data.get("name", None)
if nickname is not None:
Profile.objects.add_or_update(email, nickname)
# update account login_id
login_id = request.data.get("login_id", None)
if login_id is not None:
Profile.objects.add_or_update(email, login_id=login_id)
# update account contact email
contact_email = request.data.get('contact_email', None)
if contact_email is not None:
Profile.objects.add_or_update(email, contact_email=contact_email)
key = normalize_cache_key(email, CONTACT_CACHE_PREFIX)
cache.set(key, contact_email, CONTACT_CACHE_TIMEOUT)
reference_id = request.data.get("reference_id", None)
if reference_id is not None:
if reference_id.strip():
ccnet_api.set_reference_id(email, reference_id.strip())
else:
# remove reference id
ccnet_api.set_reference_id(email, None)
department = request.data.get("department")
if department:
d_profile = DetailedProfile.objects.get_detailed_profile_by_user(email)
if d_profile is None:
d_profile = DetailedProfile(user=email)
d_profile.department = department
d_profile.save()
quota_total_mb = request.data.get("quota_total")
if quota_total_mb:
quota_total = int(quota_total_mb) * get_file_size_unit('MB')
if is_org_context(request):
org_id = request.user.org.org_id
seafile_api.set_org_user_quota(org_id, email, quota_total)
else:
seafile_api.set_user_quota(email, quota_total)
开发者ID:haiwen,项目名称:seahub,代码行数:69,代码来源:users.py
示例17: get_cache_key_of_unseen_notifications
def get_cache_key_of_unseen_notifications(username):
return normalize_cache_key(username,
USER_NOTIFICATION_COUNT_CACHE_PREFIX)
开发者ID:haiwen,项目名称:seahub,代码行数:3,代码来源:models.py
注:本文中的seahub.utils.normalize_cache_key函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论