本文整理汇总了Python中accounts.models.User.get_by_id方法的典型用法代码示例。如果您正苦于以下问题:Python User.get_by_id方法的具体用法?Python User.get_by_id怎么用?Python User.get_by_id使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类accounts.models.User
的用法示例。
在下文中一共展示了User.get_by_id方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: TagList
# 需要导入模块: from accounts.models import User [as 别名]
# 或者: from accounts.models.User import get_by_id [as 别名]
def TagList(request, tag):
uid = request.session.get('user')
#if user not connected
if uid is None:
#if not request.user.is_authenticated():
return sign_in(request)
else:
uid = request.session.get('user')
usr = User.get_by_id(uid)
## retrieve tags slug based on user
shares = usr.shares.filter(taggit__slug=tag).order_by('-created_at')
#shares = Share.objects.filter(taggit__name=tag, author=user).select_related().get()
return render_to_response('tag_list.html', {
'user':usr,
'tag_list': shares
}, context_instance=RequestContext(request),)
示例2: allTags
# 需要导入模块: from accounts.models import User [as 别名]
# 或者: from accounts.models.User import get_by_id [as 别名]
def allTags(request):
uid = request.session.get('user')
#if user not connected
if uid is None:
#if not request.user.is_authenticated():
return sign_in(request)
else:
uid = request.session.get('user')
usr = User.get_by_id(uid)
## retrieve all tags slug based on user
all_tags = Tag.objects.filter(share__author=usr).order_by('-tag_count').annotate(tag_count=models.Count('share'))
return render_to_response('all_tags.html', {
'user':usr,
'all_tags': all_tags,
# 'shares': shares
}, context_instance=RequestContext(request),)
示例3: index
# 需要导入模块: from accounts.models import User [as 别名]
# 或者: from accounts.models.User import get_by_id [as 别名]
def index(request):
uid = request.session.get('user')
#if user not connected
if uid is None:
return sign_in(request)
#if user connected
else:
usr = User.get_by_id(uid)
#shares = Share.objects.all().order_by('-created_at')
shares = usr.shares.all().order_by('-created_at')
return render_to_response('accounts/index_connected.html', {
'user':usr,
'share_list': shares
}, context_instance=RequestContext(request),)
示例4: show_tags
# 需要导入模块: from accounts.models import User [as 别名]
# 或者: from accounts.models.User import get_by_id [as 别名]
def show_tags(context):
request = context['request']
uid = request.session['user']
user = User.get_by_id(uid)
### filter by user, then annotate (regroup), and count the last 10 tags
tagged = Tag.objects.filter(share__author=user).order_by('-tag_count').annotate(tag_count=models.Count('share'))[:10]
all_tags = Tag.objects.filter(share__author=user)
### get all the last 5 shares
#tagged = user.shares.all().order_by('-created_at')[:5]
return {
'tagged_items': tagged,
'all_tags' : all_tags
}
示例5: share_text
# 需要导入模块: from accounts.models import User [as 别名]
# 或者: from accounts.models.User import get_by_id [as 别名]
def share_text(request):
#http://stackoverflow.com/questions/8466768/using-request-user-with-django-modelform
uid = request.session.get('user')
#if user not connected
if uid is None:
#not connected
user = None
if request.method == 'POST':
#author = Share(user=request.user)
form = SigninForm(request.POST)
if form.is_valid():
#form.author = request.user
results = User.objects.filter(email=form.cleaned_data['email'])
if len(results) == 1:
if results[0].check_password(form.cleaned_data['password']):
request.session['user'] = results[0].pk
return HttpResponseRedirect('/')
else:
form.addError('Incorrect email address or password')
else:
form.addError('Incorrect email address or password')
else:
form = SigninForm()
print form.non_field_errors()
return render_to_response(
'accounts/sign_in.html',
{
'form': form,
'user': user
},
context_instance=RequestContext(request)
)
else: #if user is connected
uid = request.session.get('user')
user = User.get_by_id(uid)
if request.method == "POST":
#text = Share(author=request.user)
form = TextForm(request.POST)
if form.is_valid():
#load tags
taggit = form.cleaned_data['taggit']
text = form.save(commit=False)
#save the user instance
text.author = user
text.save()
#save/add tags in text object #http://stackoverflow.com/questions/5359714/django-django-taggit-form
for taggit in taggit:
text.taggit.add(taggit)
last_random = Share.objects.values_list('random', flat=True).order_by('-created_at')[:1]
#this returns [u'5eXB612345']
#return the random sequence only to a strng format 5eXB6
new_random = str(last_random)[3:13]
return redirect('/%s' % new_random)
else:
form = TextForm()
return render_to_response(
'new/text.html',
{
'text_form': form,
'user': user
},
context_instance=RequestContext(request)
)