本文整理汇总了Python中utils.to36函数的典型用法代码示例。如果您正苦于以下问题:Python to36函数的具体用法?Python to36怎么用?Python to36使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了to36函数的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: get_short_url
def get_short_url(self, user=None):
if not self.id: raise UrlNotSaved
domain = None
if user:
domain = redis_ob.hget("user:%s" %str(user), "custom_domain")
if not domain: domain = settings.SHORT_URL
return '%s%s/' %(domain, to36(int(self.id)))
示例2: file_upload
def file_upload(request):
if not request.method == 'POST': raise Http404
if not request.FILES: raise Http404
if not request.FILES.has_key('file'): raise Http404
if not os.path.exists(os.path.join(settings.MEDIA_ROOT, 'files')):
os.makedirs(os.path.join(settings.MEDIA_ROOT, 'files'))
url_id = redis_ob.incr('counter:url')
temp_file_name = to36(url_id)
file_data = request.FILES['file']
api_key = request.POST.get("api_key", None)
sub = file_data.name.split('.')[-1]
destination = open(os.path.join(settings.MEDIA_ROOT, 'files', temp_file_name+'.'+sub), 'wb+')
for chunk in file_data.chunks():
destination.write(chunk)
url = settings.SHORT_URL+"static/files/"+temp_file_name+'.'+sub
url_object = UrlModel(url_data={'url':url,'is_file':True, 'file_name':temp_file_name+'.'+sub})
url_object.save(url_id=url_id)
# if authenticated user set url to his account
if request.session.has_key("user_id"):
user_id = request.session["user_id"]
if redis_ob.hexists("user:%s" %str(user_id), "email"):
redis_ob.lpush("user:urls:%s" %request.session['user_id'], "url:"+str(url_object.id))
link = url_object.get_short_url(user_id)
else:
link = url_object.get_short_url()
# if api_key is set add the url to the user account
if api_key:
user_id = redis_ob.get("user:api_key:%s" %api_key)
if redis_ob.hexists("user:%s" %str(user_id), "email"):
redis_ob.lpush("user:urls:%s" %user_id, "url:"+str(url_object.id))
if request.POST.get("html", None) == "true":
return HttpResponse(simplejson.dumps({"url": link, "long_url": url}), mimetype="application/javascript")
return HttpResponse(link)
示例3: thing_attr
def thing_attr(self, thing, attr):
if attr == 'children':
return [to36(x) for x in thing.children]
if attr in ('body', 'body_html'):
return ""
return CommentJsonTemplate.thing_attr(self, thing, attr)
示例4: make_fullname
def make_fullname(typ, _id):
return '%s_%s' % (make_typename(typ), to36(_id))
示例5: make_typename
def make_typename(typ):
return 't%s' % to36(typ._type_id)