Beispiel #1
0
 def convert_to_society(self, request, queryset):
     """ Converts this CosinnusGroup's type """
     converted_names = []
     refused_portal_names = []
     for group in queryset:
         if group.portal_id != CosinnusPortal.get_current().id:
             refused_portal_names.append(group.name)
             continue
         group.type = CosinnusGroup.TYPE_SOCIETY
         # clear parent group if the project had one (societies cannot have parents!)
         group.parent = None
         group.save(allow_type_change=True)
         if group.type == CosinnusGroup.TYPE_SOCIETY:
             converted_names.append(group.name)
             CosinnusPermanentRedirect.create_for_pattern(group.portal, CosinnusGroup.TYPE_PROJECT, group.slug, group)
             
         # we beat the cache with a hammer on all class models, to be sure
         CosinnusProject._clear_cache(group=group)
         CosinnusSociety._clear_cache(group=group)
         get_cosinnus_group_model()._clear_cache(group=group)
         CosinnusGroupMembership.clear_member_cache_for_group(group)
         
         # delete and recreate all group widgets (there might be different ones for group than for project)
         WidgetConfig.objects.filter(group_id=group.pk).delete()
         create_initial_group_widgets(group, group)
     
     if converted_names:
         message = _('The following Projects were converted to Groups:') + '\n' + ", ".join(converted_names)
         self.message_user(request, message, messages.SUCCESS)
     if refused_portal_names:
         message_error = 'These Projects could not be converted because they do not belong to this portal:' + '\n' + ", ".join(refused_portal_names)
         self.message_user(request, message_error, messages.ERROR)
Beispiel #2
0
def housekeeping(request=None):
    """ Do some integrity checks and corrections. 
        Currently doing:
            - Checking all groups and projects for missing widgets versus the default widget
                settings and adding missing widgets
    """
    if request and not request.user.is_superuser:
        return HttpResponseForbidden('Not authenticated')
    
    groups = CosinnusGroup.objects.all()
    ret = ""
    for group in groups:
        ret += "Checked group %s\n<br/>" % group.slug
        create_initial_group_widgets(None, group)
    if request:
        return HttpResponse(ret)
    else:
        return ret
Beispiel #3
0
    def convert_to_project(self, request, queryset):
        """ Converts this CosinnusGroup's type """
        converted_names = []
        refused_portal_names = []
        for group in queryset:
            if group.portal_id != CosinnusPortal.get_current().id:
                refused_portal_names.append(group.name)
                continue
            group.type = CosinnusGroup.TYPE_PROJECT
            group.save(allow_type_change=True)
            if group.type == CosinnusGroup.TYPE_PROJECT:
                converted_names.append(group.name)
                CosinnusPermanentRedirect.create_for_pattern(
                    group.portal, CosinnusGroup.TYPE_SOCIETY, group.slug,
                    group)
                # all projects that had this group as parent, get set their parent=None and set this as related project
                # and all of those former child projects are also added as related to this newly-converted project
                for project in get_cosinnus_group_model().objects.filter(
                        parent=group):
                    project.parent = None
                    project.save(update_fields=['parent'])
                    RelatedGroups.objects.get_or_create(from_group=project,
                                                        to_group=group)
                    RelatedGroups.objects.get_or_create(from_group=group,
                                                        to_group=project)

            # we beat the cache with a hammer on all class models, to be sure
            CosinnusProject._clear_cache(group=group)
            CosinnusSociety._clear_cache(group=group)
            get_cosinnus_group_model()._clear_cache(group=group)
            CosinnusGroupMembership.clear_member_cache_for_group(group)

            # delete and recreate all group widgets (there might be different ones for group than for porject)
            WidgetConfig.objects.filter(group_id=group.pk).delete()
            create_initial_group_widgets(group, group)

        if converted_names:
            message = _('The following Groups were converted to Projects:'
                        ) + '\n' + ", ".join(converted_names)
            self.message_user(request, message, messages.SUCCESS)
        if refused_portal_names:
            message_error = 'These Groups could not be converted because they do not belong to this portal:' + '\n' + ", ".join(
                refused_portal_names)
            self.message_user(request, message_error, messages.ERROR)
Beispiel #4
0
def recreate_all_group_widgets(request=None, verbose=False):
    """ Resets all CosinnusGroup Dashboard Widget Configurations to their default
        by deleting and recreating them. """
    if request and not request.user.is_superuser:
        return HttpResponseForbidden('Not authenticated')
    
    # delete all widget configs
    WidgetConfig.objects.all().delete()
    
    # create all default widgets for all groups
    groups_ids = []
    all_groups = CosinnusGroup.objects.all()
    for group in all_groups:
        create_initial_group_widgets(None, group)
        groups_ids.append(str(group.id))
        if verbose:
            print((">>> recreated widget config for group id", group.id))
    
    return HttpResponse("The following groups were updated:<br/><br/>" + "<br/>".join(groups_ids))
Beispiel #5
0
    def _convert_to_type(self, request, queryset, to_group_type,
                         to_group_klass):
        """ Converts this CosinnusGroup's type """
        converted_names = []
        refused_portal_names = []
        for group in queryset:
            if group.portal_id != CosinnusPortal.get_current().id:
                refused_portal_names.append(group.name)
                continue
            # don't change type to same type
            if group.type == to_group_type:
                continue

            # remove haystack index for this group, re-index after
            group.remove_index()
            # swap types
            old_type = group.type
            group.type = to_group_type
            # clear parent group if the project had one (societies cannot have parents!)
            group.parent = None
            group.save(allow_type_change=True)
            if group.type == to_group_type:
                converted_names.append(group.name)
                CosinnusPermanentRedirect.create_for_pattern(
                    group.portal, old_type, group.slug, group)
                if old_type == CosinnusGroup.TYPE_SOCIETY:
                    # all projects that had this group as parent, get set their parent=None and set this as related project
                    # and all of those former child projects are also added as related to this newly-converted project
                    for project in get_cosinnus_group_model().objects.filter(
                            parent=group):
                        project.parent = None
                        project.save(update_fields=['parent'])
                        RelatedGroups.objects.get_or_create(from_group=project,
                                                            to_group=group)
                        RelatedGroups.objects.get_or_create(from_group=group,
                                                            to_group=project)

            # we beat the cache with a hammer on all class models, to be sure
            for klass in self.ALL_TYPES_CLASSES:
                klass._clear_cache(group=group)
            get_cosinnus_group_model()._clear_cache(group=group)
            CosinnusGroupMembership.clear_member_cache_for_group(group)

            # delete and recreate all group widgets (there might be different ones for group than for project)
            WidgetConfig.objects.filter(group_id=group.pk).delete()
            create_initial_group_widgets(group, group)

            # re-index haystack for this group after getting a properly classed, fresh object
            group.remove_index()
            group = to_group_klass.objects.get(id=group.id)
            group.update_index()

        if converted_names:
            message = _('The following items were converted to %s:'
                        ) % to_group_klass.get_trans(
                        ).VERBOSE_NAME_PLURAL + '\n' + ", ".join(
                            converted_names)
            self.message_user(request, message, messages.SUCCESS)
        if refused_portal_names:
            message_error = 'These items could not be converted because they do not belong to this portal:' + '\n' + ", ".join(
                refused_portal_names)
            self.message_user(request, message_error, messages.ERROR)