本文整理匯總了Python中seahub.utils.paginator.Paginator.get_page_range方法的典型用法代碼示例。如果您正苦於以下問題:Python Paginator.get_page_range方法的具體用法?Python Paginator.get_page_range怎麽用?Python Paginator.get_page_range使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類seahub.utils.paginator.Paginator
的用法示例。
在下文中一共展示了Paginator.get_page_range方法的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: user_msg_list
# 需要導入模塊: from seahub.utils.paginator import Paginator [as 別名]
# 或者: from seahub.utils.paginator.Paginator import get_page_range [as 別名]
def user_msg_list(request, id_or_email):
"""List messages related to a certain person.
"""
try:
uid = int(id_or_email)
try:
user = User.objects.get(id=uid)
except User.DoesNotExist:
user = None
if not user:
return render_to_response("user_404.html",{},
context_instance=RequestContext(request))
to_email = user.email
except ValueError:
to_email = id_or_email
username = request.user.username
if username == to_email:
return HttpResponseRedirect(reverse('edit_profile'))
msgs = UserMessage.objects.get_messages_between_users(username, to_email)
if msgs:
# update ``ifread`` field of messages
UserMessage.objects.update_unread_messages(to_email, username)
'''paginate'''
paginator = Paginator(msgs, 15)
# Make sure page request is an int. If not, deliver first page.
try:
page = int(request.GET.get('page', '1'))
except ValueError:
page = 1
# If page request (9999) is out of range, deliver last page of results.
try:
person_msgs = paginator.page(page)
except (EmptyPage, InvalidPage):
person_msgs = paginator.page(paginator.num_pages)
person_msgs.page_range = paginator.get_page_range(person_msgs.number)
person_msgs.object_list = list(person_msgs.object_list)
c = Contact.objects.get_contact_by_user(username, to_email)
add_to_contacts = True if c is None else False
return render_to_response("message/user_msg_list.html", {
"person_msgs": person_msgs,
"to_email": to_email,
"add_to_contacts": add_to_contacts,
}, context_instance=RequestContext(request))
示例2: user_msg_list
# 需要導入模塊: from seahub.utils.paginator import Paginator [as 別名]
# 或者: from seahub.utils.paginator.Paginator import get_page_range [as 別名]
def user_msg_list(request, id_or_email):
"""List messages related to a certain person.
"""
try:
uid = int(id_or_email)
try:
user = User.objects.get(id=uid)
except User.DoesNotExist:
user = None
if not user:
return render_to_response("user_404.html",{},
context_instance=RequestContext(request))
to_email = user.email
except ValueError:
to_email = id_or_email
username = request.user.username
if username == to_email:
return HttpResponseRedirect(reverse('edit_profile'))
msgs = UserMessage.objects.get_messages_between_users(username, to_email)
if msgs:
# update ``ifread`` field of messages
UserMessage.objects.update_unread_messages(to_email, username)
attachments = UserMsgAttachment.objects.list_attachments_by_user_msgs(msgs)
for msg in msgs:
msg.attachments = []
for att in attachments:
if att.user_msg != msg:
continue
pfds = att.priv_file_dir_share
if pfds is None: # in case that this attachment is unshared.
continue
att.repo_id = pfds.repo_id
att.path = pfds.path
att.name = os.path.basename(pfds.path.rstrip('/'))
att.token = pfds.token
msg.attachments.append(att)
'''paginate'''
paginator = Paginator(msgs, 15)
# Make sure page request is an int. If not, deliver first page.
try:
page = int(request.GET.get('page', '1'))
except ValueError:
page = 1
# If page request (9999) is out of range, deliver last page of results.
try:
person_msgs = paginator.page(page)
except (EmptyPage, InvalidPage):
person_msgs = paginator.page(paginator.num_pages)
person_msgs.page_range = paginator.get_page_range(person_msgs.number)
person_msgs.object_list = list(person_msgs.object_list)
return render_to_response("message/user_msg_list.html", {
"person_msgs": person_msgs,
"to_email": to_email,
}, context_instance=RequestContext(request))
示例3: group_discuss
# 需要導入模塊: from seahub.utils.paginator import Paginator [as 別名]
# 或者: from seahub.utils.paginator.Paginator import get_page_range [as 別名]
def group_discuss(request, group):
if group.is_pub:
raise Http404
username = request.user.username
form = MessageForm()
# remove user notifications
UserNotification.objects.seen_group_msg_notices(username, group.id)
# Get all group members.
members = get_group_members(group.id)
"""group messages"""
# Show 15 group messages per page.
paginator = Paginator(GroupMessage.objects.filter(group_id=group.id).order_by("-timestamp"), 15)
# Make sure page request is an int. If not, deliver first page.
try:
page = int(request.GET.get("page", "1"))
except ValueError:
page = 1
# If page request (9999) is out of range, deliver last page of results.
try:
group_msgs = paginator.page(page)
except (EmptyPage, InvalidPage):
group_msgs = paginator.page(paginator.num_pages)
group_msgs.page_range = paginator.get_page_range(group_msgs.number)
# Force evaluate queryset to fix some database error for mysql.
group_msgs.object_list = list(group_msgs.object_list)
msg_attachments = MessageAttachment.objects.filter(group_message__in=group_msgs.object_list)
msg_replies = MessageReply.objects.filter(reply_to__in=group_msgs.object_list)
reply_to_list = [r.reply_to_id for r in msg_replies]
for msg in group_msgs.object_list:
msg.reply_cnt = reply_to_list.count(msg.id)
msg.replies = []
for r in msg_replies:
if msg.id == r.reply_to_id:
msg.replies.append(r)
msg.replies = msg.replies[-3:]
msg.attachments = []
for att in msg_attachments:
if att.group_message_id != msg.id:
continue
# Attachment name is file name or directory name.
# If is top directory, use repo name instead.
path = att.path
if path == "/":
repo = get_repo(att.repo_id)
if not repo:
# TODO: what should we do here, tell user the repo
# is no longer exists?
continue
att.name = repo.name
else:
path = path.rstrip("/") # cut out last '/' if possible
att.name = os.path.basename(path)
# Load to discuss page if attachment is a image and from recommend.
if att.attach_type == "file" and att.src == "recommend":
att.filetype, att.fileext = get_file_type_and_ext(att.name)
if att.filetype == IMAGE:
att.obj_id = get_file_id_by_path(att.repo_id, path)
if not att.obj_id:
att.err = _(u"File does not exist")
else:
att.token = seafile_api.get_fileserver_access_token(att.repo_id, att.obj_id, "view", username)
att.img_url = gen_file_get_url(att.token, att.name)
msg.attachments.append(att)
# get available modules(wiki, etc)
mods_available = get_available_mods_by_group(group.id)
mods_enabled = get_enabled_mods_by_group(group.id)
return render_to_response(
"group/group_discuss.html",
{
"group": group,
"is_staff": group.is_staff,
"group_msgs": group_msgs,
"form": form,
"mods_enabled": mods_enabled,
"mods_available": mods_available,
},
context_instance=RequestContext(request),
)
示例4: group_discuss
# 需要導入模塊: from seahub.utils.paginator import Paginator [as 別名]
# 或者: from seahub.utils.paginator.Paginator import get_page_range [as 別名]
def group_discuss(request, group_id):
if request.method == 'POST':
form = MessageForm(request.POST)
if form.is_valid():
msg = form.cleaned_data['message']
message = GroupMessage()
message.group_id = group_id
message.from_email = request.user.username
message.message = msg
message.save()
# send signal
grpmsg_added.send(sender=GroupMessage, group_id=group_id,
from_email=request.user.username)
# Always return an HttpResponseRedirect after successfully dealing
# with POST data.
return HttpResponseRedirect(reverse('group_discuss', args=[group_id]))
else:
form = MessageForm()
op = request.GET.get('op', '')
if op == 'delete':
return group_remove(request, group_id)
elif op == 'dismiss':
return group_dismiss(request, group_id)
elif op == 'quit':
return group_quit(request, group_id)
group_id_int = int(group_id) # Checkeb by URL Conf
# remove user notifications
UserNotification.objects.filter(to_user=request.user.username,
msg_type='group_msg',
detail=str(group_id)).delete()
group = get_group(group_id_int)
if not group:
return HttpResponseRedirect(reverse('group_list', args=[]))
# Check whether user belongs to the group.
joined = is_group_user(group_id_int, request.user.username)
if not joined and not request.user.is_staff:
# Return group public info page.
return render_to_response('group/group_pubinfo.html', {
'members': members,
'group': group,
}, context_instance=RequestContext(request))
# Get all group members.
members = get_group_members(group_id_int)
is_staff = True if check_group_staff(group.id, request.user) else False
"""group messages"""
# Show 15 group messages per page.
paginator = Paginator(GroupMessage.objects.filter(
group_id=group_id).order_by('-timestamp'), 15)
# Make sure page request is an int. If not, deliver first page.
try:
page = int(request.GET.get('page', '1'))
except ValueError:
page = 1
# If page request (9999) is out of range, deliver last page of results.
try:
group_msgs = paginator.page(page)
except (EmptyPage, InvalidPage):
group_msgs = paginator.page(paginator.num_pages)
group_msgs.page_range = paginator.get_page_range(group_msgs.number)
# Force evaluate queryset to fix some database error for mysql.
group_msgs.object_list = list(group_msgs.object_list)
attachments = MessageAttachment.objects.filter(group_message__in=group_msgs.object_list)
msg_replies = MessageReply.objects.filter(reply_to__in=group_msgs.object_list)
reply_to_list = [ r.reply_to_id for r in msg_replies ]
for msg in group_msgs.object_list:
msg.reply_cnt = reply_to_list.count(msg.id)
msg.replies = []
for r in msg_replies:
if msg.id == r.reply_to_id:
msg.replies.append(r)
msg.replies = msg.replies[-3:]
for att in attachments:
if msg.id == att.group_message_id:
# Attachment name is file name or directory name.
# If is top directory, use repo name instead.
path = att.path
if path == '/':
repo = get_repo(att.repo_id)
if not repo:
# TODO: what should we do here, tell user the repo
# is no longer exists?
continue
att.name = repo.name
#.........這裏部分代碼省略.........