本文整理汇总了Python中focus.models.Actor.get_personal_members方法的典型用法代码示例。如果您正苦于以下问题:Python Actor.get_personal_members方法的具体用法?Python Actor.get_personal_members怎么用?Python Actor.get_personal_members使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类focus.models.Actor
的用法示例。
在下文中一共展示了Actor.get_personal_members方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: handle
# 需要导入模块: from focus.models import Actor [as 别名]
# 或者: from focus.models.Actor import get_personal_members [as 别名]
def handle(self, *args, **options):
members = User.objects.filter(memberid__isnull=False)
pending_users = members.filter(is_pending=True)
normal_users = members.filter(is_pending=False)
# Check for pending users that recently got their Actor, and shouldn't be pending
for u in pending_users.filter(is_expired=False):
# This method automatically updates the user if not pending anymore
u.verify_still_pending(ignore_cache=True)
# Check for expired pending users that may have gotten their Actor or Enrollment object back
# (doesn't make sense that this actually happens, but let's not make assumptions for Focus)
for u in pending_users.filter(is_expired=True):
if Actor.get_personal_members().filter(memberid=u.memberid).exists():
u.is_expired = False
u.is_pending = False
u.save()
elif Enrollment.objects.filter(memberid=u.memberid).exists():
u.is_expired = False
u.save()
# Check for normal expired users that regained their Actor and shouldn't be expired anymore
for u in normal_users.filter(is_expired=True):
if Actor.get_personal_members().filter(memberid=u.memberid).exists():
u.is_expired = False
u.save()
# Check for normal users that have lost their Actor and should be expired
for u in normal_users.filter(is_expired=False):
if not Actor.get_personal_members().filter(memberid=u.memberid).exists():
u.is_expired = True
u.save()
示例2: search
# 需要导入模块: from focus.models import Actor [as 别名]
# 或者: from focus.models.Actor import get_personal_members [as 别名]
def search(request):
if not request.is_ajax() or request.method != 'POST':
return redirect('admin.users.views.index')
if len(request.POST['q']) < settings.ADMIN_USER_SEARCH_CHAR_LENGTH:
raise PermissionDenied
local_users = User.get_users().filter(memberid__isnull=True)
for word in request.POST['q'].split():
local_users = local_users.filter(
Q(first_name__icontains=word) |
Q(last_name__icontains=word))
local_users = local_users.order_by('first_name')
actors = Actor.get_personal_members()
for word in request.POST['q'].split():
actors = actors.filter(
Q(first_name__icontains=word) |
Q(last_name__icontains=word) |
Q(memberid__icontains=word))
actors = actors.order_by('first_name')
# Match expired users only on memberid
expired_users = User.objects.all()
for word in request.POST['q'].split():
expired_users = expired_users.filter(memberid__icontains=word)
expired_users = [u for u in expired_users if not Actor.get_personal_members().filter(memberid=u.memberid).exists()]
# Pending users
pending_enrollment = Enrollment.get_active()
for word in request.POST['q'].split():
pending_enrollment = pending_enrollment.filter(
Q(first_name__icontains=word) |
Q(last_name__icontains=word) |
Q(memberid__icontains=word))
pending_enrollment = pending_enrollment.order_by('first_name')
members = User.get_users().filter(memberid__in=[a.memberid for a in actors])
pending_users = User.get_users(include_pending=True).filter(memberid__in=[e.memberid for e in pending_enrollment])
actors_without_user = [a for a in actors if a.memberid not in list(members.values_list('memberid', flat=True))]
users = list(local_users) + list(members) + list(pending_users)
context = RequestContext(request, {
'users': users,
'actors_without_user': actors_without_user,
'expired_users': expired_users
})
return HttpResponse(render_to_string('common/admin/users/user_results.html', context))
示例3: update_from_actors
# 需要导入模块: from focus.models import Actor [as 别名]
# 或者: from focus.models.Actor import get_personal_members [as 别名]
def update_from_actors(self):
t1 = time.time()
if self.print_log:
print(" update_from_actors()")
self.main_stats['actor']['started'] = str(datetime.now())
actors = Actor.get_personal_members().order_by('id')
if self.filter_from_date:
actors = actors.filter(changed_date__gt=self.filter_from_date)
bulk_count = 10000
p = Paginator(actors, bulk_count)
self.main_stats['actor']['num_pages'] = p.num_pages
self.main_stats['actor']['pages'] = {}
if self.task_log:
self.task_log.data = self.main_stats
self.task_log.save()
self.update(p, 'actor')
self.main_stats['actor']['ended'] = str(datetime.now())
self.main_stats['actor']['duration'] = time.time() - t1
if self.task_log:
self.task_log.data = self.main_stats
self.task_log.save()
if self.print_log:
self.print_stats(self.main_stats['actor'], 4)
print(" update_from_actors() done in %0.2fs"
% self.main_stats['actor']['duration'])
示例4: attempt_login
# 需要导入模块: from focus.models import Actor [as 别名]
# 或者: from focus.models.Actor import get_personal_members [as 别名]
def attempt_login(request):
matches = authenticate_users(request.POST['email'], request.POST['password'])
if len(matches) == 1:
# Exactly one match, cool, just authenticate the user
user = authenticate(user=matches[0])
log_user_in(request, user)
return matches, None
elif len(matches) > 1:
# Multiple matches, let the caller handle this
return matches, None
elif len(matches) == 0:
# Incorrect credentials. Check if this is a user from the old userpage system
old_member = authenticate_sherpa2_user(request.POST['email'], request.POST['password'])
if old_member is not None:
# Actually, it is! Let's try to import them.
if User.get_users().filter(memberid=old_member.memberid, is_inactive=False).exists():
return matches, 'old_memberid_but_memberid_exists'
# Check if a pending user exists. This shouldn't ever happen (a pending user is recently
# enrolled, and an existing user will have been member for a long time).
if User.objects.filter(memberid=old_member.memberid, is_pending=True).exists():
# Give the same error ("user exists, you need to use your new password")
return matches, 'old_memberid_but_memberid_exists'
# Verify that they exist in the membersystem (this turned out to be an incorrect assumption)
if not Actor.get_personal_members().filter(memberid=old_member.memberid).exists():
# We're not quite sure why this can happen, so we'll just give them the invalid
# credentials message - but this might be confusing for those who were able to log
# in previously.
return matches, 'invalid_credentials'
# Create the new user
try:
# Check if the user's already created as inactive
user = User.get_users().get(memberid=old_member.memberid, is_inactive=True)
user.is_inactive = False
user.set_password(request.POST['password'])
user.save()
except User.DoesNotExist:
# New user
user = User(identifier=old_member.memberid, memberid=old_member.memberid)
user.set_password(request.POST['password'])
user.save()
# Update the email on this actor, in case it were to differ from the sherpa2 email
user.update_personal_data({'email': request.POST['email']})
# Import any fjelltreffen-annonser from the old system
import_fjelltreffen_annonser(user)
authenticate(user=user)
log_user_in(request, user)
return [user], None
else:
# No luck, just provide the error message
return matches, 'invalid_credentials'
示例5: __init__
# 需要导入模块: from focus.models import Actor [as 别名]
# 或者: from focus.models.Actor import get_personal_members [as 别名]
def __init__(self, memberid, actor=None):
try:
self.actor = actor if actor is not None else cache.get('actor.%s' % memberid)
if self.actor is None:
self.actor = Actor.get_personal_members().get(memberid=memberid)
cache.set('actor.%s' % memberid, self.actor, settings.FOCUS_MEMBER_CACHE_PERIOD)
except Actor.DoesNotExist:
# The referenced memberid doesn't exist in the member system. This typically occurs when the member system
# purges members who haven't been enrolled for 2 years or more.
raise ExpiredMember("Actor with memberid '%s' does not exist" % memberid)
示例6: get_children
# 需要导入模块: from focus.models import Actor [as 别名]
# 或者: from focus.models.Actor import get_personal_members [as 别名]
def get_children(self):
from user.models import User
children = cache.get('actor.%s.children' % self.actor.memberid)
if children is None:
actor_children = Actor.get_personal_members().filter(parent=self.actor.memberid).exclude(id=self.actor.id)
children = [
User.get_or_create_inactive(memberid=actor_child.memberid)
for actor_child in actor_children
]
cache.set('actor.%s.children' % self.actor.memberid, children, settings.FOCUS_MEMBER_CACHE_PERIOD)
return children
示例7: contact_person_search
# 需要导入模块: from focus.models import Actor [as 别名]
# 或者: from focus.models.Actor import get_personal_members [as 别名]
def contact_person_search(request, forening_id):
current_forening = Forening.objects.get(id=forening_id)
if current_forening not in request.user.all_foreninger():
raise PermissionDenied
MAX_HITS = 100
if len(request.POST['q']) < settings.ADMIN_USER_SEARCH_CHAR_LENGTH:
raise PermissionDenied
local_nonmember_users = User.get_users().filter(memberid__isnull=True)
for word in request.POST['q'].split():
local_nonmember_users = local_nonmember_users.filter(
Q(first_name__icontains=word) |
Q(last_name__icontains=word)
)
local_nonmember_users = local_nonmember_users.order_by('first_name')
actors = Actor.get_personal_members()
for word in request.POST['q'].split():
actors = actors.filter(
Q(first_name__icontains=word) |
Q(last_name__icontains=word) |
Q(memberid__icontains=word)
)
actors = actors.order_by('first_name')
# Get (or create) the user objects for the first MAX_HITS actor-hits
users = [
User.get_or_create_inactive(a.memberid)
for a in actors[:MAX_HITS]]
# Merge with non-members
users = sorted(
list(users) + list(local_nonmember_users),
key=lambda u: u.get_full_name())
context = {
'current_forening': current_forening,
'users': users[:MAX_HITS],
}
return HttpResponse(json.dumps({
'results': render_to_string(
'central/admin/foreninger/contact_person_search_results.html',
context,
request=request,
),
'max_hits_exceeded': len(users) > MAX_HITS or len(actors) > MAX_HITS
}))
示例8: cache_actors
# 需要导入模块: from focus.models import Actor [as 别名]
# 或者: from focus.models.Actor import get_personal_members [as 别名]
def cache_actors(memberids):
# Run a search with several memberids towards Focus and recieve all
# relevant actor data. Then cache the result.
# This prevents multiple queries to Focus when for instance looping
# through users to display their name
# If we have more than 2100 parameters, MSSQL will cry, so split it
# up in bulks
for i in range(0, len(memberids), settings.MSSQL_MAX_PARAMETER_COUNT):
memberid_chunk = memberids[i:i + settings.MSSQL_MAX_PARAMETER_COUNT]
actors = Actor.get_personal_members().filter(
memberid__in=memberid_chunk)
for actor in actors:
cache.set(
'actor.%s' % actor.memberid,
actor,
settings.FOCUS_MEMBER_CACHE_PERIOD
)
示例9: get_queryset
# 需要导入模块: from focus.models import Actor [as 别名]
# 或者: from focus.models.Actor import get_personal_members [as 别名]
def get_queryset(self):
# This method uses Focus and local users to compile a search result
# containing valid turledere.
# See the comment on the class definition of the lazy_queryset variable
if self.lazy_queryset:
return self.lazy_queryset
SEARCH_MAX_HITS = 100
search = self.request.query_params.get('search', '').strip()
local_nonmember_users = User.get_users().filter(memberid__isnull=True)
for word in search.split():
local_nonmember_users = local_nonmember_users.filter(
Q(first_name__icontains=word) |
Q(last_name__icontains=word)
)
local_nonmember_users = local_nonmember_users.order_by('first_name')
actors = Actor.get_personal_members()
for word in search.split():
actors = actors.filter(
Q(first_name__icontains=word) |
Q(last_name__icontains=word) |
Q(memberid__icontains=word)
)
actors = actors.order_by('first_name')
# Get (or create) the user objects for the first MAX_HITS actor-hits
users = [
User.get_or_create_inactive(a.memberid)
for a in actors[:SEARCH_MAX_HITS]]
# Merge with non-members
users = sorted(
list(users) + list(local_nonmember_users),
key=lambda u: u.get_full_name())
self.lazy_queryset = users
return users
示例10: validate_existing
# 需要导入模块: from focus.models import Actor [as 别名]
# 或者: from focus.models.Actor import get_personal_members [as 别名]
def validate_existing(enrollment):
try:
actor = Actor.get_personal_members().get(memberid=enrollment.existing_memberid)
except (Actor.DoesNotExist, ValueError):
return False
if not actor.has_paid():
return False
if datetime.now().year - actor.birth_date.year < AGE_YOUTH:
return False
if actor.is_household_member():
return False
if actor.get_clean_address().country.code != enrollment.country:
return False
if enrollment.country == 'NO' and actor.get_clean_address().zipcode.zipcode != enrollment.zipcode:
return False
return True
示例11: existing
# 需要导入模块: from focus.models import Actor [as 别名]
# 或者: from focus.models.Actor import get_personal_members [as 别名]
def existing(request):
if not request.is_ajax():
return redirect('enrollment.views.household')
# Note: This logic is duplicated in validate_existing()
data = json.loads(request.POST['data'])
if data['country'] == 'NO' and len(data['zipcode']) != 4:
return HttpResponse(json.dumps({'error': 'bad_zipcode'}))
try:
actor = Actor.get_personal_members().get(memberid=data['id'])
except Actor.DoesNotExist:
return HttpResponse(json.dumps({'error': 'actor.does_not_exist'}))
except ValueError:
return HttpResponse(json.dumps({'error': 'invalid_id'}))
try:
if data['country'] == 'NO':
# Include zipcode for norwegian members
address = ActorAddress.objects.get(actor=actor.id, zipcode=data['zipcode'], country_code=data['country'])
else:
address = ActorAddress.objects.get(actor=actor.id, country_code=data['country'])
except ActorAddress.DoesNotExist:
return HttpResponse(json.dumps({'error': 'actoraddress.does_not_exist'}))
if not actor.has_paid():
return HttpResponse(json.dumps({'error': 'actor.has_not_paid'}))
age = datetime.now().year - actor.birth_date.year
if age < AGE_YOUTH:
return HttpResponse(json.dumps({'error': 'actor.too_young', 'age': age}))
if actor.is_household_member():
return HttpResponse(json.dumps({'error': 'actor.is_household_member'}))
return HttpResponse(json.dumps({
'name': "%s %s" % (actor.first_name, actor.last_name),
'address': address.a1
}))
示例12: get_children_pending
# 需要导入模块: from focus.models import Actor [as 别名]
# 或者: from focus.models.Actor import get_personal_members [as 别名]
def get_children_pending(self):
"""Returns existing single members who are *due to become* family members in this users' family"""
from user.models import User
children_pending = cache.get('actor.%s.children_pending' % self.actor.memberid)
if children_pending is None:
actors = Actor.get_personal_members().filter(
pending_family_parent=self.actor.memberid,
).exclude(
memberid=self.actor.memberid,
).exclude(
# Exclude any actual family members. This is necessary because Focus doesn't clear the appropriate
# fields when converting pending family members to actual family members.
Q(services__code=get_membership_type_by_codename('family_household')['code']) |
Q(services__code=get_membership_type_by_codename('family_primary')['code'])
).order_by('first_name', 'last_name')
children_pending = [User.get_or_create_inactive(memberid=actor.memberid) for actor in actors]
cache.set(
'actor.%s.children_pending' % self.actor.memberid,
children_pending,
settings.FOCUS_MEMBER_CACHE_PERIOD,
)
return children_pending
示例13: turleder_search
# 需要导入模块: from focus.models import Actor [as 别名]
# 或者: from focus.models.Actor import get_personal_members [as 别名]
def turleder_search(request):
MAX_HITS = 100
if len(request.POST['q']) < settings.ADMIN_USER_SEARCH_CHAR_LENGTH:
raise PermissionDenied
local_nonmember_users = User.get_users().filter(memberid__isnull=True)
for word in request.POST['q'].split():
local_nonmember_users = local_nonmember_users.filter(
Q(first_name__icontains=word) |
Q(last_name__icontains=word)
)
local_nonmember_users = local_nonmember_users.order_by('first_name')
actors = Actor.get_personal_members()
for word in request.POST['q'].split():
actors = actors.filter(
Q(first_name__icontains=word) |
Q(last_name__icontains=word) |
Q(memberid__icontains=word)
)
actors = actors.order_by('first_name')
# Get (or create) the user objects for the first MAX_HITS actor-hits
users = [User.get_or_create_inactive(a.memberid) for a in actors[:MAX_HITS]]
# Merge with non-members
users = sorted(list(users) + list(local_nonmember_users), key=lambda u: u.get_full_name())
context = RequestContext(request, {
'users': users[:MAX_HITS]
})
return HttpResponse(json.dumps({
'results': render_to_string('common/admin/aktiviteter/edit/turleder_search_results.html', context),
'max_hits_exceeded': len(users) > MAX_HITS or len(actors) > MAX_HITS
}))
示例14: authenticate_users
# 需要导入模块: from focus.models import Actor [as 别名]
# 或者: from focus.models.Actor import get_personal_members [as 别名]
def authenticate_users(email, password):
"""
Yup, this is a 'util' method instead of a proper authentication backend.
The reason for this is that as our membersystem allows duplicate email
fields, a user can potentially authenticate herself for multiple accounts,
and the Django auth backend system doesn't account for that (it returns
exactly one user, or None).
"""
email = email.strip()
# Support this special case explicitly because it will hit a lot of Actors
# and check for a matching User for each of them, which takes a long time
if email == '':
return []
# Add matching local users that aren't members
matches = [
u
for u in User.get_users().filter(
memberid__isnull=True,
email__iexact=email
)
if u.check_password(password)
]
# Add matching members in Actor
for actor in Actor.get_personal_members().filter(email__iexact=email):
try:
# Ok, look for any matching active user
user = User.get_users(
include_pending=True,
include_expired=True
).get(
memberid=actor.memberid,
is_inactive=False # ignore inactive users
)
# Reset state if this user was previously pending but is now a
# proper member
if user.is_pending:
user.is_pending = False
user.save()
# Reset state if this user was previously marked as expired for
# some reason
if user.is_expired:
user.is_expired = False
user.save()
# Now perform the password check for authentication
if user.check_password(password):
matches.append(user)
except User.DoesNotExist:
pass
# Add matching pending members
for enrollment in Enrollment.filter_on_email(email):
try:
# Ok, look for any matching active AND pending user
user = User.get_users(
include_pending=True,
include_expired=True
).get(
memberid=enrollment.memberid,
is_pending=True,
is_inactive=False # ignore inactive users
)
# Reset state if this user was previously marked as expired for
# some reason
if user.is_expired:
user.is_expired = False
user.save()
# Now perform the password check for authentication
# Check that the user isn't already matched as an Actor since this
# theoretically could be a duplicate
if user.check_password(password) and user not in matches:
matches.append(user)
except User.DoesNotExist:
pass
# And just return these matches
return matches
示例15: index
# 需要导入模块: from focus.models import Actor [as 别名]
# 或者: from focus.models.Actor import get_personal_members [as 别名]
def index(request, forening_id):
current_forening = Forening.objects.get(id=forening_id)
if current_forening not in request.user.all_foreninger():
raise PermissionDenied
forening_users = list(User.objects.filter(foreninger=current_forening))
forening_users_by_parent = []
parent_ids = [p.id for p in current_forening.get_parents_deep()]
forening_users_by_parent_all = list(User.objects.filter(foreninger__in=parent_ids))
# Prefetch and cache the actors
memberids = [u.memberid for u in (forening_users + forening_users_by_parent)]
for actor in Actor.get_personal_members().filter(memberid__in=memberids):
cache.set('actor.%s' % actor.memberid, actor, settings.FOCUS_MEMBER_CACHE_PERIOD)
# Safe to iterate without having n+1 issues
# Filter on admins
forening_users_by_parent = []
for user in forening_users_by_parent_all:
for forening in user.all_foreninger():
if forening == current_forening and forening.role == 'admin':
forening_users_by_parent.append(user)
forening_users = sorted(forening_users, key=lambda u: u.get_full_name())
forening_users_by_parent = sorted(forening_users_by_parent, key=lambda u: u.get_full_name())
sherpa_admins = sorted(User.objects.filter(permissions__name='sherpa_admin'), key=lambda u: u.get_full_name())
# The parent choices are tricky to define in the forms API, so do it here.
# Note that we're intentionally letting users choose parents among only those they have permission to.
all_sorted = request.user.all_foreninger_sorted()
parents_choices = {
'forening': all_sorted['forening'],
'turlag': all_sorted['turlag'],
}
# If the parent of the current forening isn't in the user's permissions, we still need to include that one as an
# available parent so that they're able to make changes.
if current_forening.type != 'sentral':
for current_parent in current_forening.get_main_foreninger():
if current_parent not in parents_choices['forening'] and current_parent not in parents_choices['turlag']:
parents_choices[current_parent.type].append(current_parent)
context = {
'current_forening': current_forening,
'forening_users': forening_users,
'forening_users_by_parent': forening_users_by_parent,
'sherpa_admins': sherpa_admins,
'parents_choices': parents_choices,
'admin_user_search_char_length': settings.ADMIN_USER_SEARCH_CHAR_LENGTH
}
zipcode = current_forening.zipcode
edit_form_zipcode_area = zipcode.area if zipcode is not None else ''
if current_forening.contact_person is not None:
choose_contact = 'person'
contact_person = current_forening.contact_person.id
contact_person_name = current_forening.contact_person.get_full_name()
phone = current_forening.contact_person.get_phone_mobile()
email = current_forening.contact_person.get_sherpa_email()
elif current_forening.contact_person_name != '':
choose_contact = 'person'
contact_person = None
contact_person_name = current_forening.contact_person_name
phone = current_forening.phone
email = current_forening.email
else:
choose_contact = 'forening'
contact_person = None
contact_person_name = ''
phone = current_forening.phone
email = current_forening.email
edit_form = ExistingForeningDataForm(request.user, prefix='edit', initial={
'forening': current_forening.id,
'parents': current_forening.parents.all(),
'name': current_forening.name,
'type': current_forening.type,
'group_type': current_forening.group_type,
'post_address': current_forening.post_address,
'visit_address': current_forening.visit_address,
'zipcode': zipcode.zipcode if zipcode is not None else '',
'counties': current_forening.counties.all(),
'choose_contact': choose_contact,
'contact_person': contact_person,
'contact_person_name': contact_person_name,
'phone': phone,
'email': email,
'organization_no': current_forening.organization_no,
'gmap_url': current_forening.gmap_url,
'facebook_url': current_forening.facebook_url,
})
create_form = ForeningDataForm(request.user, prefix='create', initial={
'zipcode': '',
})
#.........这里部分代码省略.........