本文整理汇总了Python中members.models.Member.get_for_staff方法的典型用法代码示例。如果您正苦于以下问题:Python Member.get_for_staff方法的具体用法?Python Member.get_for_staff怎么用?Python Member.get_for_staff使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类members.models.Member
的用法示例。
在下文中一共展示了Member.get_for_staff方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: api_member_details
# 需要导入模块: from members.models import Member [as 别名]
# 或者: from members.models.Member import get_for_staff [as 别名]
def api_member_details(request, member_card_str, staff_card_str):
""" Respond with corresponding user/member info given the membership card string in the QR code. """
success, info = Member.get_for_staff(member_card_str, staff_card_str)
if not success:
error_msg = info
return JsonResponse({'error': error_msg})
member, _ = info # type: Tuple[Member, Member]
data = {
'pk': member.pk,
'is_active': member.is_active,
'username': member.username,
'first_name': member.first_name,
'last_name': member.last_name,
'email': member.email,
'tags': [tag.name for tag in member.tags.all()]
}
return JsonResponse(data)
示例2: kiosk_add_tag
# 需要导入模块: from members.models import Member [as 别名]
# 或者: from members.models.Member import get_for_staff [as 别名]
def kiosk_add_tag(request, member_card_str, staff_card_str, tag_pk):
# We only get to this view from a link produced by a previous view.
# This view assumes that the previous view is passing valid strs and pk.
# Any exceptions raised in this view can be considered programming errors and are not caught.
# This view DOES NOT use member PKs even though the previous view could provide them.
# Using PKs would make this view vulnerable to brute force attacks to create unauthorized taggings.
success, info = Member.get_for_staff(member_card_str, staff_card_str)
if not success:
error_msg = info
return HttpResponse("Error: %s." % error_msg) #TODO: Use kiosk-domain-error template?
tag = Tag.objects.get(pk=tag_pk)
member, staff = info
# The following can be considered an assertion that the given staff member is authorized to grant the given tag.
Tagging.objects.get(can_tag=True, tagged_member=staff, tag=tag)
# Create the new tagging and then go back to the member details view.
Tagging.objects.create(tagged_member=member, authorizing_member=staff, tag=tag)
return redirect('..')
示例3: kiosk_member_details
# 需要导入模块: from members.models import Member [as 别名]
# 或者: from members.models.Member import get_for_staff [as 别名]
def kiosk_member_details(request, member_card_str, staff_card_str):
success, info = Member.get_for_staff(member_card_str, staff_card_str)
if not success:
return render(request, 'members/kiosk-invalid-card.html', {}) #TODO: use kiosk-domain-error template?
member, staff = info # type: Tuple[Member, Member]
staff_can_tags = [ting.tag for ting in Tagging.objects.filter(can_tag=True, tagged_member=staff)]
# staff member can't add tags that member already has, so:
for tag in member.tags.all():
if tag in staff_can_tags:
staff_can_tags.remove(tag)
return render(request, 'members/kiosk-member-details.html', {
"staff_card_str" : staff_card_str,
"staff_fname" : staff.first_name,
"memb_fname" : member.first_name,
"memb_name" : "%s %s" % (member.first_name, member.last_name),
"username" : member.username,
"email" : member.email,
"members_tags" : member.tags.all(),
"staff_can_tags" : staff_can_tags,
})