Beispiel #1
0
    def get_queryset(self):
        custom_tables = TenantSpecificTable.objects.all()
        customizable_models_names = get_setting('CUSTOMIZABLE_MODELS')

        search = self.request.GET.get('search')
        if search:
            custom_tables = custom_tables.filter(name__icontains=search)
            customizable_models_names = [
                m.replace('.',
                          get_setting(
                              'CUSTOMIZABLE_TABLES_LABEL_SEPARATOR')).lower()
                for m in customizable_models_names if search in m.replace(
                    '.', get_setting(
                        'CUSTOMIZABLE_TABLES_LABEL_SEPARATOR')).lower()
            ]

        filter_results = self.request.GET.get('filter')
        if filter_results == get_setting('CUSTOM_TABLES_FILTER_KEYWORD'):
            customizable_models_names = []
        elif filter_results == 'customizable_models':
            custom_tables = custom_tables.none()

        return {
            'custom_tables': custom_tables.order_by('name'),
            'customizable_models_names': sorted(customizable_models_names),
        }
Beispiel #2
0
    def get_queryset(self):
        table_slug = self.kwargs['slug']
        table_slug_parts = table_slug.split(
            get_setting('CUSTOMIZABLE_TABLES_LABEL_SEPARATOR'))
        app = table_slug_parts[0]

        if app == get_setting('CUSTOM_TABLES_LABEL'):
            return TenantSpecificTable.objects.all()

        return ContentType.objects.filter()
Beispiel #3
0
 def to_representation(self, obj):
     return {
         'name':
         '%s%s%s' %
         (get_setting('CUSTOM_TABLES_LABEL'),
          get_setting('CUSTOMIZABLE_TABLES_LABEL_SEPARATOR'), obj.name),
         'fields_definitions':
         TenantSpecificFieldDefinitionCreateSerializer(
             obj.fields_definitions, many=True).data,
     }
Beispiel #4
0
    def validate_name(self, name):
        table_slug_parts = name.split(
            get_setting('CUSTOMIZABLE_TABLES_LABEL_SEPARATOR'))
        app = table_slug_parts[0]

        if app != get_setting('CUSTOM_TABLES_LABEL') or len(
                table_slug_parts) < 2:
            raise serializers.ValidationError(
                _("This is not a valid custom table name"))

        return table_slug_parts[-1]
Beispiel #5
0
    def get_queryset(self):
        table_slug = self.kwargs['slug']
        if get_setting('CUSTOMIZABLE_TABLES_LABEL_SEPARATOR') in table_slug:
            table_slug_parts = table_slug.split(
                get_setting('CUSTOMIZABLE_TABLES_LABEL_SEPARATOR'))
            if table_slug_parts[0] == get_setting('CUSTOM_TABLES_LABEL'):
                try:
                    return get_custom_table_manager(table_slug_parts[1]).all()
                except TenantSpecificTable.DoesNotExist:
                    pass

        raise Http404()
Beispiel #6
0
    def get_serializer_class(self):
        table_slug = self.kwargs['slug']
        if get_setting('CUSTOMIZABLE_TABLES_LABEL_SEPARATOR') in table_slug:
            table_slug_parts = table_slug.split(
                get_setting('CUSTOMIZABLE_TABLES_LABEL_SEPARATOR'))
            if table_slug_parts[0] == get_setting('CUSTOM_TABLES_LABEL'):
                try:
                    return get_tenant_specific_table_row_serializer_class(
                        table_slug_parts[1])
                except TenantSpecificTable.DoesNotExist:
                    pass

        raise Http404()
Beispiel #7
0
    def get_object(self):
        if not hasattr(self, 'object'):
            table_slug = self.kwargs['slug']
            table_slug_parts = table_slug.split(
                get_setting('CUSTOMIZABLE_TABLES_LABEL_SEPARATOR'))
            app = table_slug_parts[0]

            try:
                if app == get_setting('CUSTOM_TABLES_LABEL'):
                    self.object = self.get_queryset().get(
                        name=table_slug_parts[1])
                elif (table_slug in [
                        m.replace(
                            '.',
                            get_setting('CUSTOMIZABLE_TABLES_LABEL_SEPARATOR')
                        ).lower() for m in get_setting('CUSTOMIZABLE_MODELS')
                ]):
                    self.object = ContentType.objects.get_by_natural_key(
                        *table_slug_parts)
                else:
                    raise Http404()
            except ObjectDoesNotExist:
                raise Http404()
        return self.object
Beispiel #8
0
 def get_custom_tables_names(self, custom_tables):
     return [
         get_setting('CUSTOM_TABLES_LABEL') +
         get_setting('CUSTOMIZABLE_TABLES_LABEL_SEPARATOR') + t
         for t in custom_tables.values_list('name', flat=True)
     ]
Beispiel #9
0
 def get_permissions(self):
     return [
         import_from_string(permission)() for permission in get_setting(
             'CUSTOMIZABLE_MODELS_LIST_CREATE_PERMISSIONS')
     ]
Beispiel #10
0
 def get_permissions(self):
     return [
         import_from_string(permission)() for permission in get_setting(
             'CUSTOMIZABLE_MODELS_RETRIEVE_UTPADE_DESTROY_PERMISSIONS')
     ]