2
0
Эх сурвалжийг харах

exceptions, still need to do project_template

Kevin Cummings 5 жил өмнө
parent
commit
6a479d1aed

+ 1 - 1
coderedcms/blocks/html_blocks.py

@@ -243,7 +243,7 @@ class PageListBlock(BaseBlock):
             if value['classified_by']:
                 try:
                     pages = pages.filter(classifier_terms=value['classified_by'])
-                except:
+                except AttributeError:
                     # `pages` is not a queryset, or is not a queryset of CoderedPage.
                     logger.warning(
                         '''

+ 11 - 5
coderedcms/models/page_models.py

@@ -11,7 +11,7 @@ from django.conf import settings
 from django.core.files.uploadedfile import InMemoryUploadedFile, TemporaryUploadedFile
 from django.core.files.storage import FileSystemStorage
 from django.core.mail import EmailMessage
-from django.core.paginator import Paginator
+from django.core.paginator import Paginator, InvalidPage, EmptyPage, PageNotAnInteger
 from django.core.serializers.json import DjangoJSONEncoder
 from django.core.validators import MaxValueValidator, MinValueValidator
 from django.db import models
@@ -40,7 +40,8 @@ from wagtail.admin.edit_handlers import (
     ObjectList,
     PageChooserPanel,
     StreamFieldPanel,
-    TabbedInterface)
+    TabbedInterface
+)
 from wagtail.core import hooks
 from wagtail.core.fields import StreamField
 from wagtail.core.models import Orderable, PageBase, Page, Site
@@ -59,7 +60,8 @@ from coderedcms.blocks import (
     STREAMFORM_BLOCKS,
     ContentWallBlock,
     OpenHoursBlock,
-    StructuredDataActionBlock)
+    StructuredDataActionBlock
+)
 from coderedcms.fields import ColorField
 from coderedcms.forms import CoderedFormBuilder, CoderedSubmissionsListView
 from coderedcms.models.snippet_models import ClassifierTerm
@@ -611,7 +613,7 @@ class CoderedPage(WagtailCacheMixin, Page, metaclass=CoderedPageMeta):
                         try:
                             for term in selected_terms:
                                 all_children = all_children.filter(classifier_terms=term)
-                        except:
+                        except AttributeError:
                             logger.warning(
                                 '''
                                 Tried to filter by ClassifierTerm, but <%s.%s ('%s')>.get_index_children() did
@@ -625,7 +627,11 @@ class CoderedPage(WagtailCacheMixin, Page, metaclass=CoderedPageMeta):
             pagenum = request.GET.get('p', 1)
             try:
                 paged_children = paginator.page(pagenum)
-            except:
+            except PageNotAnInteger:
+                paged_children = paginator.page(1)
+            except EmptyPage:
+                paged_children = paginator.page(1)
+            except InvalidPage:
                 paged_children = paginator.page(1)
 
             context['index_paginated'] = paged_children

+ 1 - 1
coderedcms/templatetags/coderedcms_tags.py

@@ -144,7 +144,7 @@ def query_update(querydict, key=None, value=None):
         else:
             try:
                 del(get[key])
-            except:
+            except KeyError:
                 pass
     return get
 

+ 7 - 3
coderedcms/views.py

@@ -7,7 +7,7 @@ from datetime import datetime
 from django.http import Http404, HttpResponse, JsonResponse
 from django.contrib.auth.decorators import login_required
 from django.contrib.contenttypes.models import ContentType
-from django.core.paginator import Paginator
+from django.core.paginator import Paginator, InvalidPage, EmptyPage, PageNotAnInteger
 from django.shortcuts import redirect, render
 from django.utils.translation import ungettext, ugettext_lazy as _
 from icalendar import Calendar
@@ -72,7 +72,7 @@ def search(request):
                 try:
                     model = ContentType.objects.get(model=search_model).model_class()
                     results = model.objects.live().search(search_query)
-                except:
+                except search_model.DoesNotExist:  # Possible search also causes an exception, nothing found online
                     results = None
             else:
                 results = CoderedPage.objects.live().order_by('-last_published_at').search(search_query)
@@ -83,7 +83,11 @@ def search(request):
             page = request.GET.get('p', 1)
             try:
                 results_paginated = paginator.page(page)
-            except:
+            except PageNotAnInteger:
+                results_paginated = paginator.page(1)
+            except EmptyPage:
+                results_paginated = paginator.page(1)
+            except InvalidPage:
                 results_paginated = paginator.page(1)
 
         # Log the query so Wagtail can suggest promoted results

BIN
flake8output.txt