# Path: remo/base/utils.py
# def add_permissions_to_groups(app, permissions):
#     """Assign permissions to groups."""
# 
#     # Make sure that all app permissions are created.
#     app_obj = apps.get_app_config(app)
#     create_permissions(app_obj, interactive=False)
# 
#     for perm_name, groups in permissions.iteritems():
#         for group_name in groups:
#             group, created = Group.objects.get_or_create(name=group_name)
#             permission = Permission.objects.get(codename=perm_name,
#                                                 content_type__app_label=app)
#             group.permissions.add(permission)


from django.apps import AppConfig
from django.db.models.signals import post_migrate
from remo.base.utils import add_permissions_to_groups



def event_set_groups(sender, **kwargs):
    """Set permissions to groups."""
    app_label = sender.label
    if (isinstance(app_label, basestring) and app_label != 'events'):
        return True

    perms = {'can_edit_events': ['Admin', 'Council', 'Mentor', 'Rep'],
             'can_delete_events': ['Admin', 'Council', 'Mentor'],
             'can_delete_event_comments': ['Admin'],
             'can_subscribe_to_events': ['Admin', 'Council', 'Mentor', 'Rep',
                                         'Alumni', 'Mozillians']}


# Path: remo/base/utils.py
# def add_permissions_to_groups(app, permissions):
#     """Assign permissions to groups."""
# 
#     # Make sure that all app permissions are created.
#     app_obj = apps.get_app_config(app)
#     create_permissions(app_obj, interactive=False)
# 
#     for perm_name, groups in permissions.iteritems():
#         for group_name in groups:
#             group, created = Group.objects.get_or_create(name=group_name)
#             permission = Permission.objects.get(codename=perm_name,
#                                                 content_type__app_label=app)
#             group.permissions.add(permission)


# Path: remo/events/apps.py
from django.apps import AppConfig
from django.db.models.signals import post_migrate
from remo.base.utils import add_permissions_to_groups




def event_set_groups(sender, **kwargs):
    """Set permissions to groups."""
    app_label = sender.label
    if (isinstance(app_label, basestring) and app_label != 'events'):
        return True

    perms = {'can_edit_events': ['Admin', 'Council', 'Mentor', 'Rep'],
             'can_delete_events': ['Admin', 'Council', 'Mentor'],
             'can_delete_event_comments': ['Admin'],
             'can_subscribe_to_events': ['Admin', 'Council', 'Mentor', 'Rep',
                                         'Alumni', 'Mozillians']}


    add_permissions_to_groups('events', perms)