Browse Source

exceptions, still need to do project_template

Kevin Cummings 5 years ago
parent
commit
6a479d1aed

+ 1 - 1
coderedcms/blocks/html_blocks.py

@@ -243,7 +243,7 @@ class PageListBlock(BaseBlock):
             if value['classified_by']:
             if value['classified_by']:
                 try:
                 try:
                     pages = pages.filter(classifier_terms=value['classified_by'])
                     pages = pages.filter(classifier_terms=value['classified_by'])
-                except:
+                except AttributeError:
                     # `pages` is not a queryset, or is not a queryset of CoderedPage.
                     # `pages` is not a queryset, or is not a queryset of CoderedPage.
                     logger.warning(
                     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.uploadedfile import InMemoryUploadedFile, TemporaryUploadedFile
 from django.core.files.storage import FileSystemStorage
 from django.core.files.storage import FileSystemStorage
 from django.core.mail import EmailMessage
 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.serializers.json import DjangoJSONEncoder
 from django.core.validators import MaxValueValidator, MinValueValidator
 from django.core.validators import MaxValueValidator, MinValueValidator
 from django.db import models
 from django.db import models
@@ -40,7 +40,8 @@ from wagtail.admin.edit_handlers import (
     ObjectList,
     ObjectList,
     PageChooserPanel,
     PageChooserPanel,
     StreamFieldPanel,
     StreamFieldPanel,
-    TabbedInterface)
+    TabbedInterface
+)
 from wagtail.core import hooks
 from wagtail.core import hooks
 from wagtail.core.fields import StreamField
 from wagtail.core.fields import StreamField
 from wagtail.core.models import Orderable, PageBase, Page, Site
 from wagtail.core.models import Orderable, PageBase, Page, Site
@@ -59,7 +60,8 @@ from coderedcms.blocks import (
     STREAMFORM_BLOCKS,
     STREAMFORM_BLOCKS,
     ContentWallBlock,
     ContentWallBlock,
     OpenHoursBlock,
     OpenHoursBlock,
-    StructuredDataActionBlock)
+    StructuredDataActionBlock
+)
 from coderedcms.fields import ColorField
 from coderedcms.fields import ColorField
 from coderedcms.forms import CoderedFormBuilder, CoderedSubmissionsListView
 from coderedcms.forms import CoderedFormBuilder, CoderedSubmissionsListView
 from coderedcms.models.snippet_models import ClassifierTerm
 from coderedcms.models.snippet_models import ClassifierTerm
@@ -611,7 +613,7 @@ class CoderedPage(WagtailCacheMixin, Page, metaclass=CoderedPageMeta):
                         try:
                         try:
                             for term in selected_terms:
                             for term in selected_terms:
                                 all_children = all_children.filter(classifier_terms=term)
                                 all_children = all_children.filter(classifier_terms=term)
-                        except:
+                        except AttributeError:
                             logger.warning(
                             logger.warning(
                                 '''
                                 '''
                                 Tried to filter by ClassifierTerm, but <%s.%s ('%s')>.get_index_children() did
                                 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)
             pagenum = request.GET.get('p', 1)
             try:
             try:
                 paged_children = paginator.page(pagenum)
                 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)
                 paged_children = paginator.page(1)
 
 
             context['index_paginated'] = paged_children
             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:
         else:
             try:
             try:
                 del(get[key])
                 del(get[key])
-            except:
+            except KeyError:
                 pass
                 pass
     return get
     return get
 
 

+ 7 - 3
coderedcms/views.py

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

BIN
flake8output.txt