changed user-api, so it can be filter the result for the prefix and the id
This commit is contained in:
parent
4f61c763d7
commit
1ae91d1130
@ -89,17 +89,6 @@ class Profile(models.Model, UserMixin):
|
||||
)
|
||||
|
||||
|
||||
class ParticipantUsers(object):
|
||||
user_prefix = Profile.user_prefix
|
||||
|
||||
def __iter__(self):
|
||||
for profile in Profile.objects.all():
|
||||
yield profile
|
||||
|
||||
def __getitem__(self, key):
|
||||
return Profile.objects.get(pk=key)
|
||||
|
||||
|
||||
class DjangoGroup(models.Model, UserMixin):
|
||||
user_prefix = 'djangogroup'
|
||||
|
||||
@ -109,20 +98,33 @@ class DjangoGroup(models.Model, UserMixin):
|
||||
return unicode(self.group)
|
||||
|
||||
|
||||
class DjangoGroupUsers(object):
|
||||
user_prefix = DjangoGroup.user_prefix
|
||||
class ParticipantUsers(object):
|
||||
def __init__(self, user_prefix=None, id=None):
|
||||
self.user_prefix = user_prefix
|
||||
self.id = id
|
||||
|
||||
def __iter__(self):
|
||||
if not self.user_prefix or self.user_prefix == Profile.user_prefix:
|
||||
if self.id:
|
||||
yield Profile.objects.get(pk=self.id)
|
||||
else:
|
||||
for profile in Profile.objects.all():
|
||||
yield profile
|
||||
|
||||
if not self.user_prefix or self.user_prefix == DjangoGroup.user_prefix:
|
||||
if self.id:
|
||||
yield DjangoGroup.objects.get(pk=self.id)
|
||||
else:
|
||||
for group in DjangoGroup.objects.all():
|
||||
yield group
|
||||
|
||||
def __getitem__(self, key):
|
||||
return DjangoGroup.objects.get(pk=key)
|
||||
return Profile.objects.get(pk=key)
|
||||
|
||||
|
||||
@receiver(receiv_users, dispatch_uid="participant_profile")
|
||||
def receiv_users(sender, **kwargs):
|
||||
return [ParticipantUsers(), DjangoGroupUsers()]
|
||||
return ParticipantUsers(user_prefix=kwargs['user_prefix'], id=kwargs['id'])
|
||||
|
||||
|
||||
@receiver(default_config_value, dispatch_uid="participant_default_config")
|
||||
|
@ -87,29 +87,32 @@ def split_uid(uid):
|
||||
|
||||
def get_user(uid):
|
||||
try:
|
||||
user_type, id = split_uid(uid)
|
||||
user_prefix, id = split_uid(uid)
|
||||
except TypeError:
|
||||
return EmtyUser()
|
||||
|
||||
for receiver, users_list in receiv_users.send(sender='get_user'):
|
||||
for users in users_list:
|
||||
if users.user_prefix == user_type:
|
||||
return users[id]
|
||||
# TODO: Use own Exception
|
||||
raise Exception('User with uid %s does not exist' % uid)
|
||||
return Users(user_prefix=user_prefix, id=id)[0]
|
||||
|
||||
|
||||
class Users(object):
|
||||
"""
|
||||
A Storage for a multiplicity of different User-Objects.
|
||||
"""
|
||||
def __init__(self, user_prefix=None, id=None):
|
||||
self.user_prefix = user_prefix
|
||||
self.id = id
|
||||
|
||||
def __iter__(self):
|
||||
for receiver, users_list in receiv_users.send(sender='users'):
|
||||
for users in users_list:
|
||||
for receiver, users in receiv_users.send(sender='users', user_prefix=self.user_prefix, id=self.id):
|
||||
# Does iter(users) work?
|
||||
for user in users:
|
||||
yield user
|
||||
|
||||
def __getitem__(self, key):
|
||||
user_list = list(self)
|
||||
print user_list
|
||||
return user_list[key]
|
||||
|
||||
|
||||
def generate_uid(prefix, id):
|
||||
if ':' in prefix:
|
||||
|
@ -12,4 +12,4 @@
|
||||
|
||||
from django.dispatch import Signal
|
||||
|
||||
receiv_users = Signal(providing_args=[])
|
||||
receiv_users = Signal(providing_args=['user_prefix', 'id'])
|
||||
|
Loading…
Reference in New Issue
Block a user