Skip to content

Commit

Permalink
manually merge models.py
Browse files Browse the repository at this point in the history
  • Loading branch information
Christian Glatthard committed Aug 6, 2015
2 parents 076029c + ff03c74 commit ed1a99a
Show file tree
Hide file tree
Showing 12 changed files with 250 additions and 183 deletions.
8 changes: 4 additions & 4 deletions ipynbsrv/admin/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,10 +58,10 @@ class CollaborationGroupAdmin(GroupAdmin):
form = CollaborationGroupAdminForm
fieldsets = [
('General Properties', {
'fields': ['name', 'creator', 'admins']
'fields': ['name', 'creator']
}),
('Membership Options', {
'fields': ['users', 'is_single_user_group']
'fields': ['admins', 'users', 'is_single_user_group']
}),
('Visibility Options', {
'fields': ['is_public']
Expand Down Expand Up @@ -416,7 +416,7 @@ class NotificationAdmin(admin.ModelAdmin):
Admin model for the `Notification` model.
"""

list_display = ['message', 'date', 'sender', 'has_related_object']
list_display = ['message', 'date', 'sender', 'has_related_object', 'is_system_notification']
list_filter = [
('sender', admin.RelatedOnlyFieldListFilter),
'notification_type',
Expand All @@ -428,7 +428,7 @@ class NotificationAdmin(admin.ModelAdmin):

fieldsets = [
('General Properties', {
'fields': ['notification_type', 'message', 'sender']
'fields': ['notification_type', 'message', 'sender', 'is_system_notification']
}),
('Related Objects', {
'classes': ['collapse'],
Expand Down
44 changes: 31 additions & 13 deletions ipynbsrv/admin/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,11 @@ class CollaborationGroupAdminForm(forms.ModelForm):
:link https://djangosnippets.org/snippets/2452/
"""

admins = forms.ModelMultipleChoiceField(
queryset=BackendUser.objects.all(),
widget=FilteredSelectMultiple('Admins', False),
required=False
)
users = forms.ModelMultipleChoiceField(
queryset=BackendUser.objects.all(),
widget=FilteredSelectMultiple('Users', False),
Expand All @@ -22,7 +27,8 @@ def __init__(self, *args, **kwargs):
instance = kwargs.get('instance', None)
if instance is not None:
initial = kwargs.get('initial', {})
initial['users'] = instance.get_members()
initial['admins'] = instance.admins.all()
initial['users'] = instance.get_users()
kwargs['initial'] = initial
super(CollaborationGroupAdminForm, self).__init__(*args, **kwargs)

Expand All @@ -32,23 +38,35 @@ def save(self, commit=True):
"""
group = super(CollaborationGroupAdminForm, self).save(commit=commit)
if commit:
users = list(self.cleaned_data['admins']) + list(self.cleaned_data['users'])
for user in group.get_members():
if user not in users:
group.remove_member(user)
for user in users:
group.add_member(user)
# admins
for admin in group.admins.all():
if admin not in self.cleaned_data['admins']:
group.remove_admin(admin)
for admin in self.cleaned_data['admins']:
group.add_admin(admin)
# users
for user in group.get_users():
if user not in self.cleaned_data['users']:
group.remove_user(user)
for user in self.cleaned_data['users']:
group.add_user(user)
else:
old_save_m2m = self.save_m2m

def new_save_m2m():
old_save_m2m()
users = list(self.cleaned_data['admins']) + list(self.cleaned_data['users'])
for user in group.get_members():
if user not in users:
group.remove_member(user)
for user in users:
group.add_member(user)
# admins
for admin in group.admins.all():
if admin not in self.cleaned_data['admins']:
group.remove_admin(admin)
for admin in self.cleaned_data['admins']:
group.add_admin(admin)
# users
for user in group.get_users():
if user not in self.cleaned_data['users']:
group.remove_user(user)
for user in self.cleaned_data['users']:
group.add_user(user)
self.save_m2m = new_save_m2m
return group

Expand Down
2 changes: 1 addition & 1 deletion ipynbsrv/core/auth/authentication_backends.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ def authenticate(self, username=None, password=None):
uid = BackendUser.generate_internal_uid()
group = self.create_user_groups(username, uid)
user = self.create_users(username, password, uid, group.backend_group)
group.add_member(user.backend_user)
group.add_user(user.backend_user)

if user.is_active:
return user
Expand Down
Loading

0 comments on commit ed1a99a

Please sign in to comment.