本文整理汇总了Python中focus.models.Actor类的典型用法代码示例。如果您正苦于以下问题:Python Actor类的具体用法?Python Actor怎么用?Python Actor使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Actor类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: handle
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: confirm_membership
def confirm_membership(self):
"""Register that this member has confirmed their membership"""
status = self.actor.get_membership_confirmation_status()
if status.Bekreftet:
return
Actor.confirm_membership_by_token(status.Token)
示例3: search
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))
示例4: attempt_login
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: update_from_actors
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'])
示例6: __init__
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)
示例7: get_children
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
示例8: contact_person_search
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
}))
示例9: cache_actors
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
)
示例10: enroll_family_member
def enroll_family_member(self, user_data):
"""Enroll the given user and add them to this users' family membership.
user_data is a dict with the following keys:
- first_name
- last_name
- dob
- gender
- phone
- email"""
try:
focus_service = suds.client.Client(settings.FOCUS_WSDL_URL)
# Use a kwargs dictionary to avoid SyntaxError with non-ascii unicode characters for parameter names
params = {
'Token': settings.FOCUS_WSDL_TOKEN,
'Hovedmedlem': self.actor.memberid,
'Husstandsnummer': 0,
'Fornavn': user_data['first_name'],
'Etternavn': user_data['last_name'],
'Født': datetime(
year=user_data['dob'].year,
month=user_data['dob'].month,
day=user_data['dob'].day,
),
'Kjonn': Actor.convert_gender(user_data['gender']),
'Mobil': user_data['phone'],
'Epost': user_data['email'],
'Gjensidige': user_data['accepts_partneroffers'],
}
result = focus_service.service.EndreHusstand(**params)
if result != 'OK':
raise Exception("Unknown Focus Webservice result '%s'" % result)
except:
logger.warning(
"Feil med Focus webtjeneste",
exc_info=sys.exc_info(),
extra={
'member': self,
'user_data': user_data,
},
)
raise FocusServiceError
示例11: get_queryset
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
示例12: validate_existing
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
示例13: existing
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
}))
示例14: get_children_pending
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
示例15: turleder_search
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
}))